I'm programming a 3D game engine with 2D GUI. The GUI objects have partially transparent textures and the transparency works more or less. The sky color is rendered in transparent areas of the textures but the 3D objects aren't.
This is my initialization code:
private static void initializeOpenGL() {
//Enabling OpenGL functions
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
//Using them
glCullFace(GL_BACK);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
And this is my code to switch from 2D to 3D and vice versa. I am confident it is being run at the correct time.
public static void switchTo2D() {
if (currentRenderDimension != Dimension.DIM_2) {
glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, Display.getWidth(), Display.getHeight(), 0);
glViewport(0, 0, Display.getWidth(), Display.getHeight());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
currentRenderDimension = Dimension.DIM_2;
}
}
public static void switchTo3D() {
if (currentRenderDimension != Dimension.DIM_3) {
glPopMatrix(); //From 2D
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(PreferenceHelper.getInteger("fieldOfView"), (float) Display.getWidth() / Display.getHeight(), 0.1f, 1000);
glViewport(0, 0, Display.getWidth(), Display.getHeight());
glMatrixMode(GL_MODELVIEW);
currentRenderDimension = Dimension.DIM_3;
}
}
I believe it should correctly switch the settings, but clearly it does not:
I have verified that the .png textures ARE transparent.