Jump to content
  • Advertisement
Sign in to follow this  
mcdreameruk

OpenGL Confused by VBO's

This topic is 3934 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

I have been writing a simple class that loads a height map and renders it using a simple technique. This part works fine, however a little slow using the standard glBegin(), glEnd, glVertex etc, so I decided to learn how to use VBO's. After setting them up etc, I try to draw them but just end up with a complete mess of triangles. This is the code that renders the terrain using standard opengl calls :- glNormal(m_vNormals[x+1][z]); glTexCoord2f((startW + z)/1000.0f,(startL - (x+1))/1000.0f); glVertex3f( startW + z, startL - (x+1),GetHeight (x+1,z).y); glNormal(m_vNormals[x][z]); glTexCoord2f((startW + z)/1000.0f, (startL - (x))/1000.0f); glVertex3f( startW + z, startL - (x),GetHeight (x,z).y); This code works as should but it slow. The code below shows how I am putting my vertices into an array for drawing. m_pVerts[l].x = startW + z; m_pVerts[l].y = startL + (x+1); m_pVerts[l].z = GetHeight(x+1,z).y; l++; m_pVerts[l].x = startW + z; m_pVerts[l].y = startL + x; m_pVerts[l].z = GetHeight(x,z).y; However when I call the glDrawArrays it produces a mess where I can see some of the outline of the terrain but I have random triangles going everywhere. Is it because I am using triangle strips and the first piece of code only renders 2 vertices together at once or not ??? HELP me please, I am so dissapointed that I have my terrain working but not accelarated using VBO's. Any help or tips would be much appreciated. Thanks...

Share this post


Link to post
Share on other sites
Advertisement
This seems to be a wrong setup of the vertex array.

For example:

The y-coordinate for the second vertex in your first piece of code
is startL - x, but in your vertex array definition you use startL + x. That might be the error.

VBOs should produce the same result as intermediate mode if the arrays are set up properly (correct data).

Could you post your glDrawArrays function call?

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
This seems to be a wrong setup of the vertex array.

For example:

The y-coordinate for the second vertex in your first piece of code
is startL - x, but in your vertex array definition you use startL + x. That might be the error.

VBOs should produce the same result as intermediate mode if the arrays are set up properly (correct data).

Could you post your glDrawArrays function call?


Yes I see what you mean but this works as I want it too but only in intermediate mode. This is the call to draw my arrays in my render function.

glEnableClientState( GL_VERTEX_ARRAY );
glBindBufferARB(GL_ARRAY_BUFFER_ARB,terrain.m_VertBufName);
glVertexPointer(3,GL_FLOAT,0,(char*)NULL);
glDrawArrays(GL_TRIANGLE_STRIP ,0,terrain.m_lVertCnt);
glDisableClientState( GL_VERTEX_ARRAY );


thanks

Share this post


Link to post
Share on other sites
I have just tried the above code just using straight vertex buffers in stead of VBO's and again it works perfectly. There is a post similar in the forum to do with vbo's and interleaving, the results posted in that other post look similar to my output results, just a mess or triangles (look at the rocket).

thanks

Share this post


Link to post
Share on other sites
This is the link for the similar post from above : -

http://www.gamedev.net/community/forums/topic.asp?topic_id=466994

just look at the screen shots, not the code on this post.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!