Z-Order in 2D

Started by
6 comments, last by kloffy 14 years, 2 months ago
Okay, this is tricky. I am drawing each Object in my Code isolated from the others. Meaning, if I change a state in OpenGL, I switch it back at the end of the Object's Rendering-Method. I give the Z-Value of my Vertices a value, but it is ignored. Is there a way to draw stuff without sorting it for z-order? Because I rather would like to sort it by texture-usage. Example: Quad A has a Z-Order of 1.0, but it is still rendered behind Quad B which has a Z-Order of 0.9 and vice versa. All what matters is in which Order I draw them. Is there a way to get around that? Thanks for help. o/
Advertisement
Maybe I'm missing something, but glDisable(GL_DEPTH_TEST) should do the job.
Or, glEnable(GL_DEPTH_TEST), depending on how you read the question... xD
If I disable GL_DEPTH_TEST, all I get is a black Screen, because I use blending...
regards
Blending won't change this simple fact : if you do depth testing, polygons "closer" to the eye will be drawn on top, regardless of the rendering order. If you disable depth testing, the last polygon rendered will be on top. When you use blending with depth testing on, however, you must render the polygons in far-first, near-last order because otherwise the result is not correct, but you shouldn't get a black screen. your black screen must have another cause. Did you try disabling depth test, with blending turned on and off ?
Are you sure you're correctly initing/creating a z-buffer? This may be the problem; AFAIK most cards support a 24bit depth + 8bit stencil buffer.
I use SDL to initialise OpenGL.
    // OpenGL-Flags    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, m_settings.fsaa);

Then I set my OpenGL-Settings:
void WindowGL::initGL2D(int w, int h){    // Set Viewport    glViewport(0, 0, w, h);    // Set OpenGL-Options    glClearDepth(1.0f);    glDisable(GL_DEPTH_TEST);    glDepthMask(true);    glShadeModel(GL_SMOOTH);    glEnable(GL_CULL_FACE);    glCullFace(GL_BACK);    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);        // Reset Projection-Matrix    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    // Set view-mode    glOrtho(0, w, h, 0, 1.0f, -1.0f);    // Reset Modelview-Matrix and leave it.    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();}


It does not make any difference, which value the z-vertices of my Quads get, for example Quad A is only in front of Quad B if I render it first.
I am confused tbh.
regards
Quote:Original post by RorqualPilot
It does not make any difference, which value the z-vertices of my Quads get, for example Quad A is only in front of Quad B if I render it first.
I am confused tbh.
regards

Like I said, I think Farfadet misinterpreted your question. If you want Quads that are closer to the viewer to be rendered in front of ones that are further away without sorting them you need to glEnable(GL_DEPTH_TEST) and leave glDepthMask(GL_TRUE). Also, don't forget to clear the depth buffer, i.e. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT).

This topic is closed to new replies.

Advertisement