Cylinder artefact
Hi I am experiencing artefacts with cylinders in my code. Please look at the images attached and if you have any ideas let me know. Thanks.
Looks like you don't have depth testing enabled. Try adding this command in your GL initialization routine:
Greets
Chris
glEnable(GL_DEPTH_TEST);
Greets
Chris
Thanks for the reply. I have enables depth testing. Here is my code.
glClearColor(0.0, 0.0, 0.0, 0.0); // Set the background color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST); // Enable depth testing.
glEnable(GL_CULL_FACE); // Enable culling.
glFrontFace(GL_CCW); // Enable counter clockwise culling.
glEnable(GL_LIGHTING); // Enable lighting.
float specularLight[] = {1.0f, 1.0f, 1.0f, 1.0f};
float diffuseLight[] = {1.0f, 1.0f, 1.0f, 1.0f};
float ambientLight[] = {0.0f, 0.0f, 0.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
// Render RSRnodes
RSRnodes::iterator i;
for (i = nodes.begin(); i != nodes.end(); i++)
{
i->second->render();
std::cout << "Currently rendering RSRnode with ID = " << i->second->getID() << std::endl << std::flush;
}
glutPostRedisplay();
glutSwapBuffers();
glClearColor(0.0, 0.0, 0.0, 0.0); // Set the background color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST); // Enable depth testing.
glEnable(GL_CULL_FACE); // Enable culling.
glFrontFace(GL_CCW); // Enable counter clockwise culling.
glEnable(GL_LIGHTING); // Enable lighting.
float specularLight[] = {1.0f, 1.0f, 1.0f, 1.0f};
float diffuseLight[] = {1.0f, 1.0f, 1.0f, 1.0f};
float ambientLight[] = {0.0f, 0.0f, 0.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
// Render RSRnodes
RSRnodes::iterator i;
for (i = nodes.begin(); i != nodes.end(); i++)
{
i->second->render();
std::cout << "Currently rendering RSRnode with ID = " << i->second->getID() << std::endl << std::flush;
}
glutPostRedisplay();
glutSwapBuffers();
I believe it might be z-buffer fighting. My CG website has a FAQ on how to prevent that from happening.
Tom
Tom
It doesn't look like a no-depth-testing problem, since there is clearly some correctly depth sorted geometry (quite a bit of it in fact). Instead I would expect either a lack of depth buffer precision (16 bit) and/or too large a depth range. Assuming you're using plain Win32 calls, check your depth buffer precision by calling DescribePixelFormat(hdc, pixelFormat, &pfd); after you've called ChoosePixelFormat and print out the cDepthBits member of pfd. Also, what does your glFrustum/gluPerspective call look like?
Enigma
Enigma
The z buffering was the problem. Thanks for your help guys.
I had
gluPerspective(45.0, (float)width / (float)height, 0.1, 1000.0);
just tweak the near and far plane and was fine.
I had
gluPerspective(45.0, (float)width / (float)height, 0.1, 1000.0);
just tweak the near and far plane and was fine.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement