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 7738859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:22:33+00:00 2026-06-01T08:22:33+00:00

What would I need to add to my OpenGL init method to enable depth

  • 0

What would I need to add to my OpenGL init method to enable depth testing, and how would I actually use it for texture layering?

I would have to extend the last parameter of glOrtho to something more extreme than -1, and of course glEnable depth testing. Then to use it, I can only assume that I change the third parameter of glVertex to something that isn’t 0 to send it in front / behind of other textures.

I try this, and the damn textures don’t even show. xD I must be missing something.


EDIT: RE: Tim’s response

whenever i made the image’s z more extreme than -1 it didnt show the screen was just black.

void initGL(){

GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_DEPTH_TEST); //depth test enabled

    GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glOrtho(-width/2, width/2, -height/2, height/2, 1, -10);//far changed to -10
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

}

and

void loadBG(int theLoadedOne){

GL11.glBindTexture(GL11.GL_TEXTURE_2D, theLoadedOne);
GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0,0);
GL11.glVertex3f(-width/2,height/2, -2);//new z value

    GL11.glTexCoord2f(1,0);
GL11.glVertex3f(width/2,height/2,-2);//new z value

    GL11.glTexCoord2f(1,1);
GL11.glVertex3f(width/2,-height/2,-2);//new z value

    GL11.glTexCoord2f(0,1);
GL11.glVertex3f(-width/2,-height/2,-2);//new z value

GL11.glEnd();
GL11.glFlush();

}

and

while(!Display.isCloseRequested()){
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

...

            for(int i=0;i<1;i++){  //dont mind this for loop
                bg.loadThisBG(0);  //its here for reasons
            }
            updateFPS();

        Display.update();

    } Display.destroy();

}
  • 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-06-01T08:22:35+00:00Added an answer on June 1, 2026 at 8:22 am

    Seems like you switched near and far plane. Have a look at gluOrtho2D. It just calls glOrtho with near=-1 and far=+1, resulting in the z coordinates switching sign (m33=-2/(far-near)). However, with the values given above, m33=-2/(-10-1) is positive, and the z axis reversed to standard workflow.

    This consequences in the quad being viewed from the back.

    OpenGL matrix manipulation methods do no care what you feed them; except when values would led to a division by zero.


    Assuming there is no modelview transform, and only the one matrix contributing to the projection one, here is what I think is happening:

    The z value transform from world to NDC space is z_ndc = -9/11 * z_w + 2/11 (set near and far into the orthographic matrix and take the third row). Now, z_w=-2, and so z_ndc = 20/11. This is out of the NDC space boundaries and thrown away.

    Well, I assume that this test is implicitly enabled/disabled with the Z test itself. Next suspect would be backface culling…

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

Sidebar

Related Questions

What assembly do I need to add to my project to use OpenGL in
Does anyone know the display formatter that I would need to add to the
I need to add a C# solution with examples that would be distributed as
I need to add a file upload function to an ASP.NET website and would
The exercise I have is the following: In display() add a method drawLine. Probably,
I have a program in which I need to apply a 2-dimensional texture (simple
I have written an application using opengl es view. Now I want to add
I have a website where users may upload images... I need to add my
I would need to create a temp table for paging purposes. I would be
I would need some basic vector mathematics constructs in an application. Dot product, cross

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.