OpenGL ES SDK for Android
ARM Developer Center
|
Public Member Functions | |
SpinningCube3D () | |
SpinningCube3D (Context a_Context) | |
void | createSpinningCube () |
void | render () |
void | setProjection (int a_Width, int a_Height) |
Private Member Functions | |
void | createTexture () |
void | createShaderProgram () |
void | buildVertexAndIndexBufferObjects () |
Private Attributes | |
Context | m_Context |
int | m_RotateX = 0 |
int | m_RotateY = 360 |
int | m_VertexCount = 23 |
int | m_IndexCount = 36 |
int | m_CubeDiffuseTextureId |
int[] | m_VertexAttributeVBO = new int[1] |
int[] | m_VertexAttributeIBO = new int[1] |
int | m_ShaderProgramID |
int | m_VerticesPositionAttributeId |
int | m_VerticesTextureAttributeId |
int | m_ModelViewProjectionId |
final String | m_VertexShaderSource |
final String | m_FragmentShaderSource |
float[] | m_ModelViewProjectionMatrix = new float[16] |
float[] | m_ModelingMatrix = new float[16] |
float[] | m_ModelViewMatrix = new float[16] |
float[] | m_ProjectionMatrix = new float[16] |
SpinningCube3D contains all the geometry of the Cube It also contains the required vertex/normal/texture-coordinates buffers
Definition at line 37 of file SpinningCube3D.java.
|
inline |
Default constructor
Definition at line 101 of file SpinningCube3D.java.
|
inline |
One argument constructor initializes the cube data structures
Save the context for later use
Definition at line 106 of file SpinningCube3D.java.
|
inlineprivate |
Vertices Positions
Vertices Texture Coordinates
Add other Vertices attributes Here
Triangle Indices
Front First
Front Second
Right First
Right Second
Back First
Back Second
Left First
Left Second
Top First
Top Second
Bottom First
Bottom Second
Buffers for vertices and indices
Copy the vertices and indices into the buffers
Generate the Vertex Buffers and get valid buffer IDs from OpenGL
Load the VBO data into the driver
Load the IBO data into the driver
Definition at line 275 of file SpinningCube3D.java.
|
inlineprivate |
Create the vertex shader
Upload the vertex shader source to OpenGL ES and compile it
Create the fragment shader
Upload the fragment shader source to OpenGL ES and compile it
Create the shader program and attache the vertex and fragment shaders to it
Link the program
Get Vertices Position attribute index from GLES
Get Vertices Texture Coordinate attribute index from GLES
Get Model View Projection matrix index from GLES
Definition at line 170 of file SpinningCube3D.java.
|
inline |
Create the spinning cube and setup OpenGL ES states
OpenGL ES initialization is done here
Enable back face culling to avoid drawing faces that are invisible
Use black background color
Enable depth testing
Create the Shader Program, Vertex and Fragment shaders
Create the texture and upload it to OpenGL ES
Build the Vertex and Index buffers objects and load data into it
Initialized the viewing matrix
From (0,0,-2) To (0,0,0) Up Vector (0,1,0)
Definition at line 114 of file SpinningCube3D.java.
|
inlineprivate |
Create the texture and upload it to OpenGL ES
Create the texture, setup its properties and upload it to OpenGL ES
Bind the texture and Setup its properties
Load the resource as a bitmap
Upload the texture to OpenGL ES
Mark the bitmap for deletion
Definition at line 145 of file SpinningCube3D.java.
|
inline |
Use only GLES20 methods
Start rendering using the OpenGL ES 2.0 shader program created earlier
set the Texture unit 0 active and bind the texture to it
Bind the Vertex and Index buffers
Set the pointers to the vertex position attributes
The magic number 3 means 3-float-components for each vertex position
set the pointers to the vertex texture coordinates attributes
The magic number 2 means 3-float-components for each vertex texture coordinate
The magic number 3 means 3-float-components for each vertex position
Update the rotation angles and check against maximum and minimum values
Create matrices from the euler angles
Combine the matrices into the Modeling Matrix
Create model view projection matrix
Upload the Model View Projection matrix to the bound program
Draw the cube using the indices. There are total 36 vertices to draw
Definition at line 214 of file SpinningCube3D.java.
|
inline |
Set the view port
Create the projection matrix using the aspect ratio
Definition at line 388 of file SpinningCube3D.java.
|
private |
Rendering context for the Spinning Cube
Definition at line 42 of file SpinningCube3D.java.
|
private |
Texture ID for the cube diffuse color
Definition at line 55 of file SpinningCube3D.java.
|
private |
Definition at line 86 of file SpinningCube3D.java.
|
private |
Number of indices for the vertices in the Cube
Definition at line 52 of file SpinningCube3D.java.
|
private |
Definition at line 96 of file SpinningCube3D.java.
|
private |
Definition at line 97 of file SpinningCube3D.java.
|
private |
Model View Projection matrix ID
Definition at line 72 of file SpinningCube3D.java.
|
private |
Different matrices required for correct transformations
Definition at line 95 of file SpinningCube3D.java.
|
private |
Definition at line 98 of file SpinningCube3D.java.
|
private |
Rotation angle in X and Y axis
Definition at line 45 of file SpinningCube3D.java.
|
private |
Definition at line 46 of file SpinningCube3D.java.
|
private |
Shader Program ID
Definition at line 65 of file SpinningCube3D.java.
|
private |
Vertex Attributes IBO ID
Definition at line 62 of file SpinningCube3D.java.
|
private |
Vertex buffer object and Index buffer object IDs Vertex Attributes VBO ID
Definition at line 59 of file SpinningCube3D.java.
|
private |
Number of vertices in the Cube
Definition at line 49 of file SpinningCube3D.java.
|
private |
Shader sources for the Shaders used in Spinning Cube This could also be loaded from Shader resource files
Definition at line 76 of file SpinningCube3D.java.
|
private |
Vertices attributes IDs
Definition at line 68 of file SpinningCube3D.java.
|
private |
Definition at line 69 of file SpinningCube3D.java.