Sign in to follow this  

vbos to draw cube problem(easy but wordy)

This topic is 4663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's the arrays: FIRSTLY SET UP THE ARRAYS ========================================================== //m_bldg contains the vertices of each corner on the cube at 0,0,0: //eg vertices 4, 5, 6, 7 //vertex=4 m_bdlg[4][0] = 0.0f; m_bdlg[4][1] = 0.0f; m_bdlg[4][2] = 1.0f; //vertex=5 m_bdlg[5][0] = 1.0f; m_bdlg[5][1] = 0.0f; m_bdlg[5][2] = 1.0f; //vertex=6 m_bdlg[6][0] = 1.0f; m_bdlg[6][1] = 1.0f; m_bdlg[6][2] = 1.0f; //vertex=7 m_bdlg[7][0] = 0.0f; m_bdlg[7][1] = 1.0f; m_bdlg[7][2] = 1.0f; .... etc for all 8 vertices //index arrays to draw each face: //eg below gives the 4 corners on the front face which would be array elemenst //4, 5, 6 and 7 of the m_bldg array m_indexFrontArray[0] = 4; m_indexFrontArray[1] = 5; m_indexFrontArray[2] = 6; m_indexFrontArray[3] = 7; //VBO for this: glGenBuffersARB( 1, &vboVertexData ); glBindBufferARB( GL_ARRAY_BUFFER_ARB , vboVertexData); // Bind The Buffer glBufferDataARB( GL_ARRAY_BUFFER_ARB ,8*3*sizeof(float), m_bdlg, GL_STATIC_DRAW_ARB ); ================================================================ NOW DRAW THE ARRAYS: glBindBufferARB( GL_ARRAY_BUFFER_ARB , vboVertexData ); glVertexPointer( 3, GL_FLOAT, 0, NULL ); glEnableClientState(GL_VERTEX_ARRAY); //DRAW COMMAND (etc for each face) glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, m_indexFrontArray); ... glDisableClientState(GL_VERTEX_ARRAY); ======================================= nothing is there !! other things I'm drawing are there but not this cube ? It must be easy to fix but i can't see it ! cheers

Share this post


Link to post
Share on other sites
I tend to stick with the basics:


void drawFlatCube(){
GLfloat cpoints[] = {
//front
-1.0f,-1.0f,+1.0f,
+1.0f,-1.0f,+1.0f,
+1.0f,+1.0f,+1.0f,
-1.0f,+1.0f,+1.0f,
//back
-1.0f,-1.0f,-1.0f,
+1.0f,-1.0f,-1.0f,
+1.0f,+1.0f,-1.0f,
-1.0f,+1.0f,-1.0f
};
GLuint quadIndices[] = {
//front back
0,1,2,3, 5,4,7,6,
//left right
4,0,3,7, 1,5,6,2,
//top bottom
3,2,6,7, 4,5,1,0
};
glInterleavedArrays(GL_V3F,0,cpoints);
glDrawElements(GL_QUADS,24,GL_UNSIGNED_INT,quadIndices);
}

Share this post


Link to post
Share on other sites
It looks like you're enabling the client state AFTER you're setting the glVertexPointer. I *think* you have to enable the client state before that.

Also, I think you want to create a VBO for your indicies, as well. Try something like:
//VBO for this:
glGenBuffersARB( 1, &vboVertexData );
glBindBufferARB( GL_ARRAY_BUFFER_ARB , vboVertexData); // Bind The Buffer
glBufferDataARB( GL_ARRAY_BUFFER_ARB ,8*3*sizeof(float),
m_bdlg, GL_STATIC_DRAW_ARB );

glGenBuffersARB( 1, &vboIndicies );
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB , vboVertexData); // Bind The Buffer
glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB ,(number_of_quads * 4)*sizeof(m_indexFrontArray type),
m_bdlg, GL_STATIC_DRAW_ARB );

================================================================

NOW DRAW THE ARRAYS:

glEnableClientState(GL_VERTEX_ARRAY);

glBindBufferARB( GL_ARRAY_BUFFER_ARB , vboVertexData );
glVertexPointer( 3, GL_FLOAT, 0, NULL );

glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, vboIndicies );

//DRAW COMMAND (for all faces)
glDrawElements(GL_QUADS, number_of_quads * 4, GL_m_indexFrontArray_type, m_indexFrontArray);
...

glDisableClientState(GL_VERTEX_ARRAY);

Share this post


Link to post
Share on other sites

This topic is 4663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this