LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: jeffrey1994 on May 16, 2014, 17:04:13

Title: 3D Game with 2D Text/GUI
Post by: jeffrey1994 on May 16, 2014, 17:04:13
I have a problem drawing text in a 3D perspective..

This is the function I call at the END of my render() function.


private void debugInfo()
{
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0, Window.getWidth(), Window.getHeight(), 0, -1, 1);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
   
              fontRenderer.drawString("FPS: " + coreEngine.getFPS(), 15, 25);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();

      glViewport(0, 0, Window.getWidth(), Window.getHeight());
      gluPerspective(45f, (float)(Window.getWidth() / Window.getHeight()), 0.001f, 1000f);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
}


I'm switching from 3D to 2D and then back to 3D but the text I'm trying to draw is just using the wrong texture or something.

(http://i62.tinypic.com/2942ved.png)

My FontRenderer class with Slick UnicodeFont.

public class FontRenderer
{
private UnicodeFont font;

public FontRenderer()
{
try
{
font = new UnicodeFont(new Font("Verdana", Font.BOLD, 12));
font.getEffects().add(new ColorEffect());
font.addAsciiGlyphs();
font.loadGlyphs();
}
catch (SlickException e)
{
e.printStackTrace();
}
}

public void drawString(String text, int x, int y)
{
font.drawString(x, y, text, Color.red);
}
}

Title: Re: 3D Game with 2D Text/GUI
Post by: jeffrey1994 on May 16, 2014, 22:23:22
I think it has to do with my shader? If I don't call glUseProgram it works but now uses the wrong texture on the cubes..
Title: Re: 3D Game with 2D Text/GUI
Post by: Daslee on May 17, 2014, 13:22:14
Yes, that's probably problem in the shaders, but you could simply not use that program while rendering 2d stuff and use only rendering 3d stuff.