在Java中使用glDrawArrays时出现致命错误

时间:2012-08-15 17:18:16

标签: java opengl jogl

当我使用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 );
}

1 个答案:

答案 0 :(得分:1)

在渲染

之前必须添加它
gl.glEnableClientState( GL2.GL_VERTEX_ARRAY );