1
我有一個JOGL opengl問題,我試圖使用頂點數組,但是每當我使用glArrayElement(注意:glDrawElements也不起作用),它會給出0點,0,0。重要的代碼。我假設一個窗口被初始化並且指定了一個重塑函數。JOGL glArrayElement點提供0,0,0
...
public void display(GLDrawable glDrawable) {
final GL gl = glDrawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -6);
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glArrayElement(4);
/*gl.glArrayElement(5); // These are what I'm trying to use, but they seem to return the point 0,0,0.
gl.glArrayElement(6);
gl.glArrayElement(5);
gl.glArrayElement(6);
gl.glArrayElement(7);*/
//gl.glVertex3f(1, 1, -1); // Replaced with uncommented glArrayElement above.
gl.glColor3f(0.0f, 1.0f, 0.0f);
gl.glVertex3f(-1, 1, -1);
gl.glVertex3f(1, -1, -1);
gl.glColor3f(0.0f, 0.0f, 1.0f);
gl.glVertex3f(-1, 1, -1);
gl.glVertex3f(1, -1, -1);
gl.glVertex3f(-1, -1, -1);
gl.glEnd();
}
...
protected final static float[] mesh = {1,1,1, -1,1,1, 1,-1,1, -1,-1,1,
1,1,-1, -1,1,-1, 1,-1,-1, -1,-1,-1};
protected static ByteBuffer stdMesh;
...
public void init(GLDrawable glDrawable) {
final GL gl = glDrawable.getGL();
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
stdMesh = ByteBuffer.allocateDirect(mesh.length * 4);
stdMesh.asFloatBuffer().put(mesh);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, stdMesh);
}
...
是否還有其他初始化函數/繪圖函數我還需要調用,還是另一個問題? 任何幫助表示讚賞。