I am trying to use glInterleavedArrays with a Vertex Buffer and can’t seem to get it to work…
I define my vertex structure as follows:
struct VBOVertex
{
float tu;
float tv;
float red;
float green;
float blue;
float alpha;
float nx;
float ny;
float nz;
float vx;
float vy;
float vz;
};
I define my vertex data as follows:
// GL_T2F_C4F_N3F_V3F
VBOVertex g_pCubeVertices[8] = { {1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0},
{0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, -1.0, 1.0, 1.0},
{0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, -1.0, -1.0, 1.0},
{1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, -1.0, 1.0},
{0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, -1.0, -1.0},
{0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, -1.0},
{1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 1.0, -1.0},
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, -1.0, -1.0}};
// indices
GLubyte g_pCubeIndicesTriangles[] = { 0,1,2,
0,2,3,
5,0,3,
5,3,4,
6,5,4,
6,4,7,
1,6,7,
1,7,2,
0,6,1,
0,5,6,
3,4,7,
3,7,2};
I initialize my VBO as follows;
glGenBuffers(1, &vboId);
glBindBuffer(GL_ARRAY_BUFFER, vboId);
GLsizeiptr sizeOfVBO = sizeof(g_pCubeVertices) * 8;
glBufferData(GL_ARRAY_BUFFER, sizeOfVBO, 0, GL_STATIC_DRAW_ARB);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeOfVBO, g_pCubeVertices);
And This is my render loop code:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
cameraAngleX += 0.01;
cameraAngleY += 0.01;
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);
glPushMatrix();
glLoadIdentity();
glTranslatef(0, 0, cameraDistance);
glRotatef(cameraAngleX, 1, 0, 0);
glRotatef(cameraAngleY, 0, 1, 0);
glInterleavedArrays( GL_T2F_C4F_N3F_V3F, 0, g_pCubeVertices );
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, g_pCubeIndicesTriangles);
glPopMatrix();
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glutSwapBuffers();
I do not see anything when rendering. What am I doing wrong? Is it possible to use interleaved array data with VBO? Is there a better, faster, way.
When I separate my data into separate arrays and render using glDrawElements and a VBO, it works.
Ed