I'm having trouble getting this to work along side the rest of my code. Specifically, using TrueTypeFont makes the rest of my polygons disappear.
I have a simple example that draws a triangle to the screen. If I start using TrueTypeFont, I can get text to draw to the window but the triangle no longer appears. I can't get both the triangle and the text, it is strictly either/or.
I see the same behavior in the test case from the first post on this thread...it draws text but I can't get it to also draw polygons at the same time.
Strangely, simply constructing a TrueTypeObject is enough to hide the triangle. I don't even have to call drawString(). I think I've narrowed it down to the gluBuild2DMipmaps call inside TrueTypeFont. If I comment that out, then my triangle shows up (though obviously the text doesn't). I'm at a loss as to why, though. Anyone have any ideas?
I assume I must be missing something fairly elementary, since I don't see anyone else having trouble.
Here's my code:
import java.awt.Font;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
public class Game {
public static void main(String[] args) throws Exception {
Game game = new Game();
game.Init();
game.Run();
}
private void Init() throws LWJGLException {
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
// Switch to ortho view
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0.0, Display.getDisplayMode().getWidth(), 0.0, Display.getDisplayMode().getHeight(), -1.0, 1.0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
// Set up for text
GL11.glEnable(GL11.GL_TEXTURE_2D); // exture Mapping, needed for text
GL11.glEnable(GL11.GL_BLEND); // Enabled blending for text
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
private void Run() throws LWJGLException {
Font font = new Font("Serif", Font.BOLD, 30);
/*
* If I remove this next line, the triangle is drawn.
* With the line, the triangle isn't drawn
*/
TrueTypeFont trueTypeFont = new TrueTypeFont(font, true);
while (true) {
if (Display.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
break;
}
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
GL11.glLoadIdentity();
GL11.glBegin(GL11.GL_TRIANGLES);
GL11.glVertex2f(100, 100);
GL11.glVertex2f(500, 100);
GL11.glVertex2f(300, 500);
GL11.glEnd();
// trueTypeFont.drawString(0, 0, "Hello", 1, 1);
Display.update();
}
}
}