// texture coordinates in order not to get long stretches of (1,1,1,...)
// at the start and (...,0,0,0) at the end.
float vertices[] = {
+ 0.0f, 1.0f,
0.0f, 0.0f,
- 1.0f, 0.0f,
1.0f, 1.0f,
- 0.0f, 1.0f
+ 1.0f, 0.0f
};
float texcoords[] = {
+ 0.25f, 0.0f,
0.25f, 0.0f,
0.75f, 0.0f,
- 0.75f, 0.0f,
- 0.25f, 0.0f
+ 0.75f, 0.0f
};
- int position_attrib = glGetAttribLocation(glsl_program_num, "position");
- assert(position_attrib != -1);
- int texcoord_attrib = glGetAttribLocation(glsl_program_num, "texcoord");
- assert(texcoord_attrib != -1);
- glEnableVertexAttribArray(position_attrib);
- check_error();
- glVertexAttribPointer(position_attrib, 2, GL_FLOAT, GL_FALSE, 0, vertices);
+ GLuint vao;
+ glGenVertexArrays(1, &vao);
check_error();
- glEnableVertexAttribArray(texcoord_attrib);
- check_error();
- glVertexAttribPointer(texcoord_attrib, 2, GL_FLOAT, GL_FALSE, 0, texcoords);
+ glBindVertexArray(vao);
check_error();
- glDrawArrays(GL_QUADS, 0, 4);
+ GLuint position_vbo = fill_vertex_attribute(glsl_program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices);
+ GLuint texcoord_vbo = fill_vertex_attribute(glsl_program_num, "texcoord", 2, GL_FLOAT, sizeof(texcoords), texcoords);
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
check_error();
+ cleanup_vertex_attribute(glsl_program_num, "position", position_vbo);
+ cleanup_vertex_attribute(glsl_program_num, "texcoord", texcoord_vbo);
+
glUseProgram(0);
check_error();
- glDisableVertexAttribArray(position_attrib);
- check_error();
- glDisableVertexAttribArray(texcoord_attrib);
- check_error();
// Now read the data back and see what the card did.
// (We only look at the red channel; the others will surely be the same.)
check_error();
resource_pool.release_glsl_program(glsl_program_num);
+ glDeleteVertexArrays(1, &vao);
+ check_error();
}
void measure_roundoff_problems()
// Draw the texture stretched over a long quad, interpolating it out.
float vertices[] = {
+ 0.0f, 1.0f,
0.0f, 0.0f,
- 1.0f, 0.0f,
1.0f, 1.0f,
- 0.0f, 1.0f
+ 1.0f, 0.0f
};
float texcoords[] = {
+ 0.25f, 0.0f,
0.25f, 0.0f,
0.75f, 0.0f,
- 0.75f, 0.0f,
- 0.25f, 0.0f
+ 0.75f, 0.0f
};
- int position_attrib = glGetAttribLocation(glsl_program_num, "position");
- assert(position_attrib != -1);
- int texcoord_attrib = glGetAttribLocation(glsl_program_num, "texcoord");
- assert(texcoord_attrib != -1);
- glEnableVertexAttribArray(position_attrib);
- check_error();
- glVertexAttribPointer(position_attrib, 2, GL_FLOAT, GL_FALSE, 0, vertices);
+
+ GLuint vao;
+ glGenVertexArrays(1, &vao);
check_error();
- glEnableVertexAttribArray(texcoord_attrib);
+ glBindVertexArray(vao);
check_error();
- glVertexAttribPointer(texcoord_attrib, 2, GL_FLOAT, GL_FALSE, 0, texcoords);
+
+ GLuint position_vbo = fill_vertex_attribute(glsl_program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices);
+ GLuint texcoord_vbo = fill_vertex_attribute(glsl_program_num, "texcoord", 2, GL_FLOAT, sizeof(texcoords), texcoords);
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
check_error();
- glDrawArrays(GL_QUADS, 0, 4);
+
+ cleanup_vertex_attribute(glsl_program_num, "position", position_vbo);
+ cleanup_vertex_attribute(glsl_program_num, "texcoord", texcoord_vbo);
glUseProgram(0);
check_error();
- glDisableVertexAttribArray(position_attrib);
- check_error();
- glDisableVertexAttribArray(texcoord_attrib);
// Now read the data back and see what the card did. (Ignore the last value.)
// (We only look at the red channel; the others will surely be the same.)
check_error();
resource_pool.release_glsl_program(glsl_program_num);
+ glDeleteVertexArrays(1, &vao);
+ check_error();
}
bool check_extensions()