为什么我的代码OpenGL android没有绘制三角形,我不知道为什么永远渲染黑屏的问题在哪里,有人可以帮我解决这个问题吗?
public class OpenGL implements GLSurfaceView.Renderer {
int width,height;
float blue = 0.f;
@Override
public void onDrawFrame(GL10 gl){
gl.glClearColor(.0f,.0f,blue,0.f);
gl.glClear(gl.GL_COLOR_BUFFER_BIT);
float Vertex[] = {
0.f, 1.f,
1.f, -1.f,
-1.f, -1.f,
};
ByteBuffer buffer;
FloatBuffer _float;
buffer = ByteBuffer.allocateDirect( Vertex.length * 4 );
buffer.order( ByteOrder.nativeOrder() );
_float = buffer.asFloatBuffer();
_float.put( Vertex );
_float.position(0);
gl.glColor4f(1.f,1.f,0.f,1.f);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _float);
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, Vertex.length / 3);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) {
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height){
this.width = width;
this.height = height;
gl.glViewport(0,0,width,height);
gl.glMatrixMode(gl.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0,width,0,height,0,1);
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity();
}
}