First, OpenGL overview:
In the OpenGL library, there are five classes: Cube, Cuberenderer, Opengldemo, Openglscreen, and renderer. which
1.1 renderer is a defined interface;
1.2 Cuberenderer is the concrete implementation of renderer interface;
1.3 Opengldemo is the entrance to the program;
1.4 Openglscreen is the screen displayed after the program enters;
1.5 cube is the definition of 3D model;
1.6 In addition, Cuberenderer is responsible for obtaining data from the cube and then converting and displaying the data.
1.7 When the BlackBerry uses the vertex array method to draw, the coordinate origin is in the middle.
Second, OpenGL initialization:
The initialization process for the Opengldemo application is as follows:
2.1 The Opengldemo application takes the Opengldemo class as a portal and creates a new Opengldemo instance in the static main method of the class.
2.2 in the constructor of Opengldemo first determine whether the current device supports OpenGL, if OpenGL is not supported the popup dialog prompts the user and exits the application, if OpenGL is supported to continue the initialization process.
2.3 Creates an Openglscreen instance in case the device supports OpenGL.
2.4 Creates a Cuberender instance during the creation of the Openglscreen instance.
2.5 Displays the Openglscreen instance created in step 3rd.
2.6 invokes the Opengldemo's Entereventdispatcher () method for the event loop.
The 2.7 section code is as follows:
Detect if OpenGL is supported
if (Glutils.issupported ()) {
If OpenGL is supported, create a new Openglscreen instance and display the instance
Openglscreenscreen = newopenglscreen (newcuberenderer ());
Pushscreen (screen);
}
2.8, Eglboolean Eglbindapi (Eglenum API);
API: Specifiesthe client API to bind, one of Egl_opengl_api, Egl_opengl_es_api, Oregl_openvg_api.
If API is EGL_OPENGL_API, the Currentrendering API was set to the OPENGL API.
If API is EGL_OPENGL_ES_API, the Currentrendering API was set to the OPENGL ES API.
If API is EGL_OPENVG_API, the Currentrendering API was set to the OPENVG API.
If An error occurs, the current renderingapi is unchanged.
Some functions of OpenGL and its function (the functions of this column are arranged in the order used in the program)
3.1 Clear Screen function
Prototype: void glclear (intmask);
Clear screen function, parameters for clear screen mode, there are Aregl_color_buffer_bit, Gl_depth_buffer_bit, gl_accum_buffer_bit, andgl_stencil_buffer_bit four kinds.
3.2 setting of the matrix transformation and setting of the current matrix (not understood temporarily):
Gl.glmatrixmode (Gl10.gl_modelview);
Gl.glloadidentity ();
3.3 Functions of the transformation coordinate system:
Gltranslatef (x, y, z);
Move along the X, Y, and Z axes.
3.3.1 The x-axis is from left to right, y-axis from bottom to top, and z-axis from inside to outside.
The coordinate values for the center of the 3.3.2 OpenGL screen are the 0.0f points on the x and Y axes.
The coordinate value at the left of the 3.3.2 Center is negative and the right side is positive.
3.3.4 Note:
Moving to the top of the screen is positive, and moving to the bottom of the screen is negative.
Moving to the bottom of the screen is negative, and moving out of the screen is positive.
Move along the X, Y, and Z axes.
Attention:
In Gltranslatef (x, Y, z), when you move, you are not moving relative to the center of the screen, but relative to the current screen position. The effect is to translate one (x, y, z) vector on the base of the current origin, based on the origin of the coordinates you plot.
3.4 Rotation function:
Gl.glrotatef (_angle,1.0f, 1.0f, 0.0f);
3.4.1 The first parameter is the angle of rotation (degrees);
3.4.2 Other parameters are the center of rotation;
3.5 Open OpenGL array drawing function
Gl.glenableclientstate (Gl10.gl_vertex_array);
Gl.glenableclientstate (Gl10.gl_normal_array);
Gl.glenableclientstate (Gl10.gl_texture_coord_array);
The first sentence is used to start the vertex array support, the second sentence is used to start the support of the normal vector array, the third sentence is used to start the texture array support
3.6 Window Transform function
Glviewport;
The function has four parameters,
3.6.1 The first argument and the second parameter specify where the lower-left corner of the picture appears;
3.6.2 The third and fourth parameters are used to specify the width and height of the generated picture.
3.7 Drawing vertex functions
Glvertexpointer;
3. 7. 1 with four parameters;
3. 7. 2 The first parameter is size, which specifies that a vertex is composed of several coordinate values, which must be 2, 3, or 4
3. 8 Drawing functions
Voidgldrawarrays (int mode, int first, int count);
Parameter: Mode: Specify an original drawing method, Optional: Gl_points, Gl_line_strip, Gl_line_loop, Gl_lines, Gl_triangle_strip, Gl_triangle_fan, Gl_ Triangles, Gl_quad_strip, gl_quads, and Gl_polygon;
First: Starting from the first few (array) elements;
Count:specifies the number of indices to be rendered. (tested, should be the number of vertices)
Example: Gl.gldrawarrays (Gl10.gl_triangles, 0,_vertexcount);
parameter mode:
3.8.1. Gl_triangles: Draws a triangle between every three tops, not connected
3.8.2.gl_triangle_fan: With V0v1v2,v0v2v3,v0v3v4, ... The form of the triangle is drawn
3.8.3. Gl_triangle_strip Connect and render.
3.8.4. Gl_points just draws points, does not connect, does not render.
3.8.5. Gl_line_strip, in the order of points, with the line once connected, but not closed.
3.8.6. gl_line_loop: Closed line
3.9 ... (In a program, this function should precede the 3.7 function)
void Glvertexattribpointer (Gluint index, glint size, glenum type, Glboolean normalized, Glsizei stride, const glvoid * pointer);
Voidglvertexattribipointer (gluint index, glint size, glenum type, glsizeistride, const glvoid * pointer);
Voidglvertexattriblpointer (gluint index, glint size, glenum type, glsizeistride, const glvoid * pointer);
void Glvertexpointer (glint size, glenum type, Glsizei stride, constglvoid * pointer);
1. Parameters:
3.9.1.1 Index
Specifies the index value of the vertex property to modify
3.9.1.2size
Specifies the number of components for each vertex property. Must be 1, 2, 3, or 4. The initial value is 4. (Dream Dimension: If position is made up of 3 (x, Y, z), and the color is 4 (r,g,b,a))
3.9.1.3 Type
Specifies the data type of each component in the array. The available symbolic constants are Gl_byte, Gl_unsigned_byte, Gl_short,gl_unsigned_short, gl_fixed, and Gl_float, with an initial value of gl_float.
3.9.1.4 normalized
Specifies whether the fixed point data value should be normalized (gl_true) or converted directly to a fixed point value (gl_false) when accessed. If normalized is set to gl_true, it means that the value of the integer type is mapped to the interval [ -1,1] (signed integer), or the interval [0,1] (unsigned integer), and conversely, the values are converted directly to floating point values without normalization.
3.9.1.5stride
Specifies the offset between successive vertex attributes. If 0, the vertex properties are understood as: they are tightly aligned. The initial value is 0. Specifies the step size between one property and the next.
3.9.1.6pointer
Specifies a pointer to the first component of the first vertex property in the array. The initial value is 0.
2. Error :
3.9.2.1 gl_invalid_enum Error: If type is not an acceptable value.
3.9.2.2 gl_invalid_value Error: If index is greater than or equal to gl_max_vertex_attribs.
3.9.2.3 Gl_invalid_value Error: If size is not 1, 2, 3, or 4.
3.9.2.4 Gl_invalid_value Error: If stride is less than 0.
Iv. BlackBerry GL Program creation:
4.1 to create an EGL program, you first have to set up a context and a window. As follows:
Create a new context
Screen_context_tscreen_ctx;
Screen_create_context (&screen_ctx,0);
Create a new window
Screen_window_tscreen_win;
Screen_create_window (&SCREEN_WIN,SCREEN_CTX);
After 4.2 , initialize EGL with the following code:
Create an EGL instance
Egldisplayegl_disp;
Egl_disp =eglgetdisplay (Egl_default_display);
Eglinitialize (Egl_disp,null, NULL);