Add a uniform color.
This commit is contained in:
parent
f5f08ce669
commit
7215c6aba3
1 changed files with 11 additions and 4 deletions
15
src/main.cc
15
src/main.cc
|
@ -1,6 +1,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <epoxy/gl.h>
|
#include <epoxy/gl.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void process_input(GLFWwindow* window);
|
void process_input(GLFWwindow* window);
|
||||||
|
@ -11,11 +12,9 @@ const char* vertexShaderCode = R"(
|
||||||
// Set the GLSL version to 3.3 and use the OpenGL core profile
|
// Set the GLSL version to 3.3 and use the OpenGL core profile
|
||||||
#version 330 core
|
#version 330 core
|
||||||
layout (location = 0) in vec3 aPos;
|
layout (location = 0) in vec3 aPos;
|
||||||
out vec4 vertexColor;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(aPos, 1.0);
|
gl_Position = vec4(aPos, 1.0);
|
||||||
vertexColor = vec4(0.5, 0.0, 0.0, 1.0);
|
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
@ -23,10 +22,11 @@ const char* fragmentShaderCode = R"(
|
||||||
// Set the GLSL version to 3.3 and use the OpenGL core profile
|
// Set the GLSL version to 3.3 and use the OpenGL core profile
|
||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
in vec4 vertexColor;
|
|
||||||
|
uniform vec4 ourColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
FragColor = vertexColor;
|
FragColor = ourColor;
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
@ -221,6 +221,13 @@ int main() {
|
||||||
|
|
||||||
// Use the shaderProgram shader program for drawing verticies.
|
// Use the shaderProgram shader program for drawing verticies.
|
||||||
glUseProgram(shaderProgram);
|
glUseProgram(shaderProgram);
|
||||||
|
|
||||||
|
// Change the uniform color.
|
||||||
|
float timeValue = glfwGetTime();
|
||||||
|
float greenValue = (std::sin(timeValue) / 2.0f) + 0.5f;
|
||||||
|
int vertexColorLocation = glGetUniformLocation(shaderProgram, "ourColor");
|
||||||
|
glUniform4f(vertexColorLocation, 0.0f, greenValue, 0.0f, 1.0f);
|
||||||
|
|
||||||
if (!rectangleToggled) {
|
if (!rectangleToggled) {
|
||||||
// Bind the state to use the vertexArrayObject object so OpenGL knows what to do with the verticies.
|
// Bind the state to use the vertexArrayObject object so OpenGL knows what to do with the verticies.
|
||||||
glBindVertexArray(triangleRenderObjs->vertexArrayObject);
|
glBindVertexArray(triangleRenderObjs->vertexArrayObject);
|
||||||
|
|
Loading…
Reference in a new issue