Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7699051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:23:17+00:00 2026-05-31T22:23:17+00:00

My understanding of OpenGL rendering was that without a depth test, objects would be

  • 0

My understanding of OpenGL rendering was that without a depth test, objects would be drawn in sequential order, so that the last render function you call will draw its shape on top of whatever has already been drawn. I’m finding that this seems to not be the case however:

glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);


glColor3f(1.0, 0.0, 0.0);
glBegin(GL_QUADS);
{
    glVertex2f(50, 50);
    glVertex2f(100, 50);
    glVertex2f(100, 100);
    glVertex2f(50, 100);
}
glEnd();


glColor3f(0.0, 0.0, 1.0);
glBegin(GL_QUADS);
{
    glVertex2f(30, 60);
    glVertex2f(110, 60);
    glVertex2f(110, 90);
    glVertex2f(30, 90);
}
glEnd();

Rather then the red square under the blue square, which I would expect, these calls give me a red square over a blue square!

Do I not understand how OpenGL Rendering works? Or am I just missing some kind of option or configuration thats not letting the blue square render over? I am using a custom (but very simple) shader, would that change anything?

The non accepted answer to this question seems to imply that sequential rendering doesn’t in fact occur and is implementation specific, but its accepted answer implies it is in fact the case.

Whats the best way of making the second call on top? I don’t really want to have to have some kind of global z value that I keep on incrementing throughout the program.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:23:18+00:00Added an answer on May 31, 2026 at 10:23 pm

    render function you call will draw its shape on top of whatever has already been drawn.

    That’s right.

    I’m finding that this seems to not be the case however:

    This works for me:

    #include <SDL/SDL.h>
    #include <GL/glew.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
    #include <math.h>
    
    static int scrWidth = 640;
    static int scrHeight = 480;
    
    int main(int argc, char** argv){
        SDL_Init(SDL_INIT_VIDEO);
    
        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_DEPTH_SIZE, 16);
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
    
        if (SDL_SetVideoMode(scrWidth, scrHeight, 32, SDL_OPENGL) == 0){
            fprintf(stderr, "couldn't set mode %dx%d!\n", 640, 480);
            SDL_Quit();
            return -1;
        }
        glewInit();
    
        SDL_ShowCursor(SDL_DISABLE);
    
        glClearColor(0.2, 0.2, 0.2, 0.2);
        glClearDepth(1.0);
    
        glEnable(GL_DEPTH_TEST);
    
        bool running = true;
        while (running){
            SDL_Event event;
            if (SDL_PollEvent(&event)){
                switch(event.type){
                    case SDL_QUIT:
                        running = false;
                        break;
                };
            }
            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            gluOrtho2D(0, scrWidth, scrHeight, 0);
    
            glColor3f(1.0f, 0.0f, 0.0f);
            glBegin(GL_QUADS);
            glVertex2f(50, 50);
            glVertex2f(100, 50);
            glVertex2f(100, 100);
            glVertex2f(50, 100);
            glEnd();
    
    
            glColor3f(0.0, 0.0, 1.0);
            glBegin(GL_QUADS);
            glVertex2f(30, 60);
            glVertex2f(110, 60);
            glVertex2f(110, 90);
            glVertex2f(30, 90);
            glEnd();
    
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
    
            glFlush();
            SDL_GL_SwapBuffers();       
        }   
    
        SDL_Quit();
        return 0;
    }
    

    Compare with your code and see if there’s a difference. Perhaps you didn’t really disable depthtest. You could also get the same problem if you use stencil buffer in your code with certain combinations of stencil buffer parameters (something like glStencilFunc(GL_NOTEQUAL, 0, 0xffffffff); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);). You could also get same effect if you forget to use glClear and insert “swap buffers” call between first and second polygon.

    am using a custom (but very simple) shader, would that change anything?

    Yes it could change everything. However, in this case it means that you haven’t provided enough information to help you with your problem. When you want help with your code you should post complete and functional, but minimal example that illustrates your problem. “Forgetting” to post this example is a bad idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My understanding of Hibernate is that as objects are loaded from the DB they
I am rendering an OpenGL scene that include some bitmap text. It is my
I would like to render image in OpenGL ES, pixel by pixel. I want
From my understanding, the objects would get clipped. Is this correct? And how would
Understanding that I should probably just dig into the source to come up with
My understanding is that wxWidgets is for a number of programming languages (C++, Python,
My understanding is that C/C++ produces native code to run on a particular machine
My understanding is that in unix, when memory is freed, the memory doesn't get
I am trying to build my understanding of OpenGL and see how the 'pros'
The Problem (TL;DR) My problem, fundamentally, is that I do not know how OpenGL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.