Color changing shaders!
This commit is contained in:
parent
8ad43456cf
commit
e3febb936e
|
@ -77,6 +77,8 @@ public:
|
||||||
glUseProgram(program_id);
|
glUseProgram(program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int vertexShader_id, fragmentShader_id, program_id;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadFile(std::string path, char** source)
|
void LoadFile(std::string path, char** source)
|
||||||
{
|
{
|
||||||
|
@ -90,6 +92,4 @@ private:
|
||||||
memcpy_s(*source, s, shader.c_str(), s);
|
memcpy_s(*source, s, shader.c_str(), s);
|
||||||
(*source)[s] = '\0';
|
(*source)[s] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int vertexShader_id, fragmentShader_id, program_id;
|
|
||||||
};
|
};
|
|
@ -76,10 +76,14 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
|
float time = glfwGetTime();
|
||||||
|
int timeUniformLocation = glGetUniformLocation(program.program_id, "t");
|
||||||
|
|
||||||
glClearColor(0.4f, 0.1f, 0.5f, 1.0f);
|
glClearColor(0.4f, 0.1f, 0.5f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
program.Use();
|
program.Use();
|
||||||
|
glUniform1f(timeUniformLocation, time);
|
||||||
q.Draw();
|
q.Draw();
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
|
|
@ -37,7 +37,6 @@ public:
|
||||||
{
|
{
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices);
|
||||||
glBindVertexArray(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -28,7 +28,6 @@ public:
|
||||||
{
|
{
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
glBindVertexArray(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
#version 460 core
|
#version 460 core
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
in vec4 vertexColor;
|
||||||
|
|
||||||
|
uniform float t;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
FragColor = vertexColor * vec4((sin(t) + 1.f) / 2, (cos(t) + 1.f) / 2, (-sin(t) + 1.f), 1.f);
|
||||||
}
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
#version 460 core
|
#version 460 core
|
||||||
layout (location = 0) in vec3 aPos;
|
layout (location = 0) in vec3 aPos;
|
||||||
|
|
||||||
|
out vec4 vertexColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
||||||
|
vertexColor = vec4(aPos.x + 0.5, aPos.y + 0.5, 0.5, 1.0);
|
||||||
}
|
}
|
Loading…
Reference in a new issue