3

I followed the tutorial for OpenGL found here as provided by the top answer to this question but my cube refuses to render the front and back faces, all other faces render, same problem with a pyramid. Here is the source code:

public void render(){
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight(), -1, 1);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); //clear screen

    //Center square according to screen size
    GL11.glPushMatrix();
    if(Display.wasResized()){
        MX = 0; //MX is mouse X position
        MY = 0; //MY is mouse Y position
    }
    if((MX == 0 && MY ==0)){
        GL11.glTranslatef((Display.getWidth()/2), (Display.getHeight()/2), 0.0f);
    }else{
        GL11.glTranslatef(MX+50, MY+50, 0.0f);
    }
    GL11.glRotatef(angle, 0.0f,1.0f,0.5f); //Angle is the angle of the quads rotation
    GL11.glBegin(GL11.GL_QUADS);

    GL11.glColor3f(0.0f,1.0f,0.0f);
    GL11.glVertex3f(50.0f, 50f, -50f);
    GL11.glVertex3f(-50.0f, 50f, -50f);
    GL11.glVertex3f(-50.0f, 50f, 50f);
    GL11.glVertex3f(50.0f, 50f, 50f);

    GL11.glColor3f(0.0f,0.5f,0.0f);
    GL11.glVertex3f(50.0f, -50f, 50f);
    GL11.glVertex3f(-50.0f, -50f, 50f);
    GL11.glVertex3f(-50.0f, -50f, -50f);
    GL11.glVertex3f(50.0f, -50f, -50f);

    GL11.glColor3f(1.0f,0.0f,0.0f);
    GL11.glVertex3f(50.0f, 50f, 50f);
    GL11.glVertex3f(-50.0f, 50f, 50f);
    GL11.glVertex3f(-50.0f, -50f, 50f);
    GL11.glVertex3f(50.0f, -50f, 50f);

    GL11.glColor3f(1.0f,1.0f,0.0f);
    GL11.glVertex3f(50.0f, -50f, -50f);
    GL11.glVertex3f(-50.0f, -50f, -50f);
    GL11.glVertex3f(-50.0f, 50f, -50f);
    GL11.glVertex3f(50.0f, 50f, -50f);

    GL11.glColor3f(0.0f,0.0f,1.0f);
    GL11.glVertex3f(-50.0f, 50f, 50f);
    GL11.glVertex3f(-50.0f, 50f, -50f);
    GL11.glVertex3f(-50.0f, -50f, -50f);
    GL11.glVertex3f(-50.0f, -50f, 50f);

    GL11.glColor3f(1.0f,0.0f,1.0f);
    GL11.glVertex3f(50.0f, 50f, -50f);
    GL11.glVertex3f(50.0f, 50f, 50f);
    GL11.glVertex3f(50.0f, -50f, 50f);
    GL11.glVertex3f(50.0f, -50f, -50f);

    GL11.glEnd();
    GL11.glPopMatrix();
}
Community
  • 1
  • 1
getynge
  • 135
  • 1
  • 7
  • Can we have a screen shot. Just so I know its not depth culling. Can you see the edges of the cube where you expect to see the other face? What happens if you spin it? (adding to angle the rotate call) – Andrew May 10 '13 at 02:52

1 Answers1

2

Looks to me like its a depth issue. The front of the cube is off the front of the frustum and the back is getting clipped out.

GL11.glOrtho(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight(), -1, 1);

Notice the 1 (last param), Anything past that will be clipped out.

What you are seeing in effect is a section of your cube which is really stretched out.

Andrew
  • 1,764
  • 3
  • 24
  • 38
  • Thanks! I just had to set Znear and Zfar to 100 and my display handled a rotating 3d cube perfectly fine! Thanks! – getynge May 10 '13 at 03:05