flickering geometry

Hi guys, i’m a beginner with OpenGL…

i’m trying to draw a translucent rectangle on my terrain, but the rectangle keeps flickering on one of triangle.
I have tried to render it as a triangle strip, but the problem still persist…

could some one please give me some pointers on how should i resolve the issue?

following is the code that i wrote to render the rectangle…

glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_TRIANGLE_STRIP);
glColor4f(glowR, glowG, 0.0f, glowTransparency);
glVertex3d(MAP_SIZE_X, 0, 0);

glColor4f(glowR, glowG, 0.0f, glowTransparency);
glVertex3d(0, 0, 0);

glColor4f(glow2R, glow2G, 0.0f, glowTransparency);
glVertex3d(MAP_SIZE_X, 0, MAP_SIZE_Z);

glColor4f(glow2R, glow2G, 0.0f, glowTransparency);
glVertex3d(0, 0, MAP_SIZE_Z);
glEnd();

glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);

this is the main file, with the projection matrices, viewport and stuff…

/**
* Render the scene
*/
void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 

//set projection matrix and view volume
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (0,1024,0,768, -100, 0);
glMultMatrixd(proj_homograph);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //Reset modelview matrix for new frame.

if(isCalibrationStarted())
{
//calibrate the system
calibrateSystem();
}
else
{
glRotatef(Rotate, 0, 0, 1);

if(locateShape)
{
generateTerrain();
} 
else
{
drawSun();

renderCalibration();
}

renderTerrain();

//Draw translucent objects last
if(!locateShape)
{
if(showTerrain)
{ 
renderWater();

renderEruption();

drawDawn();
} 
else if(isWaterShown())
{
renderWater();
}
}
}//end of else

glFlush();
glutSwapBuffers();
}



//****************************** idle function *******************************
static void idle( void )
{
glutPostRedisplay();
}



//***************************** reshape function *******************************
static void reshape( int width, int height )
{
glViewport(0, 0, (GLint)width, (GLint)height);
}



void initialiseGraphics()
{

glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(0,0);
glutInitWindowSize(1024,768);
projNo = glutCreateWindow("Sandbox Alive!");

glutFullScreen();

glutDisplayFunc(RenderScene);
glutIdleFunc( idle );
glutReshapeFunc( reshape );

ShowCursor(false);
//glutSetWindow(projNo);

glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do

glEnable(GL_CULL_FACE); // Enable Culling
glFrontFace(GL_CCW); // Draw CCW front-facing polygons only

glEnable(GL_POLYGON_SMOOTH); // Antialiasing Polygons

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}





void initialise()
{
initialiseGraphics();
initialiseUI();
initialiseLight();
initialiseWater();
initialiseTerrain();
initialiseCloud();
initialiseValues();
initialiseVolcanoEngine();


//initialise projector homograph
Matrix temp = proj_computeHomograph(point3D, proj_point2D, 6);
temp = cam_computeHomograph(point3D, cam_point2D, 6);

initialiseCam();
previewCam();

cout << "done init" << endl;
}




//************************** Main Function *******************************
int main(int argc, char* argv[])
{
totalHorX = (abs(MAP_SIZE_X/stripeWidth) - rowIndex + 1)/incrementStep + 1;
totalVerZ = (abs(MAP_SIZE_Z/stripeWidth) - colIndex + 1)/incrementStep + 1;

glutInit(&argc, argv);
initialise(); 
glutMainLoop();

return 0;
}

this is a picture and a youtube video of the problem

http://img243.imageshack.us/my.php?image=snc00238hh3.jpg
http://www.youtube.com/watch?v=Uo44LC1upsY

actually the effect is more pronounced when viewed on the screen.
however, the screenshot couldn’t capture the glitches at all

the rectangle is splitted into 2 triangles, wif the top triangle occupy the top left corner, top right corner and bottom right corner.

This triangle flickers alot, has those zebra stripes effect running across.

The other lower triangle has no issue at all

any help will be greatly appreciated!

i looked at screenshot + video but couldnt see any flickering?

flickering is often caused by zfighting (though in this case it prolly isnt)

also glVertex3d etc most hardware only deals with floats so glVertex3f
also enlarge the near/far values in the glOrtho call, it looks like the triangle could be sitting on the extent of one of them

Hi sir,

thanks for the reply

Here’s the image with the shading problem boxed
http://img206.imageshack.us/my.php?image=editedrv1.jpg

Here’s one w/o the problem
http://img294.imageshack.us/my.php?image=clearii1.png

it should b a smooth shading for the red rectangle, but there are areas that appear to be darker than it suppose to
the effect is more obvious when viewed by naked eye, somehow the cameras couldnt capture this effect clearly.

I have tried changing glVertex3d to glVertex3f, but the problem still persist.

as for the zfighting, from my understand on wiki, its overlapping geometry? i have tried rendering only the red rectangle, though the rect still flickers

can i check with you how does the glortho interact with glMultMatrixd and other vertices?
Currently all my objects are drawn in the negative space, ie, negative x, negative z and positive Y

the glMultMatrixd would project everything to a xy plane, with the z coordinates left untouch. Does this affect the glortho? Does the near/far values refer to the z axis after the projection or before the projection? Is the viewer still at the origin, looking down at the negative z axis?

sorry for the questions.

thank you

Try pushing your near clip plane out (and then pulling it in further for kicks) to see if that affects the results. If you have Z precision issues, unless you are rastering multiple triangles overlapping in the same plane, that should show a difference. If not, it’s something else.

Currently all my objects are drawn in the negative space, ie, negative x, negative z and positive Y … Does the near/far values refer to the z axis after the projection or before the projection? Is the viewer still at the origin, looking down at the negative z axis?

After MODELVIEW is applied, you’re in eye space. That is, looking down the -Z axis with +X right and +Y up.

near/far in glOrtho are the negative of the eye space Z coordinate. That is, positive means in front of you (down -Z) and negative means behind you (down +Z). So to your question “before projection”, in eye space. In fact they’re used to compute the projection matrix.

ok I see it, I think thats a vsync issue, you need to turn it ON

from a google
http://www.devmaster.net/forums/showthread.php?t=443

if u have nvidia drivers u can turn it on always from the driver panel (no doubt also with ATI)

or from code, in a cross plateform way :

int (*SwapInterval)(int);

// main init code :
SwapInterval = getProcAddress(“glXSwapInterval”);
if (!SwapInterval)
SwapInterval = getProcAddress(“glXSwapIntervalEXT”);
if (!SwapInterval)
SwapInterval = getProcAddress(“glXSwapIntervalSGI”);
if (!SwapInterval)
SwapInterval = getProcAddress(“wglSwapInterval”);
if (!SwapInterval)
SwapInterval = getProcAddress(“wglSwapIntervalEXT”);
if (!SwapInterval)
SwapInterval = getProcAddress(“wglSwapIntervalSGI”);
// actual vsync activation
SwapInterval(1);

// no vsync, if needed :
SwapInterval(0);

thx for the help guys, appreciate it

but i hav tried the above methods, both turning on or off the vsync doesn’t make the problem goes away :frowning:

is there any other possibilities??/

hi guys,
reporting back my findings…

the flickering does not occur if opengl is rendering in window mode, everything is nice n well…

but the problem is back once it is switched to full screen mode…

is it possible to track if the vsync is actually switching on/off??

btw i’m using a matrox millennium G550 32mb agp gfx if that helps

thx guys

Crappy card … Most probably the zbuffer precision is not sufficient in fullscreen. Do you have a 16 or 24bits zbuffer when doing fullscreen ?

haha, yea, lousy card

is there a way to check the bits??

under the graphics settings, there is an option for 32-bit zbuffer, but the description say that its for direct3d…

the description goes like this,
“Enable this to make a 32-bit Z-buffer available for programs that use Direct3D. Compared to a traditional 16-bit Z-buffer, a 32-bit Z-buffer allows for more accurate 3D depth calculations, but may slow down performance.”

so i suppose its using a 16bit in opengl??

>>is it possible to track if the vsync is actually switching on/off??
I dont think so, what u can do is check the fps if its in vsync it will remain around 60fps (or whatever the monitor is) if not itll be like 200

from the screenshot it looks like vsync issue + not a depth fighting issue

when its windowed its prolly vsynced the same as the desktop