diff options
Diffstat (limited to '')
-rw-r--r-- | src/main.c | 33 | ||||
-rw-r--r-- | src/shader.c | 0 | ||||
-rw-r--r-- | src/shader.h | 0 |
3 files changed, 25 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c index 8c77270..77ed9d5 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,6 @@ #include <GL/glew.h> #include <GLFW/glfw3.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> @@ -7,6 +8,11 @@ void on_resize(GLFWwindow *win, int width, int height) { glViewport(0, 0, width, height); } +void get_max_attrib_count(int *attrib_count) { + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, attrib_count); + printf("Max vertex attribs %d\n", *attrib_count); +} + int main() { // Initialize GLFW if (!glfwInit()) { @@ -25,7 +31,6 @@ int main() { } glfwSetFramebufferSizeCallback(window, (void *)on_resize); - glfwMakeContextCurrent(window); // Initialize GLEW @@ -35,6 +40,9 @@ int main() { return -1; } + int attrib_count; + get_max_attrib_count(&attrib_count); + float vertices[] = { 0.5f, 0.5f, 0.0f, // top right 0.5f, -0.5f, 0.0f, // bottom right @@ -55,9 +63,11 @@ int main() { const char *vertex_shader_src = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" + "out vec4 vertexColor;\n" "void main()\n" "{\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" + " vertexColor = vec4(0.5, 0.0, 0.0, 1.0);\n" "}\0"; unsigned int vertex_shader = glCreateShader(GL_VERTEX_SHADER); @@ -73,13 +83,13 @@ int main() { printf("ERROR::SHADER::VERTEX::COMPILATION_FAILED\n%s\n", info_log); } - const char *fragment_shader_src = - "#version 330 core\n" - "out vec4 FragColor;\n" - "void main()\n" - "{\n" - " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" - "}\0"; + const char *fragment_shader_src = "#version 330 core\n" + "out vec4 FragColor;\n" + "uniform vec4 ourColor;\n" + "void main()\n" + "{\n" + " FragColor = ourColor;\n" + "}\0"; unsigned int fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragment_shader, 1, &fragment_shader_src, NULL); @@ -124,6 +134,13 @@ int main() { glClear(GL_COLOR_BUFFER_BIT); glUseProgram(shader_program); + float time_value = glfwGetTime(); + float green_value = (sin(time_value) / 2.0f) + 0.5f; + int vertex_color_location = + glGetUniformLocation(shader_program, "ourColor"); + + glUniform4f(vertex_color_location, 0.0f, green_value, 0.0f, 1.0f); + glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glBindVertexArray(0); diff --git a/src/shader.c b/src/shader.c deleted file mode 100644 index e69de29..0000000 --- a/src/shader.c +++ /dev/null diff --git a/src/shader.h b/src/shader.h deleted file mode 100644 index e69de29..0000000 --- a/src/shader.h +++ /dev/null |