Skip to main content
GameDev.net gamedev.net
🔒 Locked

VBO problem

Started by juglarx Mar 21, 2005 at 9:04 PM 4 replies 450+ views
Original Post
juglarx
juglarx
Hi guys!! i have a problem using the ARB vertex object , is a newby error , the problem is that , i have a square formed by 12 vertex and i try to render this square using 2 triangles , y don't try to use face index, only the vertex list.. well the problem is , when i render it only saw a single triangle, but a give the data for a square(formed by 2 trianges) , i think i have a stupid mistake and i can see it , any one can help? here is my code

//all my square points......
float SquarePoints[] = {
   5.5f, -1.5f, 0.0f, -1.5f, 1.5f, 1.0f,
   -1.5f, 1.5f, 0.0f, 1.5f, 1.5f,  0.0f
};
all the buffer initialization ....

	// Generate And Bind The VB
	glGenBuffersARB( 1, &squareBufferID );							// Get A Valid Name
	glBindBufferARB( GL_ARRAY_BUFFER_ARB, squareBufferID );
      glBufferDataARB( GL_ARRAY_BUFFER_ARB, 12*sizeof(float), SquarePoints,DRAW_ARB );

   
   // done,  unbind everything!
   glBindBufferARB(GL_ARRAY_BUFFER_ARB, NULL);
   glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, NULL);

and them draw it!!

	glBindBufferARB( GL_ARRAY_BUFFER_ARB, squareBufferID );
	glVertexPointer(3, GL_FLOAT, 0,0);
	glEnableClientState( GL_VERTEX_ARRAY );
	glDrawArrays( GL_TRIANGLES, 0, 4);	// Draw 

	glDisableClientState( GL_VERTEX_ARRAY );
nts
nts
Quote:
Original post by juglarx
glDrawArrays( GL_TRIANGLES, 0, 4);	// Draw 


Your sending down 4 vertecies, triangles have 3 points and you have 2 triangles so 2*3=6 [smile]

alternatively if that isn't it (off the top of my head above) check the face ordering and backface culling.

HTH
juglarx
juglarx
thanks for the fast reply! :) y use 6 in glDrawArrays( GL_TRIANGLES ... ) but i had the same result ... i thinks is something bad in may VBO implementation but.. i can't figure out what happend :(
Kalidor
Kalidor
Quote:
Original post by juglarx
thanks for the fast reply! :) y use 6 in glDrawArrays( GL_TRIANGLES ... ) but i had the same result ... i thinks is something bad in may VBO implementation but.. i can't figure out what happend :(


You also need to have the right number of vertices in the array. You only have 4 in SquarePoints. If you used an index buffer you would only need 4 and just reference 2 of them twice. I'm surprised your program isn't crashing when you tell it to draw 6 vertices but only send 4.
juglarx
juglarx
yes , it crash :( but i can't figure out what happend with this code ... i only see one triangle ....
Kalidor
Kalidor
Quote:
Original post by juglarx
yes , it crash :( but i can't figure out what happend with this code ... i only see one triangle ....


Like I said, that's because you are only sending 4 vertices. Using GL_TRIANGLES you would need 6 vertices to make 2 triangles. Try using GL_TRIANGLE_STRIP, that will only need 4 vertices.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.