Thanks,
I got it. After reading the quick reference guide and a tutorial.
I read this tutorial Tutorial: OpenGL 3.1 The First Triangle (C++/Win) - OpenGL Wiki
And in this tutorial there are two vbo’s. The first for
vertex coordinates and the second for colors. So far so
good the tutorial works. But then I wanted to put the vertex
coordinates and the colors in one vbo.
float vert[18] = { 0.0f, 1.0f, -1.0f,
-0.8f, -0.8f, -1.0f,
0.8f, -0.8f, -1.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f
};
glGenBuffers(2, &vb);
glBindBuffer(GL_ARRAY_BUFFER, vb);
glBufferData(GL_ARRAY_BUFFER, sizeof(vert), vert, GL_STATIC_DRAW);
For drawing I call this…
glBindBuffer(GL_ARRAY_BUFFER, vb[0]);
glVertexAttribPointer(shader.getAttribLocation("in_Position"), 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(shader.getAttribLocation("in_Position"));
glVertexAttribPointer(shader.getAttribLocation("in_Color"), 3, GL_FLOAT, GL_FALSE, 9*sizeof(float), 0);
glEnableVertexAttribArray(shader.getAttribLocation("in_Color"));
shader.bind();
glDrawArrays(GL_TRIANGLES, 0, 3);
shader.unbind();
glDisableVertexAttribArray(shader.getAttribLocation("in_Position"));
glDisableVertexAttribArray(shader.getAttribLocation("in_Color"));
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
Well, this draws the triangle but the blue color is missing.
Actually the colors of the triangle vertices are
red
green blue
But putting the vertices and colors in one vbo it looks like
green
red black
The first 9 float values are the vertices and the left 9 values
are the color values. So for the color vertexattributepointer
I set the stride to 9 * sizeof(float)
glVertexAttribPointer(shader.getAttribLocation(“in_Color”), 3, GL_FLOAT, GL_FALSE, 9*sizeof(float), 0);
Can someone tell me what I did wrong ?
best regards,
lobbel