PDA

View Full Version : VBO/IBO Terrain Rendering Problem



Erebel55
06-28-2010, 10:26 PM
Hello, I am having a heck of a time getting my head around vbo/ibo fully.
Right now my terrain is rendering wrong..it is rendering with two layers..when it should only have one.

http://i274.photobucket.com/albums/jj265/Erebel55/bugscreeny5.jpg

The diagonal solid strips aren't supposed to be there...only the triangles. This is causing me problems because it makes it so that the terrain appears to have two layers in some parts.

For example here is two screenshots of me inside of the terrain.
http://i274.photobucket.com/albums/jj265.../buscreeny5.jpg (http://i274.photobucket.com/albums/jj265/Erebel55/buscreeny5.jpg)
http://i274.photobucket.com/albums/jj265/Erebel55/bugscreeny4.jpg

Here is a pastebin of how I create and draw my terrain.
http://pastebin.com/zCQZ2Cxe

Normally, I render my terrain with GL_TRIANGLE_STRIP. I am only using GL_TRIANGLES at the moment so that I can see what is going on easier.

Any help would be hugely appreciated..this has been bugging me for a while.

Thanks.

Dark Photon
06-29-2010, 04:45 AM
vbo/ibo...Right now my terrain is rendering wrong..it is rendering with two layers..when it should only have one.
This didn't make sense to me.


The diagonal solid strips aren't supposed to be there...only the triangles.
Well at least it looks like your vertex attribute positions are right. Probably just have a problem getting the right index list (or index list order) for your triangles.

To help rule out that some of the triangles are facing the wrong way, try:

glDisable ( GL_CULL_FACE ) ;

If you see them now, you may just have the order of the triangle indices specified wrong. They should match whatever glFrontFace (http://pyopengl.sourceforge.net/documentation/manual/glFrontFace.3G.html) convention you have active (CCW by default).

Also, to see the verts you are sending down:

glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE ) ;

Also, in case your normals are flipped for some reason, slap some code in your shader to flip the normals toward the eye (two-sided lighting tweak):

normal_eye *= float( dot( normal_eye, -vertex_eye ) >= 0 ) * 2. - 1.;

Probably should have used the faceforward built-in, but didn't know about that at the time:

normal_eye = faceforward( normal_eye, vertex_eye, normal_eye );

Erebel55
06-29-2010, 07:02 AM
Thank you very much for your reply.

I tried everything you suggested but the strips are still there..
Here is a screenshot showing this.
New Screenshot (http://i274.photobucket.com/albums/jj265/Erebel55/bugscreeny6.jpg)

CCW is active for glFrontFace. Thank you for the useful tips :)

So, I'm assuming that my index order is wrong? :o

Dark Photon
06-29-2010, 04:38 PM
I tried everything you suggested but the strips are still there..
They weren't intended to fix it. They were intended to help you see what is going on.


Here is a screenshot showing this.
New Screenshot (http://i274.photobucket.com/albums/jj265/Erebel55/bugscreeny6.jpg)

CCW is active for glFrontFace. ... So, I'm assuming that my index order is wrong?
Kind of what it looks like, assuming this is supposed to be a regular grid of triangles. Looks like you're missing indices for a bunch of triangles. Notice you can see in the white areas that there are no edges at all. Assuming this is with cullface off (and your shader isn't turning the color to white), then looks like missing indices for certain triangles.

Try drawing a short patch of 10, 20, or however many triangles it takes to see the problem. Then incrementally subtract one triangle at a time from your rendering until you see the problem.