src/gl/gridprogram.cpp

changeset 55
cb81ecb5fb23
parent 54
a4055f67b9c7
child 64
f99d52b1646b
--- a/src/gl/gridprogram.cpp	Thu Feb 13 15:25:01 2020 +0200
+++ b/src/gl/gridprogram.cpp	Wed Feb 26 02:21:07 2020 +0200
@@ -42,7 +42,7 @@
 
 out vec4 color;
 smooth in vec2 ex_uv;
-const vec4 lineColor = vec4(1.0, 1.0, 1.0, 0.75);
+uniform vec4 gridColor;
 const float pi = 3.14159265f;
 
 void main(void)
@@ -58,7 +58,7 @@
 	/* add dashes */
 	d *= (1 + cos(ex_uv.y / 0.00001f * pi)) * 0.5f;
 	d *= (1 + cos(ex_uv.x / 0.00001f * pi)) * 0.5f;
-	color = vec4(lineColor.xyz, d);
+	color = vec4(gridColor.xyz, gridColor.w * d);
 }
 )";
 
@@ -89,6 +89,7 @@
 		this->vertexArrayObject.bind();
 		this->program->enableAttributeArray(0);
 		this->program->setAttributeBuffer(0, GL_FLOAT, 0, 2, 0);
+		this->program->setUniformVector("gridColor", this->gridColor);
 		this->vertexArrayObject.release();
 		this->buffer.release();
 		this->program->release();
@@ -123,6 +124,22 @@
 	this->checkForGLErrors();
 }
 
+void GridProgram::setGridColor(const QColor& newGridColor)
+{
+	const glm::vec4 vec = gl::colorToVector4(newGridColor);
+	if (this->isInitialized)
+	{
+		this->program->bind();
+		this->program->setUniformVector("gridColor", vec);
+		this->program->release();
+		this->checkForGLErrors();
+	}
+	else
+	{
+		this->gridColor = vec;
+	}
+}
+
 void GridProgram::draw()
 {
 	this->program->bind();

mercurial