|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.microedition.lcdui.Displayable
javax.microedition.lcdui.Canvas
javax.microedition.lcdui.game.GameCanvas
m3gac.OpenGLSample
public class OpenGLSample
Demonstrates 3D rendering using the Java Binding for the OpenGL ES API (JSR 239). This sample uses OpenGL ES 1.0 features with fixed-point variants of functions. To run this sample, the device must support a texture size of 256x256 pixels.
| Field Summary | |
|---|---|
private int |
angle
The cube's current rotation angle. |
private javax.microedition.khronos.egl.EGL10 |
egl
Object for executing EGL operations. |
private javax.microedition.khronos.egl.EGLContext |
eglContext
EGL context used for rendering. |
private javax.microedition.khronos.egl.EGLDisplay |
eglDisplay
EGL Display used for rendering. |
private javax.microedition.khronos.egl.EGLSurface |
eglWindowSurface
EGL surface used for rendering. |
private static byte[] |
FACE_NORMALS
Face normals. |
private javax.microedition.khronos.opengles.GL10 |
gl
Object for executing OpenGL operations. |
private javax.microedition.lcdui.Graphics |
graphics
2D graphics context for rendering. |
private boolean |
isRunning
Flag whether thread is running. |
private static byte[] |
STRIPS
Triangle strip information. |
private static byte[] |
VERTEX_POSITIONS
Vertex positions. |
private static byte[] |
VERTEX_TEX_COORDS
Vertex texture coordinates (origin at the lower left corner). |
| Fields inherited from class javax.microedition.lcdui.game.GameCanvas |
|---|
DOWN_PRESSED, FIRE_PRESSED, GAME_A_PRESSED, GAME_B_PRESSED, GAME_C_PRESSED, GAME_D_PRESSED, LEFT_PRESSED, RIGHT_PRESSED, UP_PRESSED |
| Fields inherited from class javax.microedition.lcdui.Canvas |
|---|
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP |
| Constructor Summary | |
|---|---|
OpenGLSample()
Constructor. |
|
| Method Summary | |
|---|---|
void |
destroy()
Stops the animation. |
void |
init()
Starts the animation. |
private void |
initCamera(float fovy,
float aspectRatio,
float near,
float far)
Initializes the camera with a perspective projection matrix. |
private void |
initCube()
Initializes the cube's vertex data. |
private void |
initGL()
Initializes the EGL, GL, and Graphics contexts. |
private void |
initLight()
Creates a directional light. |
private void |
initTexture(java.lang.String resource)
Loads an image from the given resource and uses it as texture. |
private void |
render(javax.microedition.lcdui.Graphics graphics)
Renders the sample. |
void |
run()
Animation loop. |
private static int |
toX(float value)
Converts a float to a fixed-point value (GLfixed). |
private static int |
toX(int value)
Converts an int to a fixed-point value (GLfixed). |
| Methods inherited from class javax.microedition.lcdui.game.GameCanvas |
|---|
flushGraphics, flushGraphics, getGraphics, getKeyStates, paint |
| Methods inherited from class javax.microedition.lcdui.Canvas |
|---|
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, keyPressed, keyReleased, keyRepeated, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, setCommandListener, setFullScreenMode, showNotify, sizeChanged |
| Methods inherited from class javax.microedition.lcdui.Displayable |
|---|
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setTicker, setTitle |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final byte[] VERTEX_POSITIONS
private static final byte[] VERTEX_TEX_COORDS
private static final byte[] FACE_NORMALS
private static final byte[] STRIPS
private int angle
private boolean isRunning
private javax.microedition.lcdui.Graphics graphics
private javax.microedition.khronos.egl.EGL10 egl
private javax.microedition.khronos.opengles.GL10 gl
private javax.microedition.khronos.egl.EGLDisplay eglDisplay
private javax.microedition.khronos.egl.EGLContext eglContext
private javax.microedition.khronos.egl.EGLSurface eglWindowSurface
| Constructor Detail |
|---|
public OpenGLSample()
| Method Detail |
|---|
public void init()
public void destroy()
public void run()
run in interface java.lang.Runnableprivate void initGL()
private void initCube()
private void initLight()
private void initTexture(java.lang.String resource)
resource - named resource.
private void initCamera(float fovy,
float aspectRatio,
float near,
float far)
fovy - field of view in the vertical direction, in degrees.aspectRatio - the viewport's width divided by its height.near - distance to the front clipping plane.far - distance to the back clipping plane.private void render(javax.microedition.lcdui.Graphics graphics)
graphics - graphics context for drawing.private static int toX(int value)
value - conversion value.
private static int toX(float value)
value - conversion value.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||