PDA

View Full Version : Vertex Array problems



Halcyon
01-10-2003, 06:25 PM
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

glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(3,GL_FLOAT,0,fvColorData);

glVertexPointer(3,GL_FLOAT,0,fvVertexData);

glTranslatef(0.0f,0.0f,-5.0f);

// Draw the top face of the cube.

glDrawElements(GL_TRIANGLE_STRIP,4,GL_INT,ivIndexD ataTop);

// Draw the sides of the cube

glDrawElements(GL_TRIANGLE_STRIP,10,GL_INT,ivIndex DataSides);

// Draw the bottom of the cube

glDrawElements(GL_TRIANGLE_STRIP,4,GL_INT,ivIndexD ataBottom);


glDisableClientState(GL_VERTEX_ARRAY);

glDisableClientState(GL_COLOR_ARRAY);



glFlush();

SwapBuffers(this->m_hDC);


Thanks for any help!

- Halcyon



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

Morglum
01-11-2003, 01:20 AM
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};

Halcyon
01-11-2003, 10:28 AM
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

Halcyon
01-11-2003, 10:37 AM
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