return shader;
}
-int create_gl_resources(Compositor *compositor, CompositedScreen *screen)
+unsigned link_program(unsigned *shaders, unsigned nshaders)
{
+ unsigned program;
+ unsigned i;
int status;
char info_log[1024];
GLsizei length;
+ program = glCreateProgram();
+ for(i=0; i<nshaders; ++i)
+ glAttachShader(program, shaders[i]);
+ glBindAttribLocation(program, 0, "vertex");
+ glLinkProgram(program);
+
+ glGetProgramiv(program, GL_LINK_STATUS, &status);
+ glGetProgramInfoLog(program, sizeof(info_log), &length, info_log);
+ if(!status)
+ {
+ fprintf(stderr, "Program link failed:\n%s\n", info_log);
+ glDeleteProgram(program);
+ return 0;
+ }
+ else if(length)
+ printf("Program info log:\n%s\n", info_log);
+
+ return program;
+}
+
+int create_gl_resources(Compositor *compositor, CompositedScreen *screen)
+{
use_gl(compositor, screen);
screen->shaders[0] = compile_shader(GL_VERTEX_SHADER, vshader);
if(!screen->shaders[0] || !screen->shaders[1])
return 0;
- screen->program = glCreateProgram();
- glAttachShader(screen->program, screen->shaders[0]);
- glAttachShader(screen->program, screen->shaders[1]);
- glBindAttribLocation(screen->program, 0, "vertex");
- glLinkProgram(screen->program);
+ screen->program = link_program(screen->shaders, 2);
+ if(!screen->program)
+ return 0;
screen->geometry_loc = glGetUniformLocation(screen->program, "geometry");
- glGetProgramiv(screen->program, GL_LINK_STATUS, &status);
- glGetProgramInfoLog(screen->program, sizeof(info_log), &length, info_log);
- if(!status)
- {
- fprintf(stderr, "Program link failed:\n%s\n", info_log);
- glDeleteProgram(screen->program);
- return 0;
- }
- else if(length)
- printf("Program info log:\n%s\n", info_log);
-
glGenBuffers(1, &screen->vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, screen->vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);