From: Mikko Rasa Date: Sat, 12 Dec 2015 11:17:02 +0000 (+0200) Subject: Some refactoring of OpenGL code X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=bd6748fb5beb9d2f5cb0dd62fce445fe73b4d10e;p=geometrycompositor.git Some refactoring of OpenGL code In preparation for geometry correction --- diff --git a/source/main.c b/source/main.c index 0992542..f4704ae 100644 --- a/source/main.c +++ b/source/main.c @@ -63,29 +63,31 @@ static const char *vshader = "#version 150\n" "uniform vec4 geometry;\n" "in vec2 vertex;\n" + "in vec2 texture_coord;\n" "out vec2 texcoord;\n" "void main()\n" "{\n" " gl_Position = vec4((geometry.xy+vertex*geometry.zw)*2.0-1.0, 0.0, 1.0);\n" - " texcoord = vec2(vertex.x, 1.0-vertex.y);\n" + " texcoord = texture_coord;\n" "}\n"; static const char *fshader = "#version 150\n" - "uniform sampler2D window;\n" + "uniform sampler2D image;\n" "in vec2 texcoord;\n" "out vec4 frag_color;\n" "void main()\n" "{\n" - " frag_color = texture(window, texcoord);\n" + " frag_color = texture(image, texcoord);\n" "}\n"; static const float vertices[] = { - 0.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 1.0f, - 1.0f, 0.0f + /* vertex texcoord */ + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 1.0f, 1.0f }; int terminate_requested = 0; @@ -193,6 +195,8 @@ unsigned link_program(unsigned *shaders, unsigned nshaders) for(i=0; ishaders[0] = compile_shader(GL_VERTEX_SHADER, vshader); @@ -228,10 +234,14 @@ int create_gl_resources(Compositor *compositor, CompositedScreen *screen) glBindBuffer(GL_ARRAY_BUFFER, screen->vertex_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + stride = 4*sizeof(float); glGenVertexArrays(1, &screen->vertex_array); glBindVertexArray(screen->vertex_array); - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, stride, NULL); glEnableVertexAttribArray(0); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, stride, (void *)(2*sizeof(float))); + glEnableVertexAttribArray(1); + glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0);