84danie 84danie - 5 months ago 36
Java Question

Lwjgl gluPerspective displaying a black screen

I have a simple application that displays a 3D cube that rotates on all axes, and a camera controlled via mouse that allows you to adjust the angle you're looking at the cube.

The entire application works exactly as I want when I use glOrtho, but once I change it to gluPerspective I only get a black screen.

Here is my method to initialize openGL:

public void initializeOpenGL()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, ((float)WIDTH) / ((float)HEIGHT), 0.01f, 500f);
//glOrtho(0, 640, 480, 0, 600, -1); //displays everything correctly
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
}


And then here is my loop method:

public void begin()
{
float degrees = 0;
Mouse.setGrabbed(false);
while(!Display.isCloseRequested())
{
moveCamera(); //calculates the changes in mouse position
GL11.glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera.lookThrough(); //applies the changes
glTranslatef((float)WIDTH/2,(float)HEIGHT/2,10f);
glRotatef(degrees++,1f,1f,1f);
glScalef(100,100,100);

drawQuad();

Display.update();
Display.sync(60);
}
Display.destroy();
System.exit(0);
}


Please let me know if I must provide more information or code!

Answer Source

I created an image displaying where the camera looks: http://i.imgur.com/9NVSyqj.png As you can see the camera looks along the -z axis

-> you should try translating the quad to something like:

glTranslatef(0,0, -10f );

Instead of moving the quad to the middle of the Display you move it half the size of the Display in the nowhere of your Landscape

SHORT VERSION: Gist: https://gist.github.com/Chronove/11da12b2635bfc040981