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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:44:56+00:00 2026-05-27T15:44:56+00:00

I’m trying to make a copy of MineCraft in Java using OpenGL (LWJGL). The

  • 0

I’m trying to make a copy of MineCraft in Java using OpenGL (LWJGL). The problem I’m facing is that everything of my 2D overlay (aiming cross in the middle, menus, etc…) are all white. The 3D part of the game works great: every cube has a texture on each side.

But when I try to draw the overlay, as I said, every texture is white, but I can see the shape of it (because it has transparent areas). I’ll add a picture of it.

enter image description here
(This is supposed to be the inventory)

As you can see, the overlay is completely white. And it should look like this:

enter image description here

I’m already searching the web for hours. Can’t seem to find a solution.
This drives my crazy… I already searched for instructions of how to create a 2D overlay on a 3D scene, but they don’t help either. So I though, I’ll give StackOverflow a try.

Hopefully someone can help me?
Thanks for reading my question and for the (hopefully coming) answers!

Martijn

Here is the code:

Initialising OpenGL

public void initOpenGL() throws IOException
{
    // init OpenGL
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 800, 600, 0, 1, 300);
    glMatrixMode(GL_MODELVIEW);

    float color = 0.9f;

    glClearColor(color, color, color, color);
    glEnable(GL_TEXTURE_2D);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    glShadeModel(GL_FLAT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_CULL_FACE);


    glEnable(GL_FOG);
    glFog(GL_FOG_COLOR, MineCraft.wrapDirect(color, color, color, 1.0f));
    glFogi(GL_FOG_MODE, GL_LINEAR);
    glFogf(GL_FOG_START, _configuration.getViewingDistance() * 0.8f);
    glFogf(GL_FOG_END, _configuration.getViewingDistance());
    glFogi(NVFogDistance.GL_FOG_DISTANCE_MODE_NV, NVFogDistance.GL_EYE_RADIAL_NV);
    glHint(GL_FOG_HINT, GL_NICEST);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

Configuring the matrixes for drawing the overlay (Out of inspiration, I literally copied all the OpenGL calls for this method from BlockMania (another open-source MineCraft copy), which works great)

public void renderOverlay()
{
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    GLU.gluOrtho2D(0, conf.getWidth(), conf.getHeight(), 0);
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_COLOR_MATERIAL);
    glPushMatrix();
    glLoadIdentity();

    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    /** RENDER **/
    if (_activatedInventory != null)
    {
        _activatedInventory.renderInventory();
    }

    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
}

Drawing the texture itself:

public void renderInventory()
{
    Configuration conf = Game.getInstance().getConfiguration();

    glTranslatef(conf.getWidth() / 2.0f, conf.getHeight() / 2.0f, 0.0f);

    glEnable(GL_TEXTURE_2D);
    Texture tex = TextureStorage.getTexture("gui.inventory");
    tex.bind(); // newdawn.slick (same library for my whole program, so this works)

    float hw = 170; // half width
    float hh = 163; // half height

    Vector2f _texPosUpLeft = new Vector2f(3, 0);
    Vector2f _texPosDownRight = new Vector2f(_texPosUpLeft.x + hw, _texPosUpLeft.y + hh);

    _texPosUpLeft.x /= tex.getTextureWidth();
    _texPosUpLeft.y /= tex.getTextureHeight();
    _texPosDownRight.x /= tex.getTextureWidth();
    _texPosDownRight.y /= tex.getTextureHeight();

    glColor3f(1, 1, 1); // Changes this doesn't make any effect
    glBegin(GL_QUADS);
    glTexCoord2f(_texPosUpLeft.x, _texPosUpLeft.y);
    glVertex2f(-hw, -hh);
    glTexCoord2f(_texPosDownRight.x, _texPosUpLeft.y);
    glVertex2f(hw, -hh);
    glTexCoord2f(_texPosDownRight.x, _texPosDownRight.y);
    glVertex2f(hw, hh);
    glTexCoord2f(_texPosUpLeft.x, _texPosDownRight.y);
    glVertex2f(-hw, hh);
    glEnd();
}

(The texture pack I’m using is CUBISM1.00)

  • 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-27T15:44:57+00:00Added an answer on May 27, 2026 at 3:44 pm

    I found it!!

    It was the fog. For one or another reason it looks like it thinks the overlay is out of sight and gives it the color of the fog. So, disabling the fog before rendering the overlay solved it.

    glDisable(GL_FOG);
    
    /* Render overlay here */
    
    glEnable(GL_FOG);
    

    If there are still people who read this, is this caused by matrix abuse or is this behaviour normal?

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.