Hello Guest

LWJGL 3D cube not rendered correctly

  • 2 Replies
  • 7914 Views
LWJGL 3D cube not rendered correctly
« on: May 26, 2013, 14:58:56 »


As the title says, the cube isn't rendered correctly (you see these holes?)

Here is the code:

     
Code: [Select]
GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(-5, 5, -5, 5, -1, 5);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

float x = 0;
while (!Display.isCloseRequested())
{
Display.update();

GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT|GL11.GL_COLOR_BUFFER_BIT);
GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glColor3f(1, 0, 0);
        GL11.glRotatef(x+=0.01f, 1, 1, 1);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glColor3f(0.0f,1.0f,0.0f);          // Set The Color To Green
        GL11.glVertex3f( 1.0f, 1.0f,-1.0f);          // Top Right Of The Quad (Top)
        GL11.glVertex3f(-1.0f, 1.0f,-1.0f);          // Top Left Of The Quad (Top)
        GL11.glVertex3f(-1.0f, 1.0f, 1.0f);          // Bottom Left Of The Quad (Top)
        GL11.glVertex3f( 1.0f, 1.0f, 1.0f);          // Bottom Right Of The Quad (Top)
        GL11.glColor3f(1.0f,0.5f,0.0f);          // Set The Color To Orange
        GL11.glVertex3f( 1.0f,-1.0f, 1.0f);          // Top Right Of The Quad (Bottom)
        GL11.glVertex3f(-1.0f,-1.0f, 1.0f);          // Top Left Of The Quad (Bottom)
        GL11.glVertex3f(-1.0f,-1.0f,-1.0f);          // Bottom Left Of The Quad (Bottom)
        GL11.glVertex3f( 1.0f,-1.0f,-1.0f);          // Bottom Right Of The Quad (Bottom)
        GL11.glColor3f(1.0f,0.0f,0.0f);          // Set The Color To Red
        GL11.glVertex3f( 1.0f, 1.0f, 1.0f);          // Top Right Of The Quad (Front)
        GL11.glVertex3f(-1.0f, 1.0f, 1.0f);          // Top Left Of The Quad (Front)
        GL11.glVertex3f(-1.0f,-1.0f, 1.0f);          // Bottom Left Of The Quad (Front)
        GL11.glVertex3f( 1.0f,-1.0f, 1.0f);          // Bottom Right Of The Quad (Front)
        GL11.glColor3f(1.0f,1.0f,0.0f);          // Set The Color To Yellow
        GL11.glVertex3f( 1.0f,-1.0f,-1.0f);          // Bottom Left Of The Quad (Back)
        GL11.glVertex3f(-1.0f,-1.0f,-1.0f);          // Bottom Right Of The Quad (Back)
        GL11.glVertex3f(-1.0f, 1.0f,-1.0f);          // Top Right Of The Quad (Back)
        GL11.glVertex3f( 1.0f, 1.0f,-1.0f);          // Top Left Of The Quad (Back)
        GL11.glColor3f(0.0f,0.0f,1.0f);          // Set The Color To Blue
        GL11.glVertex3f(-1.0f, 1.0f, 1.0f);          // Top Right Of The Quad (Left)
        GL11.glVertex3f(-1.0f, 1.0f,-1.0f);          // Top Left Of The Quad (Left)
        GL11.glVertex3f(-1.0f,-1.0f,-1.0f);          // Bottom Left Of The Quad (Left)
        GL11.glVertex3f(-1.0f,-1.0f, 1.0f);          // Bottom Right Of The Quad (Left)
        GL11.glColor3f(1.0f,0.0f,1.0f);          // Set The Color To Violet
        GL11.glVertex3f( 1.0f, 1.0f,-1.0f);          // Top Right Of The Quad (Right)
        GL11.glVertex3f( 1.0f, 1.0f, 1.0f);          // Top Left Of The Quad (Right)
        GL11.glVertex3f( 1.0f,-1.0f, 1.0f);          // Bottom Left Of The Quad (Right)
        GL11.glVertex3f( 1.0f,-1.0f,-1.0f);          // Bottom Right Of The Quad (Right)
        GL11.glEnd();
        GL11.glLoadIdentity();
}

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: LWJGL 3D cube not rendered correctly
« Reply #1 on: May 26, 2013, 19:38:56 »
That is viewport clipping. Your view is too close to the cube so anything outside the viewing volume (in this case behind the camera) gets clipped. Set the near value in glOrtho to -2 or -3 instead.

Re: LWJGL 3D cube not rendered correctly
« Reply #2 on: May 27, 2013, 13:01:22 »
Ah ok thanks  ;D