Jump to content
  • Advertisement
Sign in to follow this  
agrant

Cylinder artefact

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Looks like you don't have depth testing enabled. Try adding this command in your GL initialization routine:


glEnable(GL_DEPTH_TEST);



Greets

Chris

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!