From 2be1557dab0cca0857e2b76b8413bdcc747d97ad Mon Sep 17 00:00:00 2001 From: BaronKiko Date: Sat, 5 Jan 2019 23:07:16 +0000 Subject: [PATCH] constant attributes --- constant_attributes/source/main.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/constant_attributes/source/main.cpp b/constant_attributes/source/main.cpp index 9c74695..c5bc557 100644 --- a/constant_attributes/source/main.cpp +++ b/constant_attributes/source/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include // EGL library #include // EGL extensions @@ -182,22 +183,21 @@ static void setMesaConfig() static const char* const vertexShaderSrc = R"glsl( #version 150 core in vec2 pos; + in vec2 offset; void main() { - gl_Position = vec4(pos, 0.0, 1.0); + gl_Position = vec4(pos + offset, 0.0, 1.0); } )glsl"; static const char* const fragmentShaderSrc = R"glsl( #version 330 core out vec4 FragColor; - - uniform vec4 ourColor; // we set this variable in the OpenGL code. void main() { - FragColor = ourColor; + FragColor = vec4(0.0f, 0.0f, 1.0f, 1.0f); } )glsl"; @@ -273,10 +273,13 @@ static void sceneInit() glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); } + +float pos; + static void sceneRender() { - int vertexColorLocation = glGetUniformLocation(shaderProgram, "ourColor"); - glUniform4f(vertexColorLocation, 0.0f, 1.0f, 0.0f, 1.0f); + GLint vertexLoc = glGetAttribLocation(shaderProgram, "offset"); + glVertexAttrib2f(vertexLoc, sin(pos++ / 20) / 2, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);