Archived

This topic is now archived and is closed to further replies.

Problems in displaying Graphics

This topic is 5747 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 am new in OpenGL. I tried drawing a Square and a triangle, with the triangle in front of the square with a distance of 0.01f in the z axis. The problem is that when i rotated the view to the back, the triangle is still in front of the square, which shouldn''t be the case. The grahics generated seems to integrate each other producing some weird lines on the triangle too. I am using the NeHe Tutorial 2 to do this... Can anyone tell me what is wrong? I just want the triangle to appear sticking on to the square...

Share this post


Link to post
Share on other sites
Hello, I am also new to OpenGL, but it sounds to me like you're having some z-fighting. Z-fighting happens when two objects are too close together (Your computer has trouble deciding which one to show first, so it tries to show both on the same plane). Try moving the triangle away from the square a bit more.

[edited by - Kaelus on March 21, 2002 11:43:50 PM]

Share this post


Link to post
Share on other sites
I know how to solve your problem with Direct3D8 (it''s actually very simple).

I did some digging and there are a number of ways to do it with OpenGL.

The official OpenGL website has a lot to say about it. One way is to tweak the far and near clipping planes when rendering overlapping primitives. Check it out at this link:

http://www.opengl.org/developers/faqs/technical/polygonoffset.htm

I don''t know which method is best in OpenGL. Direct3D provides a way to do it for you, and if I had to guess it just adds 1 to the value it stores in the Z Buffer for each pixel. However adding 1 would create other problems in some situations.

Actually, the best solution is usually multi-texturing, but that is not always possible.

--TheMuuj

Share this post


Link to post
Share on other sites
Oops.. I may have misread your problem.

If your polygons are CLOSE but NOT overlapping, you might try just modifying your near and far clipping planes. If your far plane is too far away from the camera, or the near is too close, you lose precision in your Z-Buffer. A Z-Buffer with a higher depth will usually help, but you can''t rely on having a 32-bit Z-Buffer available.

If you can''t move your clipping planes, then try the solution I posted before.

--TheMuuj

Share this post


Link to post
Share on other sites
i think you need to turn on depth testing

glEnable(GL_DEPTH_TEST);

that''s all...

Yours might be bigger. Yours might be harder. BUT, mine is multi textured, bump-mapped, pixel shaded & fully user customizable!

Share this post


Link to post
Share on other sites
I don''t know if this is what you''re looking for but if you want it to look like there is a triangle on the surface of a square you could load a texture that has a tringle on it and apply it to the square.

Share this post


Link to post
Share on other sites
This is part of the program that i modified from NeHe's Lesson2. Zoom, tiltx, tilty are for navigation purpose.

=================================================================
glTranslatef(0.0f,0.0f,zoom);
glRotatef(tiltx,1.0f,0.0f,0.0f);
glRotatef(tilty,0.0f,1.0f,0.0f);

glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd();

glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.035f); // Top
glVertex3f(-1.0f,-1.0f, 0.035f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.035f); // Bottom Right
glEnd();
=================================================================

I need to set the distance to a minimum of 0.035f to prevent the so called Z-Fighting.. But Is there a way to create the triangle closer to the square w/o Z-Fighting as a gap can be seen between the shapes currently..
But if I navigate from further away... Z-fighting occurs again

Muuj, I don't understand the clipping planes.. Can you direct me to some tutorials and how to make Z-buffer with a higher depth?

I consider using texture but If I use a texture, I will not be able to manipulate the triangle to what i want... My Concept of Texturing is importing pictures into OpenGL..am I right?

Thanks to everyone who trys to help me





[edited by - knight on March 22, 2002 3:13:41 AM]

Share this post


Link to post
Share on other sites
Like I said, I'm not an expert at OpenGL. I have done a little coding with it, but I have not learned much more than the basics.

As for any tutorials, the ones I use are at NEHE's site, and at GameTutorials.com.

As for changing the depth of the Z-Buffer, I think that requires you to use an OpenGL extension, which I have never tried.

What is your far clipping plane set at (this is set when you set the viewing frustrum)? If it is really far away, and you don't have any objects that far away, you should probably make the clipping plane closer. This also (often times) requires you to add fog to make your scene look good, but work on getting the clipping planes set correctly first.

If not, you need to use one of the many techniques for preventing Z Fighting with OpenGL. I'm not sure what the correct term is, but I think Z-Bias is one of them (correct me if I'm wrong).

And texturing is basically drawing images on your primitives. Sometimes, you can draw multiple images on one primitive (multitexturing), which in many cases is a way of avoiding Z-Fighting all together.

But if you actually need to render one primitive close to or overlapping another primitive, you will need to fix the Z-Fighting.

You might also try using a different function for your Z-Test. Once again, I don't know how to do this in OpenGL. It may be something like glDepthFunc...

Can anyone else give more specifics? I know in general what needs to be done, but I don't know enough about OpenGL to help.

--TheMuuj

[edited by - TheMuuj on March 22, 2002 7:08:19 PM]

Share this post


Link to post
Share on other sites
qint read everything (to pissed) but try these in order of preference

A/ move the near clip plane out
B/ check out glPolygonOffset
C/ hack it ala d3d eg with glDepthRange(0,0.99)

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites