2013-05-10 51 views
3

我跟着OpenGL的教程發現here問題提供的頂部答案this問題,但我的立方體拒絕呈現正面和背面,所有其他面呈現,同樣的問題金字塔。這裏是源代碼:lwjgl中的我的多維數據集不能正確呈現

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(); 
} 
+0

我們能有一個屏幕截圖。就這樣我知道它不是深度剔除。你能看到立方體的邊緣,你期望看到另一面嗎?如果你旋轉它會發生什麼? (加入角度旋轉呼叫) – Andrew 2013-05-10 02:52:53

回答

2

在我看來像它的深度問題。立方體的前面是關閉的視錐的正面和背面是越來越剪切掉。

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

注意1(最後一個參數),過去的任何東西都會被剪掉。

你們看到的實際上是你的立方體這實在是伸出的部分。

+0

謝謝!我只需將Znear和Zfar設置爲100,並且我的顯示器可以完美地處理旋轉的3D立方體!謝謝! – getynge 2013-05-10 03:05:55