Vertex Array problems

Ok, i’m trying to rendering a cube using vertex arrays, but for some reason the glDrawElements(…) isn’t working for me.
Here is the code that I have:

// These are the variables that are defined

static float fvVertexData[] = {-0.5f,-0.5f,0.5f, // Vertex 0
-0.5f,0.5f,0.5f, // Vertex 1
0.5f,-0.5f,0.5f, // Vertex 2
0.5f,0.5f,0.5f, // Vertex 3
0.5f,-0.5f,-0.5f, // Vertex 4
0.5f,0.5f,-0.5f, // Vertex 5
-0.5f,-0.5f,-0.5f, // Vertex 6
-0.5f,0.5f,-0.5f}; // Vertex 7

static float fvColorData[] = {1.0f,0.0f,0.0f, // Color for Vertex 0
0.0f,0.0f,1.0f, // Color for Vertex 1
1.0f,0.0f,0.0f, // Color for Vertex 2
0.0f,0.0f,1.0f, // Color for Vertex 3
1.0f,0.0f,0.0f, // Color for Vertex 4
0.0f,0.0f,1.0f, // Color for Vertex 5
1.0f,0.0f,0.0f, // Color for Vertex 6
0.0f,0.0f,1.0f}; // Color for Vertex 7

static int ivIndexDataTop[] = {1,7,3,5};

static int ivIndexDataBottom[] = {0,2,4,6};

static int ivIndexDataSides[] = {0,1,2,3,4,5,6,7,8,9};

// This is the code in my render procedure





// Draw the top face of the cube.


// Draw the sides of the cube


// Draw the bottom of the cube






Thanks for any help!

  • Halcyon

[This message has been edited by Halcyon (edited 01-10-2003).]

the line

static int ivIndexDataSides[] = {0,1,2,3,4,5,6,7,8,9};

is referencing inexistent vertices (8,9)
replace it with

static int ivIndexDataSides[] = {0,1,2,3,4,5,6,7,0,1};

HAHAHA…oops…thanks for catching that for me. I fixed it, but I still don’t have anything showing up. It’s just so odd, because the vertex pointer is pointing at the right stuff. The glArrayElement(…) procedure works, but the glDrawElements doesn’t. And i don’t think it should be inside any glBegin(…)/glEnd() statements. So am i forgetting to do something obvious here?

  • Halcyon

I figured it out! Apparently the glDrawElements procedure only takes GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT or GL_UNSIGNED_INT for the third parameter. I was passing in GL_INT, so it did absolutely nothing. Again thanks for pointing out the indexing error i made and for looking over the code.

  • Halcyon