PDA

View Full Version : GL_DEPTH_TEST causes rendering problems with trian



BahamutZaero
05-02-2010, 01:31 AM
I've got my OpenGL ES code working and rendering great and very fast, however I'm now having a weird issue related to depth tests. What happens is any vertice whose Z value is not exactly 0.0f causes that entire portion of the object to not get drawn. So if the Z values of the 4 points are 0.1f,0.0f,0.0f,0.0f, then the entire top-left triangle will not be drawn at all (which makes sense - if there was something occluding it, which there isn't as I'm testing this with only one object in the scene).

Here is the code I'm using:

//PUAP -Mat use GL_MODULATE to tint, GL_REPLACE for texture only
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

// Clear our color and depth buffers
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

// Array of render vertices
GLfloat renderObjVects[] =
{
-1.0f, -1.0f, 0.1f, // Bottom Left
1.0f, -1.0f, 0.0f, // Bottom Right
-1.0f, 1.0f, 0.0f, // Top Left
1.0f, 1.0f, 0.0f // Top Right
};

// Array of texture coordinates
GLfloat texCoords[] =
{
1.0f, 0.0f,
0.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f
};

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

// Enable Properties
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

// Set our blend types
glBlendFunc(GL_ONE, GL_SRC_COLOR);

// Enable depth checking so objects can layer
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepthf(1.0f);
glClear(GL_DEPTH_BUFFER_BIT);

// Enable our pointers.
glVertexPointer(3, GL_FLOAT, 0, renderObjVects);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

// Set our Projection Mode
glMatrixMode(GL_MODELVIEW);

// Set the shading model
glShadeModel(GL_SMOOTH);


// Clear things out
glColor4f(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glLoadIdentity();

// Bind this imagemap for use
glBindTexture( GL_TEXTURE_2D, thisData.mpPageTextureHandle->getGLName() );

// Now... let's draw!
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

Here is a screenshot of the problem in action using the above code: Picasa Image Link of a Banana (http://picasaweb.google.com/109821053317077386155/General#5466414937401835458)