This is in preparation for removing fixed-function use altogether,
for OpenGL 3.2+ core context support.
glDepthMask(GL_FALSE);
check_error();
glDepthMask(GL_FALSE);
check_error();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
if (phases.size() > 1) {
glGenFramebuffers(1, &fbo);
check_error();
if (phases.size() > 1) {
glGenFramebuffers(1, &fbo);
check_error();
output_textures.insert(make_pair(phases[phase], tex_num));
}
output_textures.insert(make_pair(phases[phase], tex_num));
}
- glUseProgram(phases[phase]->glsl_program_num);
+ const GLuint glsl_program_num = phases[phase]->glsl_program_num;
+ glUseProgram(glsl_program_num);
check_error();
// Set up RTT inputs for this phase.
check_error();
// Set up RTT inputs for this phase.
check_error();
string texture_name = string("tex_") + phases[phase]->effect_ids[input];
check_error();
string texture_name = string("tex_") + phases[phase]->effect_ids[input];
- glUniform1i(glGetUniformLocation(phases[phase]->glsl_program_num, texture_name.c_str()), sampler);
+ glUniform1i(glGetUniformLocation(glsl_program_num, texture_name.c_str()), sampler);
unsigned sampler_num = phases[phase]->inputs.size();
for (unsigned i = 0; i < phases[phase]->effects.size(); ++i) {
Node *node = phases[phase]->effects[i];
unsigned sampler_num = phases[phase]->inputs.size();
for (unsigned i = 0; i < phases[phase]->effects.size(); ++i) {
Node *node = phases[phase]->effects[i];
- node->effect->set_gl_state(phases[phase]->glsl_program_num, phases[phase]->effect_ids[node], &sampler_num);
+ node->effect->set_gl_state(glsl_program_num, phases[phase]->effect_ids[node], &sampler_num);
check_error();
}
// Now draw!
check_error();
}
// Now draw!
- glBegin(GL_QUADS);
-
- glTexCoord2f(0.0f, 0.0f);
- glVertex2f(0.0f, 0.0f);
-
- glTexCoord2f(1.0f, 0.0f);
- glVertex2f(1.0f, 0.0f);
+ float vertices[] = {
+ 0.0f, 0.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+ 0.0f, 1.0f
+ };
+
+ int position_attrib = glGetAttribLocation(glsl_program_num, "position");
+ assert(position_attrib != -1);
+ glEnableVertexAttribArray(position_attrib);
+ check_error();
+ glVertexAttribPointer(position_attrib, 2, GL_FLOAT, GL_FALSE, 0, vertices);
+ check_error();
- glTexCoord2f(1.0f, 1.0f);
- glVertex2f(1.0f, 1.0f);
+ int texcoord_attrib = glGetAttribLocation(glsl_program_num, "texcoord");
+ if (texcoord_attrib != -1) {
+ glEnableVertexAttribArray(texcoord_attrib);
+ check_error();
+ glVertexAttribPointer(texcoord_attrib, 2, GL_FLOAT, GL_FALSE, 0, vertices); // Same as texcoords.
+ check_error();
+ }
- glTexCoord2f(0.0f, 1.0f);
- glVertex2f(0.0f, 1.0f);
+ glDrawArrays(GL_QUADS, 0, 4);
+ check_error();
+ glDisableVertexAttribArray(position_attrib);
+ check_error();
+ if (texcoord_attrib != -1) {
+ glDisableVertexAttribArray(texcoord_attrib);
+ check_error();
+ }
for (unsigned i = 0; i < phases[phase]->effects.size(); ++i) {
Node *node = phases[phase]->effects[i];
for (unsigned i = 0; i < phases[phase]->effects.size(); ++i) {
Node *node = phases[phase]->effects[i];
+attribute vec2 position;
+attribute vec2 texcoord;
varying vec2 tc;
void main()
{
varying vec2 tc;
void main()
{
- tc = gl_MultiTexCoord0.st;
- gl_Position = ftransform();
+ // The result of glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0) is:
+ //
+ // 2.000 0.000 0.000 -1.000
+ // 0.000 2.000 0.000 -1.000
+ // 0.000 0.000 -2.000 -1.000
+ // 0.000 0.000 0.000 1.000
+ gl_Position = vec4(2.0 * position.x - 1.0, 2.0 * position.y - 1.0, -1.0, 1.0);
+ tc = texcoord;