3D Game with 2D Text/GUI

Started by jeffrey1994, May 16, 2014, 17:04:13

Previous topic - Next topic

jeffrey1994

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.



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);		
	}
}


jeffrey1994

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..

Daslee

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.