You must switch between spelling and perspective. Two functions are created for this: display_ready2d (this sets up the orthoprojection matrix) and display_ready3d (this creates a perspective projection).
Unfortunately, the display_ready3d function does not reset the matrix stack before applying it. You must add glLoadIdentity before calling gluPerspective. Also, you should not clear the framebuffer in these functions, since you want to be able to switch between matrix settings. Therefore, change this to the following:
private def display_ready3d(fov: Float, aspect: Float) { glMatrixMode(GL_PROJECTION) glLoadIdentity(); gluPerspective(fov, aspect, 0.01f, 100.0f) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glEnable(GL_DEPTH_TEST) }
display_ready2d before drawing the GUI and display_ready3d before draw_something. You should also put clear commands there, which should also cover the depth buffer; also, a clear color should have an alpha value of 1 (except that you created a transparent window).
def display(width: Int, height: Int, AR: Float, gui: Nifty) { glViewport(0, 0, width, height) glClearDepth(1.) glClearColor(0., 0., 0., 1.) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) display_ready3d(90, width/height) draw_something() display_ready2d(width, height) gui.render(false) glFlush() Display.update() }
source share