0

I'm drawing triangles with only x and y coordinates per vertex:

glVertexPointer(2, GL_FLOAT, 0, vertices);

Sometimes when I draw a triangle over another triangle they seem to be coplanar and the surface jerks because they share the exact same surface in space.

Is there a way of saying "OpenGL, I want that you draw this triangle on top of whatever is below it" without using 3D coordinates, or do I have to enable depth test and use 3D coordinates to control a Z-index?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Proud Member
  • 40,078
  • 47
  • 146
  • 231

1 Answers1

3

If you want to render the triangle just on top of whatever was in the framebuffer before, you can just disable the depth test entirely. But if you need some custom ordering different from draw order, then you won't get around adding additional depth information (in the form of a 3rd z-coordinate). There is no way to say to OpenGL "render the following stuff but with the z-coordinate collectively set to some value". You can either say "render the follwing stuff on top of whatever is there" or "render the following stuff on whatever depth results from its transformed vertices".

Christian Rau
  • 45,360
  • 10
  • 108
  • 185
  • The problem is that the triangles I draw "on top" of others seem to intersect with them because they are coplanar, and it creates jagging / jittering effects on the coplanar surfaces when they move. How do you say "render the follwing stuff on top of whatever is there"? Simply by calling glVertexPointer(2, GL_FLOAT, 0, vertices); again and again for each set of triangles to cover others? – Proud Member Nov 26 '13 at 14:06
  • @ProudMember *"seem to intersect with them because they are coplanar"* - That kind of depth fighting only happens if the the depth test is enabled. If you just want to draw the triangle on top of whatever was there before, why do you use depth testing at all? Either you want a specific order, then you have to use depth testing and give your triangles reasonably different depths (so they shouldn't be coplanar). Or you want to sort them in draw order, then you just don't use any depth testing at all. – Christian Rau Nov 26 '13 at 15:24
  • Then it makes sense. I thought I was sure depth testing was disabled when this problem surfaced. Thanks for the tip. – Proud Member Dec 02 '13 at 10:54