Use uniforms for color
This commit is contained in:
parent
2844f9a71e
commit
682a9b45e6
3 changed files with 27 additions and 7 deletions
24
main.c
24
main.c
|
|
@ -12,7 +12,6 @@
|
|||
#define log_err(str, ...) do { fprintf(stderr, "[ERROR] (%s:%d): " str "\n", __FILE__, __LINE__, ##__VA_ARGS__); } while (0)
|
||||
#define log_debug(str, ...) do { fprintf(stderr, "[DEBUG] (%s:%d): " str "\n", __FILE__, __LINE__, ##__VA_ARGS__); } while (0)
|
||||
|
||||
|
||||
char *read_entire_file(char *path)
|
||||
{
|
||||
FILE *f = fopen(path, "rb");
|
||||
|
|
@ -38,7 +37,13 @@ static void glfw_error_callback(int errcode, const char *description)
|
|||
fprintf(stderr, "[GLFW ERROR][ERRCODE %d] %s\n", errcode, description);
|
||||
}
|
||||
|
||||
int main()
|
||||
void set_uniform(GLuint program_id, const char *name, vec4f value)
|
||||
{
|
||||
GLint location = glGetUniformLocation(program_id, name);
|
||||
glUniform4f(location, value.x, value.y, value.z, value.w);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
GLFWwindow *window;
|
||||
|
||||
|
|
@ -106,8 +111,6 @@ int main()
|
|||
background_color.b = 0.3f;
|
||||
background_color.a = 1.0f;
|
||||
|
||||
|
||||
|
||||
hexgrid_t grid;
|
||||
grid.rows = 2;
|
||||
grid.columns = 2;
|
||||
|
|
@ -181,6 +184,7 @@ int main()
|
|||
//glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
//glBindVertexArray(0);
|
||||
|
||||
int64_t framecount = 0;
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
int width, height;
|
||||
|
|
@ -193,6 +197,15 @@ int main()
|
|||
glUseProgram(shader_program);
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
// Set uniforms
|
||||
vec4f hex_color;
|
||||
hex_color.r = (float)(framecount % 1100)/1100;
|
||||
hex_color.g = (float)(framecount % 300)/300;
|
||||
hex_color.b = (float)(framecount % 1700)/1700;
|
||||
hex_color.a = 1.0f;
|
||||
|
||||
set_uniform(shader_program, "uniform_color", hex_color);
|
||||
|
||||
for (size_t i = 0; i < grid.rows * grid.columns; ++i)
|
||||
{
|
||||
glBindVertexArray(grid.hexes[i].vao);
|
||||
|
|
@ -203,5 +216,8 @@ int main()
|
|||
}
|
||||
glfwPollEvents();
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
++framecount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#version 330 core
|
||||
out vec4 color;
|
||||
in vec4 vertex_color;
|
||||
out vec4 final_color;
|
||||
void main()
|
||||
{
|
||||
color = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
final_color = vertex_color;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 pos;
|
||||
uniform vec4 uniform_color;
|
||||
out vec4 vertex_color;
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(pos, 1.0f);
|
||||
vertex_color = uniform_color;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue