OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D Class Reference

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]
 

Detailed Description

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.

Constructor & Destructor Documentation

com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.SpinningCube3D ( )
inline

Default constructor

Definition at line 101 of file SpinningCube3D.java.

com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.SpinningCube3D ( Context  a_Context)
inline

One argument constructor initializes the cube data structures

Save the context for later use

Definition at line 106 of file SpinningCube3D.java.

Member Function Documentation

void com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.buildVertexAndIndexBufferObjects ( )
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.

void com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.createShaderProgram ( )
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.

void com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.createSpinningCube ( )
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.

void com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.createTexture ( )
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.

void com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.render ( )
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.

void com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.setProjection ( int  a_Width,
int  a_Height 
)
inline

Set the view port

Create the projection matrix using the aspect ratio

Definition at line 388 of file SpinningCube3D.java.

Member Data Documentation

Context com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_Context
private

Rendering context for the Spinning Cube

Definition at line 42 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_CubeDiffuseTextureId
private

Texture ID for the cube diffuse color

Definition at line 55 of file SpinningCube3D.java.

final String com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_FragmentShaderSource
private
Initial value:
=
"precision mediump float;\n" +
"varying vec2 vTextureCoordinate;\n" +
"uniform sampler2D sTextureSampler;\n" +
"void main(){\n" +
"gl_FragColor = texture2D(sTextureSampler, vTextureCoordinate);\n" +
"}\n"

Definition at line 86 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_IndexCount = 36
private

Number of indices for the vertices in the Cube

Definition at line 52 of file SpinningCube3D.java.

float [] com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_ModelingMatrix = new float[16]
private

Definition at line 96 of file SpinningCube3D.java.

float [] com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_ModelViewMatrix = new float[16]
private

Definition at line 97 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_ModelViewProjectionId
private

Model View Projection matrix ID

Definition at line 72 of file SpinningCube3D.java.

float [] com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_ModelViewProjectionMatrix = new float[16]
private

Different matrices required for correct transformations

Definition at line 95 of file SpinningCube3D.java.

float [] com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_ProjectionMatrix = new float[16]
private

Definition at line 98 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_RotateX = 0
private

Rotation angle in X and Y axis

Definition at line 45 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_RotateY = 360
private

Definition at line 46 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_ShaderProgramID
private

Shader Program ID

Definition at line 65 of file SpinningCube3D.java.

int [] com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_VertexAttributeIBO = new int[1]
private

Vertex Attributes IBO ID

Definition at line 62 of file SpinningCube3D.java.

int [] com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_VertexAttributeVBO = new int[1]
private

Vertex buffer object and Index buffer object IDs Vertex Attributes VBO ID

Definition at line 59 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_VertexCount = 23
private

Number of vertices in the Cube

Definition at line 49 of file SpinningCube3D.java.

final String com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_VertexShaderSource
private
Initial value:
=
"uniform mat4 uModelViewProjection;\n" +
"attribute vec4 aPosition;\n" +
"attribute vec2 aTextureCoordinate;\n" +
"varying vec2 vTextureCoordinate;\n" +
"void main(){\n" +
"gl_Position = uModelViewProjection * aPosition;\n" +
"vTextureCoordinate = aTextureCoordinate;\n" +
"}\n"

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.

int com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_VerticesPositionAttributeId
private

Vertices attributes IDs

Definition at line 68 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.spinningcubejava.SpinningCube3D.m_VerticesTextureAttributeId
private

Definition at line 69 of file SpinningCube3D.java.


The documentation for this class was generated from the following file: