I am currently working my way through the current OpenGL Programming Guide, Version 4.3. I implemented the code of the first example, that should display two triangles. Basically pretty simple.
But nothing is displayed when I run that code (just the black window).
This is the init function where the triangles are created:
GLuint vertexArrayObjects[1];
GLuint buffers[1];
const GLuint vertexCount = 6;
void init() {
// glClearColor(0,0,0,0);
glGenVertexArrays(1, vertexArrayObjects);
glBindVertexArray(vertexArrayObjects[0]);
GLfloat vertices[vertexCount][1] {
{-90.0, -90.0},
{ 85.0, -90.0},
{-90.0, 85.0},
{ 90.0, -85.0},
{ 90.0, 90.0},
{-85.0, 90.0}
};
glGenBuffers(1, buffers);
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
ShaderInfo shaders[] {
{GL_VERTEX_SHADER, "one.vsh"},
{GL_FRAGMENT_SHADER, "one.fsh"},
{GL_NONE, nullptr}
};
GLuint program = LoadShaders(shaders);
glUseProgram(program);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, ((char *)NULL + (0)));
glEnableVertexAttribArray(0);
}
And the very simple draw:
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(vertexArrayObjects[0]);
glDrawArrays(GL_TRIANGLES, 0, vertexCount);
glFlush();
}
But as said, nothing is drawn. Is there an error in my implementation?
The full code is here and LoadShaders (straight from the books website, so this should be out of interest) is here. The shaders are here.