Practice2- 使用OpenGL ES画点
public void onSurfaceCreated( GL10 gl, EGLConfig config ){
gl.glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );//
gl.glShadeModel( GL10.GL_FLAT );//
gl.glHint( GL10.GL_POINT_SMOOTH_HINT, GL10.GL_FASTEST );//
gl.glEnableClientState( GL10.GL_VERTEX_ARRAY );//set for array as vertex
gl.glEnableClientState( GL10.GL_COLOR_ARRAY );//set for array as color
gl.glDisable( GL10.GL_TEXTURE_2D );//no 2D texture binded, so we disable it for fast speed
}
//override method
public void onDrawFrame( GL10 gl ){
gl.glClear( GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT );
int x = 0;
int y = 0;
int i = 0,j=0;
int vertex[] = new int[pointNum * 2];
int color[] = new int[pointNum * 4];
//set each dot's position
for( i=0 ; i<pointNum ; i++ ){
if( dispWidth != 0 ){
x = rand.nextInt( dispWidth );
}
if( dispHeight != 0 ){
y = rand.nextInt( dispHeight );
}
vertex[i*2] = x * 0x10000;
vertex[i*2+1] = y * 0x10000;
for( j=0 ; j<4 ; j++ ){
color[i*4 + j] = one;
}
}
drawPoint( gl, vertex, color, 10 );
try{
Thread.sleep( 17 );
} catch ( InterruptedException e ){
}
//System.gc();uncomment this will slow down performance
}
private void drawPoint( GL10 gl, int[] vertex, int[] color, int size ){
gl.glPointSize( size );
gl.glVertexPointer( 2, GL10.GL_FIXED, 0, getIntBuffer( vertex ) );
gl.glColorPointer( 4, GL10.GL_FIXED, 0, getIntBuffer( color ) );
gl.glDrawArrays( GL10.GL_POINTS, 0, pointNum );
}