I’m working on a small learning project using lwjgl without helpers such as slick2d. So far everything has been easier than expected, but I just noticed while developing an inventory system for my game, that I cannot render text and sprites together?
This is a microsoft paint edit, of how it should render:
Here is the code from my Inventory interface:
public void render() {
textureManager.draw("tray", 124, trayRenderHeight);
GL11.glColor3f(1, 1, 0); // yellow
for (int i = 0; i < slot.length; i++) {
if (slot[i] > -1 && count[i] > 0) {
GLString.drawString("" + count[i], 124 + (i * 36), trayRenderHeight, false);
}
}
}
And here is the 2D rendering code which the inventory display is called in:
private void preRender2D() {
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
//GL11.glOrtho(0, Display.getWidth(), 0, Display.getHeight(), -1, 1);
GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, -1, 1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glLoadIdentity();
/*
* Next, we need to enable blending. Without this enabled, transparent sprites may not render as expected.
*/
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
white.bind(); // so that 2D colors wont mix
}
private void render2D() {
if (renderDebug) {
GL11.glColor3f(0, 0, 0); // black
GLString.drawString("FPS: " + lastFrameCount, 10, 10, FontType.PLAIN);
GLString.drawString("MEM: " + LocalMachine.getMemoryUsage() + "M", 10, 25, FontType.PLAIN);
GLString.drawString("Mouse: " + getMouseX() + ", " + getMouseY(), 10, 40, FontType.PLAIN);
//GLString.drawString("Mouse 3D: " + mouse3dX + ", " + mouse3dZ, 10, 55, false);
GLString.drawString("Player: " + player.getX() + ", " + player.getZ(), 10, 70, FontType.PLAIN);
GLString.drawString("Chunk: " + chunkX + "-" + chunkZ, 10, 85, FontType.PLAIN);
}
if (!renderFrame) {
chatbox.render();
inventory.render();
// TODO : figure out why textures have to be rendered last, because none of the strings will draw if a texture is rendered before them (same error is now happening with inventory class)
for (int i = 0; i < 5; i++) {
textureManager.draw("hp", Display.getWidth() - (33 * i) - 40, 0);
}
textureManager.draw("pointer", getMouseX() - 8, getMouseY() - 8);
if (renderBrand) {
textureManager.draw("brand", Display.getWidth() / 2 - 250, Display.getHeight() / 2 - 150);
}
}
}