0

当我使用 glDrawArrays 时,我在显示一个盒子的顶点时遇到问题,一个一个渲染顶点可以正常工作,请帮忙。

public class Box {
public void draw (GL2 gl, float x, float y, float z, float side) 
{
    FloatBuffer points;
    float[] pointsData = { 
            -side, side, -side, //A0
            side, side, -side, //A1
            side, side, side, //A2
            -side, side, side, //A3
            -side, -side, -side, //B0
            side, -side, -side, //B1
            side, -side, side, //B2
            -side, -side, side, //B3
        };

    //FloatBuffer colors;
    //float[] colorsData;

    int pointsDataLength = pointsData.length;

    points = FloatBuffer.allocate(pointsDataLength);
    points.put( pointsData, 0, pointsDataLength );
    points.rewind();

    gl.glTranslatef(x, y, z);
    /*
    gl.glBegin( GL.GL_POINTS ); 
    for( int i=0; i < pointsDataLength/3; i++ ) 
    {
        gl.glVertex3fv( pointsData, i*3 );
    }      
    gl.glEnd();
    */
    gl.glVertexPointer( 3, GL.GL_FLOAT, 0, points );
    //gl.glColor3f( 1f, 0f, 0f ); 
    gl.glDrawArrays( GL.GL_POINTS, 0, pointsDataLength/3 );
}
4

1 回答 1

1

必须在渲染之前添加它

gl.glEnableClientState( GL2.GL_VERTEX_ARRAY );
于 2012-08-15T17:20:21.700 回答