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

Public Member Functions

 SpinningCube3D ()
 
 SpinningCube3D (Context a_Context)
 
void createSpinningCube ()
 
void render ()
 
void setWidthHeight (int a_Width, int a_Height)
 
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_CubeFBOTextureId
 
int[] m_RenderToTextureFBO = new int[1]
 
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]
 
int m_Width
 
int m_Height
 
int m_FBOWidth = 256
 
int m_FBOHeight = 256
 

Detailed Description

SpinningCube3D contains all the geometry of the Cube It also contains the required vertex/normal/texture-coordinates buffers

Definition at line 38 of file SpinningCube3D.java.

Constructor & Destructor Documentation

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

Default constructor

Definition at line 117 of file SpinningCube3D.java.

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

One argument constructor initializes the cube data structures

Save the context for later use

Definition at line 122 of file SpinningCube3D.java.

Member Function Documentation

void com.arm.malideveloper.openglessdk.rendertotexturejava.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

Create the texture, setup its properties for the FBO

Bind the texture for FBO and Setup its properties

Create the Frame Buffer Objects for rendering into it

Initialize FBO

Bind our frame buffer

Attach texture to the frame buffer

Check FBO is complete and OK

Un-bind frame buffer

Definition at line 321 of file SpinningCube3D.java.

void com.arm.malideveloper.openglessdk.rendertotexturejava.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 182 of file SpinningCube3D.java.

void com.arm.malideveloper.openglessdk.rendertotexturejava.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

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 130 of file SpinningCube3D.java.

void com.arm.malideveloper.openglessdk.rendertotexturejava.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 157 of file SpinningCube3D.java.

void com.arm.malideveloper.openglessdk.rendertotexturejava.SpinningCube3D.render ( )
inline

Use only GLES20 methods

Start rendering using the OpenGL ES 2.0 shader program created earlier

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

Setup with view port with the width and height and reset the projection matrix accordingly

Create model view projection matrix

Upload the Model View Projection matrix to the bound program

set the Texture unit 0 active and bind the texture to it

Enable frame buffer to start rendering into it

Create an Orange back ground

Bind the texture

Draw the cube using the indices. There are total 36 vertices to draw

Un-bind the frame buffer and render to the screen frame buffer

Use blue background color

Setup with view port with the width and height and reset the projection matrix accordingly

Create model view projection matrix

Upload the Model View Projection matrix to the bound program

Bind the texture

Draw the cube using the indices. There are total 36 vertices to draw

Definition at line 226 of file SpinningCube3D.java.

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

Set the view port

Create the projection matrix using the aspect ratio

Definition at line 472 of file SpinningCube3D.java.

void com.arm.malideveloper.openglessdk.rendertotexturejava.SpinningCube3D.setWidthHeight ( int  a_Width,
int  a_Height 
)
inline

Definition at line 467 of file SpinningCube3D.java.

Member Data Documentation

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

Rendering context for the Spinning Cube

Definition at line 43 of file SpinningCube3D.java.

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

Texture ID for the cube diffuse color

Definition at line 56 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.rendertotexturejava.SpinningCube3D.m_CubeFBOTextureId
private

Texture ID for the FBO attached texture

Definition at line 59 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.rendertotexturejava.SpinningCube3D.m_FBOHeight = 256
private

Definition at line 114 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.rendertotexturejava.SpinningCube3D.m_FBOWidth = 256
private

Width and Height of the frame buffer

Definition at line 113 of file SpinningCube3D.java.

final String com.arm.malideveloper.openglessdk.rendertotexturejava.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 94 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.rendertotexturejava.SpinningCube3D.m_Height
private

Definition at line 110 of file SpinningCube3D.java.

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

Number of indices for the vertices in the Cube

Definition at line 53 of file SpinningCube3D.java.

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

Definition at line 104 of file SpinningCube3D.java.

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

Definition at line 105 of file SpinningCube3D.java.

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

Model View Projection matrix ID

Definition at line 80 of file SpinningCube3D.java.

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

Different matrices required for correct transformations

Definition at line 103 of file SpinningCube3D.java.

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

Definition at line 106 of file SpinningCube3D.java.

int [] com.arm.malideveloper.openglessdk.rendertotexturejava.SpinningCube3D.m_RenderToTextureFBO = new int[1]
private

Vertex buffer object and Index buffer object IDs Frame Buffer FBO ID

Definition at line 64 of file SpinningCube3D.java.

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

Rotation angle in X and Y axis

Definition at line 46 of file SpinningCube3D.java.

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

Definition at line 47 of file SpinningCube3D.java.

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

Shader Program ID

Definition at line 73 of file SpinningCube3D.java.

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

Vertex Attributes IBO ID

Definition at line 70 of file SpinningCube3D.java.

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

Vertex Attributes VBO ID

Definition at line 67 of file SpinningCube3D.java.

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

Number of vertices in the Cube

Definition at line 50 of file SpinningCube3D.java.

final String com.arm.malideveloper.openglessdk.rendertotexturejava.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 84 of file SpinningCube3D.java.

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

Vertices attributes IDs

Definition at line 76 of file SpinningCube3D.java.

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

Definition at line 77 of file SpinningCube3D.java.

int com.arm.malideveloper.openglessdk.rendertotexturejava.SpinningCube3D.m_Width
private

Width and Height of the screen buffer

Definition at line 109 of file SpinningCube3D.java.


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