"#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;
for(i=0; i<nshaders; ++i)
glAttachShader(program, shaders[i]);
glBindAttribLocation(program, 0, "vertex");
+ glBindAttribLocation(program, 1, "texture_coord");
+ glBindFragDataLocation(program, 0, "frag_color");
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &status);
int create_gl_resources(Compositor *compositor, CompositedScreen *screen)
{
+ unsigned stride;
+
use_gl(compositor, screen);
screen->shaders[0] = compile_shader(GL_VERTEX_SHADER, vshader);
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);