Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to mix 2D and 3D using LWJGL.

I have wrote 2D little method that allow me to easily switch between 2D and 3D.

protected static void make2D() {
    glOrtho(0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, 0.0f, 1.0f);


protected static void make3D() {
    GL11.glLoadIdentity(); // Reset The Projection Matrix
    GLU.gluPerspective(45.0f, ((float) SCREEN_WIDTH / (float) SCREEN_HEIGHT), 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window


The in my rendering code i would do something like:

//draw 2D stuffs here

//draw 3D stuffs here

What i'm trying to do is to draw a 3D shape (in my case a quad) and i 2D image. I found this example and i took the code from TextureLoader, Texture and Sprite to load and render a 2D image.

Here is how i load the image.

TextureLoader loader = new TextureLoader();
Sprite s = new Sprite(loader, "player.png")

And how i render it:

s.draw(0, 0);

It works great.

Here is how i render my quad:

glTranslatef(0.0f, 0.0f, 30.0f);
glScalef(12.0f, 9.0f, 1.0f);

Once again, no problem, the quad is properly rendered.

DrawUtils is a simple class i wrote containing utility method to draw primitives shapes.

Now my problem is when i want to mix both of the above, loading/rendering the 2D image, rendering the quad. When i try to load my 2D image with the following:

s = new Sprite(loader, "player.png);

My quad is not rendered anymore (i'm not even trying to render the 2D image at this point). Only the fact of creating the texture create the issue. After looking a bit at the code of Sprite and TextureLoader i found that the problem appears after the call of the glTexImage2d. In the TextureLoader class:


Commenting this like make the problem disappear. My question is then why? Is there anything special to do after calling this function to do 3D? Does this function alter the render part, the projection matrix?

share|improve this question
You are using deprecated OpenGL features. Try updating your code, better sooner than later... – Eric B Nov 26 '12 at 12:36

Try disabling textures before you draw the quad. If the corner of the texture is transparent, and the texture is still bound when you draw the quad, maybe the whole quad is being drawn with the transparent pixel.

share|improve this answer
Could be. Since you were drawing your quad without textures, and creating the Sprite could have setup the texture for rendering... – Liosan Nov 26 '12 at 10:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.