Jump to content
  • Advertisement
Sign in to follow this  
Koen VB

Jagged polygon edges

This topic is 4502 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

I have a problem with jagged polygon edges. I have written some code to load a mesh from an Anim8or file and display it. The code loads vertex coördinates, normals and polygons. Now I created a dodecahedron and loaded it in my test application. The polygons don't have any color or material assigned to them. A single point light source is positioned near the object. This is what it looks like: http://img150.imageshack.us/img150/8920/0027dg.png Some polygon edges look horribly jagged. This changes when the object is rotated. When facing towards the camera, the edges appear smooth but when they are about to disappear towards the rear side they are messed up. When I disable the lights the effect also disappears. This is the same object in the same orientation, without lights: http://img95.imageshack.us/img95/2466/0035qr.png Has anyone else ever had this problem?

Share this post


Link to post
Share on other sites
Advertisement
This is called aliasing. The solution, not surprisingly, is called anti-aliasing. There is quite a bit of information you can attain via google about OpenGL and anti-aliasing. There is built-in support for anti-aliasing in OpenGL.

Share this post


Link to post
Share on other sites
Forgot to tell that. I think I enabled it, like this:

glEnable(GL_POLYGON_SMOOTH);

Is there anything else I need to do to enable anti-aliasing?
Also, I changed the background color to red. This what the object looks like:

http://img90.imageshack.us/img90/3093/0043rz.png

Now you can see a smooth edge on the polygon, it seems like the problem is with the lighting or something.

Share this post


Link to post
Share on other sites
for me it doesnt look like antialiasing is the solution. whats your projection matrix?

the antialias thing: google for opengl multisampling

Share this post


Link to post
Share on other sites
I've seen this problem before. The cause is the call to gluProjection. Make sure the value of the zNear parameter is not zero. I'm not sure why setting it to zero causes the problem with lighting, but I normally set that parameter to 0.1 and it cures the problem.

Clayton

Share this post


Link to post
Share on other sites
I also have this problem. I think there is no real solution for it.
The problem occurs because the Z-Buffer rounds the depth values.
So if 2 polygons are close, the depth value is rounded to the same value, and OpenGL doesn't know which one is in front.
This explains why the problem appears at the sides of for example a cube. At the edges, the polygons are really close.

When you set the projection mode (glOrtho/gluPerspective), make sure the value of zNear is not to low, and the value of zFar is not to high (zNear has teh biggest influence).

You can also make a z-buffer that can hold more precise values. In the code below, i create a z-buffer that can hold 16 bit values. Setting this to 24 or 32 would give nicer graphics, but slow down the rendering.

For some reason setting a 24/32 bits depth buffer didn't help me. I guess my prehistoric gforce2 cant handle depth buffers with more than 16 bits?


static PIXELFORMATDESCRIPTOR pfd = // pfd tells windows how we want things to be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size of this pixel format descriptor
1, // Version number
PFD_DRAW_TO_WINDOW | // Format must support window
PFD_SUPPORT_OPENGL | // Format must support OpenGL
PFD_DOUBLEBUFFER, // Must support double buffering
PFD_TYPE_RGBA, // Request an RGBA format
bits, // Select our color depth
0, 0, 0, 0, 0, 0, // Color bits ignored
0, // No alpha buffer
0, // Shift bit ignored
0, // No accumulation buffer
0, 0, 0, 0, // Accumulation bits ignored
16, // 16Bit Z-Buffer (Depth buffer)
0, // No stencil buffer
0, // No auxiliary buffer
PFD_MAIN_PLANE, // Main drawing layer
0, // Reserved
0, 0, 0 // Layer masks ignored
};



Share this post


Link to post
Share on other sites
First of all, thanks everybody for the help. I followed Thork's advice. The problem was indeed the call to glPerspective. I set the near parameter to 1 instead of 0.1 and the problem was solved.

Share this post


Link to post
Share on other sites
Moving the Znear to 0.0f causes a loss of depth-buffer precision, which is only 24-bit in current hardware solutions.
Therefore, the lighting calculations cannot take place in a normal way. Try moving the farplane to -1.0f and see what losing even more precision causes.

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!