Question

I'm still new to OpenGL ES 2.0 and have come to understand the transformation matrix operations moderately well. Though I'm a little unclear on the relevance of the z-order when drawing a primitive. For instance, when I use a perspective projection matrix and transform the vertices of a quad with it, it will indeed draw the quad smaller (so that it would appear further away). However when I draw a quad at a greater z-order first and another quad at a lesser z-order second, the second quad still appears in front of the first. Is this expected for ES 2.0 or do I need to enable something else? Is it necessary that I sort the quads by z-order or is there another way around this by enabling a setting?

For example, draw the first quad at (0, 0.5, 0) and the second at (0, 0.5, -2.0). The second appears smaller due to the perspective transform, but in front of the first. Both quads have the same vertices. Perhaps I should also mention that when drawing these quads, I'm not doing it in one call to glDrawElements(), I'm calling glDrawElements() in a loop, e.g. drawing each model of a list.

Was it helpful?

Solution

Unless you are basically doing a 2D application, you don't want to manually sort your primitives, you'll want to use a depth buffer (z-buffer). An OpenGL ES 1.1 turial on the topic is here, this stuff isn't any different in ES 2.0.

Make sure to google for some help getting the depth buffer setup on your specific platform, the color / depth buffer setup is different in iOS/Android/GLUT/etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top