I have this code: https://github.com/magicgoose/lwjgl-nifty-test-project
When I render only GUI, it works like expected. When I try to render triangle (in perspective projection) and then render GUI, everything fails, and even GUI don't render correctly - i get only letters on black background. (it happens if I uncomment
draw_something()
statement in display(...)
method)
private def draw_something() {
glTranslatef(0, 0, -20)
glBegin(GL_TRIANGLES)
glVertex3f(0.0f, 1.0f, 0.0f)
glVertex3f(-1.0f, -1.0f, 0.0f)
glVertex3f(1.0f, -1.0f, 0.0f)
glEnd()
}
What I am doing wrong? I tried searching for working examples with nifty-gui AND 3d graphics on background, but no luck.
Update 1
I've changed the code based on datenwolf's answer, now GUI is rendered OK, but I can see white triangle only for a couple of milliseconds (maybe actually it is in a single frame?), seems like 3d setup is being "damaged"... This happens only if I render GUI, if I comment the line gui.render(false)
, white triangle stays on the screen.
Update 2
I added some motion to the 3d part (see updates in repository), now I can see that the triangle is barely visible (it looks like z-fighting).