Triangle strips not rendered properly. OpenGL driver problem?

I have something really crazy going on in my little OpenGL project. I’m writing some terrain code but I get holes through my terrain all over the place.

I tracked it down to the glVertex3f calls.
If I hardcode a call to glVertex3f with a Z value of 0.035723 it just doesn’t render the triangle!
I switched the triangle strips off and used GL_LINE_STRIPS - same problem!

As soon as I change the Z value to 0.05 it works. If I change the Z value to 0.1 it stops working again.
So I typecast everything through GLfloats just in case - still broken.

It looks like a driver problem to me - what do you guys think?

I’m running SDL + OpenGL + NVidia Linux GLX drivers on Mandrake 9.0 with my faithful old TNT2.

Paul

What projection type are you using (ie ortho, perspective, etc)? What is your near and far set to? If it is not your near clipping plane, then show some code and someone may be able to help you.

Here is my code which I rewrote just to prove that it’s not my code that is the problem.

// Render a strip of triangles
glBegin(GL_TRIANGLE_STRIP);

// Row 1
// First row renders fine
glVertex3f(0, 15, 0.09);
glVertex3f(0, 14, 0.09);
glVertex3f(1, 15, 0.09); // T1
glVertex3f(1, 14, 0.09); // T2
glVertex3f(2, 15, 0.09); // T3
glVertex3f(2, 14, 0.09); // T4

glEnd();

glBegin(GL_TRIANGLE_STRIP);

// Row 2
// This row does not render at all !!
glVertex3f(0, 14, 0.1);
glVertex3f(0, 13, 0.1);
glVertex3f(1, 14, 0.1); // T1
glVertex3f(1, 13, 0.1); // T2
glVertex3f(2, 14, 0.1); // T3
glVertex3f(2, 13, 0.1); // T4

glEnd();

glBegin(GL_TRIANGLE_STRIP);

// Row 3
// This row renders fine
glVertex3f(0, 13, 0.11);
glVertex3f(0, 12, 0.11);
glVertex3f(1, 13, 0.11); // T1
glVertex3f(1, 12, 0.11); // T2
glVertex3f(2, 13, 0.11); // T3
glVertex3f(2, 12, 0.11); // T4

glEnd();

First row renders fine, second one doesn’t render at all and third one is fine.

If I change all the 0.1’s in row 2 to 0.11’s then row two renders! No change in camera or any matrices.

Row 2 should show since it is between row 1 and 3 so it’s definately not a clipping problem.

Hehehe! This one has me flumoxed.
Must be buggy drivers or GL libraries.

Paul

[This message has been edited by surgptr (edited 04-05-2003).]

I think I found the problem.
On Mesa’s web site :

Mesa 5.0 has been released. This is a stable release which implements the OpenGL 1.4 specification.

Bug fixes:
- fixed missing triangle bug when running vertex programs

Let me install Mesa 5.0 and see what happens.

mesa is a software renderer. if you’re using that, then you’re not using your TNT2 at all, which automatically rules out the possibility of a nvidia driver bug. obviously, you want to be using your TNT2 if you can.

posted by sugptr:
Bug fixes:

  • fixed missing triangle bug when running vertex programs

you’re not using vertex programs here (at least not in the code you showed), so that’s not the problem. how are you setting up your projection matrix? can you post the code?

Here is how I set up my projection matrix and viewing transformation.

GLfloat ratio = width / height;

// Set up our viewport so that all of the window is used
glViewport(0, 0, width, height);

// Set the matrix mode to the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Define the perspective characteristics of our virtual world
gluPerspective(45.0, ratio, 0.0, 2000.0);

// In my rendering section I just hardcoded a gluLookAt
gluLookAt(8, 0, 30, 8, 8, 0, 0, 0, 1);

I’m certain it’s not a clipping problem.
I can see objects underneath, above and to the sides of the missing triangles.

For gluPerspective both the near and far should be positive, and I would assume that far should be greater than near… Zero is neither positive nor negative. The near plane should be greater than 0, otherwise the ratio between zFar/zNear ~ infinity and will result in great loss of depth precision. Testing it there was not a problem, especially since your gluLookAt pushes you out 30+ units. So, no it isn’t a clipping problem. I added glPolygonMode just to make sure, but I saw a 2x3 rectangle made of triangles.

So, what is your bit depth? 8, 16, 32???

Just to try it, add glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) to your code just after setting the gluPerspective or somewhere in that bit of code. Tell us what you see.

Set your near for gluPerspective to 1.0, your far to 40.0, keep gluLookAt the same and keep the call glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) and tell us what you see.

the problem is definitely your zFar/zNear ratio. you want this ratio to be as low as reasonably possible, but yours is infinity since zNear is 0. push zNear out some. there are many explanations on the web for why you need to do this. just google for “zFar zNear ratio” and you’ll get lots of stuff. here’s one reference.

from that reference: “Empirically it has been observed that [zFar/zNear] ratios greater than 1000 [produce undesirable results].”

Hah! You guys nailed it right on the head!

Yup, it was the Znear parameter in the gluPerspective call that was messing things up.

I still find it strange though that it was “clipping” the middle row of triangles.

Anyway thanks - you guys rock!
Paul