Press on the image to return to the main documentation page.
OpenGL2
Written by Andrew Graham
Android includes support for high performance 3D graphics via the OpenGL ES API. OpenGL ES is a flavor of the OpenGL specification intended for embedded devices. Versions of OpenGL ES are loosely peered to versions of the primary OpenGL standard. Android currently supports OpenGL ES 2.0, which corresponds to OpenGL 1.5. If the application you have in mind is possible with OpenGL 1.5 on a desktop system, it should be possible on Android.
This library also contains a Matrix2 object that operates on 4x4 OpenGL matrices and a Visibility2 object that imlpements a collection of utility methods for computing the visibility of triangle meshes.
This object does all the drawing work and is an exposure of the Android GLES20 object.
The GL2 function and parameter names mirror those of the GLES20 object which should be present on Android versions 2.2 and later (API level 8 or later).
Some variations of functions that use native buffers instead of arrays are omitted, generally where there is an array equivalent. Where there is not an equivalent using an array has been synthesised. This is an 'Activity Object', it cannot be declared under Sub Process_Globals.
An implementation of SurfaceView that uses the dedicated surface for displaying OpenGL rendering. A GLSurfaceView provides the following features:
Manages a surface, which is a special piece of memory that can be composited into the Android view system. Manages an EGL display, which enables OpenGL to render into a surface. Renders on a dedicated thread to decouple rendering performance from the UI thread. Supports both on-demand and continuous rendering.
At present a reasonable set of drawing defaults are used to set up the GLSurfaceView. More control may be available in a future release of this library glFrustrumf must be called in the SurfaceChanged event to define a frustrum otherwise the GLSurfaceView is ready to be drawn on.
Presently there is an unwanted field "ba" visible to Basic4android. Ignore this field. This field appears due to a feature (bug?) in the Basic4android documentation doclet.
This view raises the following three events all of which run on a separate rendering thread and NOT on the main thread of the application. Because of this cosw running in these events must no attempt to manipulate GUI elements. The RunOnGuiThread method can be used to invoke a Sub to tun on the main thread and QueueEvent used to invoke a Sub to run on the rendering thread.
SurfaceCreated Called when the surface is created or recreated. Called when the rendering thread starts and whenever the EGL context is lost. The EGL context will typically be lost when the Android device awakes after going to sleep. Since this method is called at the beginning of rendering, as well as every time the EGL context is lost, this method is a convenient place to put code to create resources that need to be created when the rendering starts, and that need to be recreated when the EGL context is lost. Textures are an example of a resource that you might want to create here. Note that when the EGL context is lost, all OpenGL resources associated with that context will be automatically deleted. You do not need to call the corresponding "glDelete" methods such as glDeleteTextures to manually delete these lost resources.
SurfaceChanged Called when the surface has changed size. Called after the surface is created and whenever the OpenGL ES surface size changes. Typically you will set your viewport here. If your camera is fixed then you could also set your projection matrix here
Draw Called to draw the current frame. This is an 'Activity Object', it cannot be declared under Sub Process_Globals.
Events:
Click LongClick Draw(gl As GL1) 'The view wants to be drawn using the supplied GL10 SurfaceChanged(gl As GL1, width As Int, height As Int) 'Called when the surface has changed size. SurfaceCreated(gl As GL1) 'Called when the surface is created or recreated.