我在lwjgl中的多维数据集无法正确呈现

时间:2013-05-10 01:53:34

标签: java opengl lwjgl

我按照here问题的最佳答案提供的OpenGL发现this教程,但我的立方体拒绝渲染正面和背面,所有其他面渲染,金字塔问题相同。这是源代码:

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

1 个答案:

答案 0 :(得分:2)

在我看来,这是一个深度问题。立方体的正面偏离了平截头体的前部,背部被剪掉了。

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

注意1(最后一个参数),过去的任何内容都将被剪掉。

你所看到的实际上是你的立方体的一部分,它真正伸展开来。