Press on the image to return to the main documentation page. |

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.

GLSurfaceView2

Matrix2

Visibility2

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.

eyeX eye point X

eyeY eye point Y

eyeZ eye point Z

centerX center of view X

centerY center of view Y

centerZ center of view Z

upX up vector X

upY up vector Y

upZ up vector Z

fovy specifies the field of view angle, in degrees, in the Y direction.

aspect specifies the aspect ratio that determines the field of view in the x direction.

Aspect ratio is the ratio of x (width) to y (height).

zNear specifies the distance from the viewer to the near clipping plane (always positive).

zFar specifies the distance from the viewer to the far clipping plane (always positive).

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.

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.

The value is constructed by OR-together zero or more of the DEBUG_CHECK_* constants.

The debug flags take effect whenever a surface is created.

The default value is zero.

OpenGL2 is only supported by API level 8 (FROYO) devices or later.

which will choose a config as close to 16-bit RGB as possible, with a depth buffer as

close to 16-bits as possible.

Calls SetEGLConfigChooser(true);

which will choose a config with 8bit RGBA with the specified depth size and stencil size.

Calls SetEGLConfigChooser(8, 8, 8, 8, depthSize, stencilSize);

The owner of this view must call this method when the activity is paused.

Calling this method will pause the rendering thread.

Must not be called before a renderer has been set.

because an uncaught exception on a non-main thread will close the application.

This can be used to communicate with the Renderer on the rendering thread and

safely run non-atomic functions without any further thread synchronisation.

Using this method to update data used while rendering ensures that the data will

only be changed when rendering is not occurring,.

If an uncaught exception occurs when running the event it is saved in the

QueuedEventException property.

When renderMode is RENDERMODE_CONTINUOUSLY, the renderer is called repeatedly

to re-render the scene. When renderMode is RENDERMODE_WHEN_DIRTY, the scene

is only rendered when the surface is created, or when requestRender() is called.

Defaults to RENDERMODE_CONTINUOUSLY.

Using RENDERMODE_WHEN_DIRTY can improve battery life and overall system performance

by allowing the GPU and CPU to idle when the view does not need to be updated.

This method can only be called after setRenderer(Renderer)

This method is typically used when the render mode has been set to RENDERMODE_WHEN_DIRTY,

so that frames are only rendered on demand.

May be called from any thread.

Must not be called before a renderer has been set.

The owner of this view must call this method when the activity is resumed.

Calling this method will recreate the OpenGL display and resume the rendering thread.

Must not be called before a renderer has been set.

This mechanism is the only way a thread can access GUI items. This call returns

immediately. If it is necessary for the thread to wait for the result of the

GUI operation then it should wait on a Lock that will be reset by the called Sub

after it haas completed the GUI operation. Sometimes it seems that if the user

presses the back button, and maybe in other scenarions, then Android loses the

message and the GUI thread doesn't get it and the Sub isn't run and the Lock

isn't freed so it may be advisable in this case to use WaitFor with a reasonably

long timeout and retry until it returns True.

Returns True if the Sub was found otherwise returns False.

Matrices are 4 x 4 column-vector matrices stored in column-major order:

m[offset + 0] m[offset + 4] m[offset + 8] m[offset + 12]

m[offset + 1] m[offset + 5] m[offset + 9] m[offset + 13]

m[offset + 2] m[offset + 6] m[offset + 10] m[offset + 14]

m[offset + 3] m[offset + 7] m[offset + 11] m[offset + 15]

Vectors are 4 row x 1 column column-vectors stored in order:

v[offset + 0] v[offset + 1] v[offset + 2] v[offset + 3]

More than one matrix or vector may be in an array. The offset parameter defines the location

of the required item in the array.

Parameters

m the float array that holds the perspective matrix

offset the offset into float array m where the perspective matrix data is written

Parameters

mInv the array that holds the output inverted matrix

mInvOffset an offset into mInv where the inverted matrix is stored.

m the input array

mOffset an offset into m where the matrix is stored.

Returns

true if the matrix could be inverted, false if it could not.

In matrix notation: result = lhs x rhs. Due to the way matrix multiplication works,

the result matrix will have the same effect as first multiplying by the rhs matrix,

then multiplying by the lhs matrix. This is the opposite of what you might expect.

The same float array may be passed for result, lhs, and/or rhs.

However, the result element values are undefined if the result elements overlap either

the lhs or rhs elements.

Parameters

result The float array that holds the result.

resultOffset The offset into the result array where the result is stored.

lhs The float array that holds the left-hand-side matrix.

lhsOffset The offset into the lhs array where the lhs is stored.

rhs The float array that holds the right-hand-side matrix.

rhsOffset The offset into the rhs array where the rhs is stored.

In matrix notation: result = lhs x rhs The same float array may be passed for resultVec, lhsMat,

and/or rhsVec. However, the resultVec element values are undefined if the resultVec elements

overlap either the lhsMat or rhsVec elements.

Parameters

resultVec The float array that holds the result vector.

resultVecOffset The offset into the result array where the result vector is stored.

lhsMat The float array that holds the left-hand-side matrix.

lhsMatOffset The offset into the lhs array where the lhs is stored.

rhsVec The float array that holds the right-hand-side vector.

rhsVecOffset The offset into the rhs vector where the rhs vector is stored.

Parameters

m source matrix.

mOffset index into m where the matrix starts.

a angle to rotate in degrees.

x scale factor x.

y scale factor y.

z scale factor z.

Parameters

rm returns the result.

rmOffset index into rm where the result matrix starts.

m source matrix.

mOffset index into m where the source matrix starts.

a angle to rotate in degrees.

x scale factor x.

y scale factor y.

z scale factor z.

Parameters

rm returns the result.

rmOffset index into rm where the result matrix starts.

m source matrix.

mOffset index into m where the source matrix starts.

a angle to rotate in degrees.

x scale factor x.

y scale factor y.

z scale factor z.

Parameters

m matrix to scale.

mOffset index into m where the matrix starts.

x scale factor x.

y scale factor y.

z scale factor z.

Parameters

sm returns the result.

smOffset index into sm where the result matrix starts.

m source matrix.

mOffset index into m where the source matrix starts.

x scale factor x.

y scale factor y.

z scale factor z.

Parameters

m returns the result.

mOffset index into m where the result matrix starts.

Parameters

rm returns the result.

rmOffset index into rm where the result matrix starts.

x angle of rotation, in degrees.

y angle of rotation, in degrees.

z angle of rotation, in degrees.

Parameters

rm returns the result.

rmOffset index into rm where the result matrix starts.

x scale factor x.

y scale factor y.

z scale factor z.

Parameters

m matrix.

mOffset index into m where the matrix starts.

x translation factor x.

y translation factor y.

z translation factor z.

Parameters

tm returns the result.

tmOffset index into sm where the result matrix starts.

m source matrix.

mOffset index into m where the source matrix starts.

x translation factor x.

y translation factor y.

z translation factor z.

Parameters

mTrans the array that holds the output inverted matrix.

mTransOffset an offset into mInv where the inverted matrix is stored.

m the input array.

mOffset an offset into m where the matrix is stored.

It is approximately the minimal bounding sphere of an axis-aligned box that bounds the points.

Parameters

positions positions in x, y, z triples

positionsOffset offset into positions array

positionsCount number of position triples to process

sphere array containing the output as (x, y, z, r)

sphereOffset offset where the sphere data will be written

and a list of spheres, determine which spheres intersect the frustum.

A ModelView-Projection matrix can be computed by multiplying a Projection matrix by

a ModelView matrix (in that order.). There are several possible ways to obtain the current

ModelView and Projection matrices. The most generally applicable way is to keep track of the

current matrices in application code. If that is not convenient, there are two optional

OpenGL ES extensions which may be used to read the current matrices from OpenGL ES:

GL10 - Ext.glQueryMatrixxOES

GL11 - GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES and

GL11 - GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES

The problem with reading back the matrices is that your application will only work with devices

that support the extension(s) that it uses.

A frustum is a six-sided truncated pyramid that defines the portion of world space that is visible in the view.

Spheres are described as four floating point values: x, y, z, and r, in world-space coordinates.

R is the radius of the sphere.

Parameters

mvp a float array containing the mode-view-projection matrix

mvpOffset The offset of the mvp data within the mvp array.

spheres a float array containing the sphere data.

spheresOffset an offset into the sphere array where the sphere data starts

spheresCount the number of spheres to cull.

results an integer array containing the indices of the spheres that are either contained entirely within or intersect the frustum.

resultsOffset an offset into the results array where the results start.

resultsCapacity the number of array elements available for storing results.

Returns

the number of spheres that intersected the frustum. Can be larger than resultsCapacity,

in which case only the first resultsCapacity results are written into the results array.

The mesh is specified as an indexed triangle list.

Parameters

ws the world space to screen space transform matrix, as an OpenGL column matrix.

wsOffset an index into the ws array where the data starts.

positions the vertex positions (x, y, z).

positionsOffset the index in the positions array where the data starts.

indices the indices of the triangle list. The indices are expressed as chars because they are unsigned 16-bit values.

indicesOffset the index in the indices array where the index data starts.

indexCount the number of indices in use. Typically a multiple of three. If not a multiple of three, the remaining one or two indices will be ignored.

Returns

2 if all of the mesh is visible, 1 if some part of the mesh is visible, 0 if no part is visible.

Top