1

JOGL opengl の問題があり、頂点配列を使用しようとしていますが、glArrayElement を使用するたびに (注: glDrawElements も機能しません)、ポイントが 0,0,0 になります。重要なコード。ウィンドウが初期化され、reshape 関数が指定されていると仮定しています。

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

他にも呼び出す必要がある初期化関数/描画関数はありますか、それとも別の問題ですか? どんな助けでも大歓迎です。

4

1 に答える 1

0

バッファに配列値を適切に入力する必要があります。あなたがやっている方法は新しい FloatBuffer を返しますが、結果を保存する代わりに破棄しています。

それ以外の

...
protected static ByteBuffer stdMesh;
...
 stdMesh = ByteBuffer.allocateDirect(mesh.length * 4);
 stdMesh.asFloatBuffer().put(mesh);
...

行う

...
protected static FloatBuffer stdMesh;
...
stdMesh = BufferUtil.newFloatBuffer(mesh.length * 3);
for (int i = 0; i < mesh.length; i++){
    stdMesh.put(mesh[i]);
}
stdMesh.flip();
...

flip()バッファーを使用する前に必ず呼び出してください。

于 2011-01-24T08:13:20.857 に答える