/**
* Entry, triangle
*/
// Custom Renderer
Class myrenderer implements Android. OpenGL. glsurfaceview. Renderer {
Private float ratio;
// When the surface layer is created
Public void onsurfacecreated (gl10 GL, eglconfig config ){
// Set the screen color
Gl. glclearcolor (0, 0, 0, 1 );
// Enable the vertex buffer.
Gl. glableclientstate (gl10.gl _ vertex_array );
}
// When the surface size is
Public void onsurfacechanged (gl10 GL, int width, int height ){
// Set the view and output area.
Gl. glviewport (0, 0, width, height );
Ratio = (float) width/(float) height;
// Matrix mode, projection matrix, OpenGL Based on State Machine
Gl. glmatrixmode (gl10.gl _ projection );
// Load the Unit Matrix
Gl. glloadidentity ();
// Intercept
Gl. glfrustumf (-1f, 1f,-ratio, ratio, 3, 7 );
}
// Drawing
Public void ondrawframe (gl10 GL ){
// Clear the color cache area
Gl. glclear (gl10.gl _ color_buffer_bit );
// Model View Matrix
Gl. glmatrixmode (gl10.gl _ modelview );
Gl. glloadidentity (); // load the Unit Matrix
// Eyex, eyey, and Eyez: coordinates of the eye
// Centerx, centery, and centerz: eye observation point.
// UPX, UPX, and UPX: Specify the eye Vector
Glu. glulookat (GL, 0, 0, 5, 0, 0, 0, 0, 1, 0 );
// Draw a triangle
// Draw an array
// Triangle coordinates
Float [] coords = {
0f, ratio, 2f,
-1f,-ratio, 2f,
1f,-ratio, 2f };
// Allocate byte cache space to store vertex coordinate data
Bytebuffer Ibb = bytebuffer. allocatedirect (coords. length * 4 );
// Set the order (Local Order)
Ibb. Order (byteorder. nativeorder ());
// Place the vertex coordinate Array
Floatbuffer fbb = Ibb. asfloatbuffer ();
Fbb. Put (coords );
// Locate the pointer and read the vertex data from this position
Ibb. Position (0 );
// Set the drawing color in red.
Gl. glcolor4f (1f, 0f, 0f, 1f );
// 3-dimensional point, which uses three coordinate values to represent a point
// Type: Data Type of each vertex
// Stride: 0, span.
// Ibb: Specify the vertex buffer.
Gl. glvertexpointer (3, gl10.gl _ float, 0, Ibb );
// Draw a triangle
// 0: start point:
// 3: number of points to be drawn
Gl. gldrawarrays (gl10.gl _ triangles, 0, 3 );
}
}