So, I have been working on a game, And it was going great until I needed to add a 2D HUD/overly/GUI. As of now, I can fully render the 3D scene perfectly, and the 2D scene perfectly, but not at the same time. Here are the important parts of my source. I'm wondering what I'm doing wrong, why it's wrong, and what I should do to fix it.
Main class:
public void start() {
map = new NoiseMapGenerator().generateMap(1280 / 16, 720 / 16, System.nanoTime(), null);
mapRenderer = new DeafultMapRenderer();
resizeScreen(1280, 720);
mapRenderer.setMap(map);
guiRenderer = new DeafultGUIRenderer();
guiRenderer.initilizeRenderer(1280, 720);
while (!Display.isCloseRequested()) {
mapRenderer.ready();
mapRenderer.render();// Works fine, cannot be source of the problem
guiRenderer.ready();
guiRenderer.render();// Works fine, cannot be source of the problem
pollInput(); //Works fine, cannot be the source of the problem
updateDelta();
Display.update();
}
mapRenderer.destructRenderer();
guiRenderer.destructRenderer();
Display.destroy();
}
public void resizeScreen(int width, int height) {
try {
Display.destroy();
Display.setTitle("Neutrality");
Display.setFullscreen(fullscreen);
Display.setDisplayModeAndFullscreen(new DisplayMode(width, height));
Display.create();
mapRenderer.initilizeRenderer(map, width, height);
} catch (LWJGLException e) {
ErrorHandler.handleError(e, "Failed to initlize the screen.", true);
}
}
Default Map Renderer:
public void ready() {
glMatrixMode(GL_PROJECTION);
glPushMatrix();
gluPerspective(80f, (float) width / height, .1f, 1000f);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glRotatef(-30, 1.0f, 0.0f, 0.0f);
glTranslatef(-(width / 32), 0, -10);
}
public void initilizeRenderer(Map map, int width, int height) {
glMatrixMode(GL11.GL_PROJECTION);
glLoadIdentity();
gluPerspective(80f, (float) width / height, .1f, 1000f);
glMatrixMode(GL11.GL_MODELVIEW);
//glPolygonMode(GL_BACK, GL_LINE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
setUpLighting();
loadTexture("resources/grass.png", "grassTexture", GL_LINEAR, GL_LINEAR);
loadTexture("resources/water.png", "waterTexture", GL_LINEAR, GL_LINEAR);
loadTexture("resources/beach.png", "beachTexture", GL_NEAREST, GL_NEAREST);
loadTexture("resources/snow.png", "snowTexture", GL_NEAREST, GL_LINEAR);
loadTexture("resources/underwater.png", "underwaterTexture", GL_NEAREST, GL_LINEAR);
loadTexture("resources/gravel.png", "gravelTexture", GL_NEAREST, GL_NEAREST);
loadTexture("resources/error.png", "errorTexture", GL_NEAREST, GL_LINEAR);
tree = new Model("resources/tree10.obj");
city = new Model("resources/city.obj");
glRotatef(-30, 1.0f, 0.0f, 0.0f);
glTranslatef(-(width / 32), 0, -10);
}
DeafultGUIRenderer:
public void initilizeRenderer(int width, int height) {
}
public void ready() {
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glLoadIdentity();
glOrtho(0, 1280, 720, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glLoadIdentity();
}
public void destructRenderer() {
}
public void render() {
glDisable(GL_LIGHTING);
glColor3f(1f, .5f, 1f);
// draw quad
glBegin(GL_QUADS);
glVertex2f(100, 100);
glVertex2f(100 + 200, 100);
glVertex2f(100 + 200, 100 + 200);
glVertex2f(100, 100 + 200);
glVertex2f(0, 0);
glVertex2f(1, 0);
glVertex2f(1, 1);
glVertex2f(0, 1);
glEnd();
glEnable(GL_LIGHTING);
}
Thanks for any help, I know this might be a basic question, but I'm just starting out with working with 3D from scratch, and I'm only beginning to understand some parts of OpenGL.