OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Native.cpp File Reference

The application shows the projected lights effect. There is a spot light effect adjusted to display the texture instead of the normal light colour. There is also a shadow map technique used to make the scene more realistic by applying some shadows. More...

#include <jni.h>
#include <android/log.h>
#include <GLES3/gl3.h>
#include "Common.h"
#include "CubeModel.h"
#include "Mathematics.h"
#include "Matrix.h"
#include "PlaneModel.h"
#include "ProjectedLights.h"
#include "Shader.h"
#include "Texture.h"
#include "Timer.h"
#include <cstring>

Go to the source code of this file.

Functions

static void drawCubeAndPlane (bool isCameraPointOfView)
 Draw cube and plane model. More...
 
static void generateAndPrepareColorTextureObject ()
 Generate a colour texture object and fill it with data. More...
 
static void generateAndPrepareDepthTextureObject ()
 Generate a depth texture object, set its properties and bind it to the generated framebuffer object. More...
 
static void getRenderSceneProgramLocations (GLuint programObjectId, RenderSceneProgramLocations *locationsStoragePtr)
 Retrieve locations for attributes and uniforms used in a program object responsible for rendering a scene. More...
 
static void initializeProgramObject (ProgramAndShaderObjectIds *objectIdsPtr, const char *fragmentShaderFileName, const char *vertexShaderFileName)
 Create and compile shader objects. If successful, they are attached to the program object, which is then linked. More...
 
static void initializeViewMatrices ()
 Initilize data that will be used to translate vertices into eye- and NDC-space. More...
 
static void renderFrame ()
 Function called to render the new frame into the back buffer. More...
 
static void setupGeometryData ()
 Prepare the geometry data that will be used while rendering the scene. More...
 
static void setupGraphics (int width, int height)
 Prepare the OpenGLES environment to start the animation. More...
 
static void uninit ()
 Delete created objects and free allocated memory. More...
 
static void updateSpotLightDirection ()
 Calculate the updated direction of the spot light and update the corresponding OpenGLES object settings so that the new spot light direction will be used. More...
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_projectedLights_NativeLibrary_init (JNIEnv *env, jobject obj, jint width, jint height)
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_projectedLights_NativeLibrary_step (JNIEnv *env, jobject obj)
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_projectedLights_NativeLibrary_uninit (JNIEnv *env, jobject obj)
 

Variables

CameraViewProperties cameraViewProperties
 
GeometryProperties cubeGeometryProperties
 
DirectionalLightProperties directionalLightProperties
 
SpotLightViewProperites lightViewProperties
 
GeometryProperties planeGeometryProperties
 
RenderSceneObjects renderSceneObjects
 
ProgramAndShaderObjectIds renderSceneProgramAndShadersIds
 
RenderSceneProgramLocations renderSceneProgramLocations
 
GLsizei shadowMapHeight
 
GLsizei shadowMapWidth
 
SpotLightProperties spotLightProperties
 
Timer timer
 
GLsizei windowHeight
 
GLsizei windowWidth
 

Detailed Description

The application shows the projected lights effect. There is a spot light effect adjusted to display the texture instead of the normal light colour. There is also a shadow map technique used to make the scene more realistic by applying some shadows.

The projected lights effect is implemented in two basic steps described as follows:

  1. Calculating the shadow map. a. The scene is rendered from spot light's point of view. b. The result is stored in the depth texture, which is called a shadow map. c. The shadow map will be used in next steps to verify whether a fragment should be lit by the spot light or should be obscured by shadow.
  2. Scene rendering. a. The scene (which consists of a plane, on top of which is placed a single cube) is rendered from the camera's point of view. b. Directional lighting is implemented to accentuate the 3D scene with the perspective. c. A spot light effect is implemented, however it is adjusted to display texture rather than a simple colour. d. Shadows are computed for the spot lighting (the result of the first step is now used).

Definition in file Native.cpp.

Function Documentation

static void drawCubeAndPlane ( bool  isCameraPointOfView)
static

Draw cube and plane model.

Note
It is assumed that proper program object is made active.
Parameters
isCameraPointOfViewTrue, if a scene from camera point of view is supposed to be rendered. False in case of rendering a scene from spot light perspective.

Definition at line 163 of file Native.cpp.

static void generateAndPrepareColorTextureObject ( )
static

Generate a colour texture object and fill it with data.

Note
The texture will be projected onto the scene.

Definition at line 279 of file Native.cpp.

static void generateAndPrepareDepthTextureObject ( )
static

Generate a depth texture object, set its properties and bind it to the generated framebuffer object.

Note
The texture object will be used to store scene depth values calculated from the spot light's point of view.

Definition at line 343 of file Native.cpp.

static void getRenderSceneProgramLocations ( GLuint  programObjectId,
RenderSceneProgramLocations locationsStoragePtr 
)
static

Retrieve locations for attributes and uniforms used in a program object responsible for rendering a scene.

Parameters
programObjectIdID of a program object for which locations are queried.
locationsStoragePtrPointer to structure object where retrieved locations will be stored. Cannot be NULL.

Definition at line 400 of file Native.cpp.

static void initializeProgramObject ( ProgramAndShaderObjectIds objectIdsPtr,
const char *  fragmentShaderFileName,
const char *  vertexShaderFileName 
)
static

Create and compile shader objects. If successful, they are attached to the program object, which is then linked.

Parameters
objectIdsPtrDeref where generated program and shader objects IDs will be stored. Cannot be NULL.
fragmentShaderFileNameName of fragment shader file. Cannot be NULL.
vertexShaderFileNameName of vertex shader file. Cannot be NULL.

Definition at line 455 of file Native.cpp.

static void initializeViewMatrices ( )
static

Initilize data that will be used to translate vertices into eye- and NDC-space.

Definition at line 487 of file Native.cpp.

JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_projectedLights_NativeLibrary_init ( JNIEnv *  env,
jobject  obj,
jint  width,
jint  height 
)

Definition at line 993 of file Native.cpp.

JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_projectedLights_NativeLibrary_step ( JNIEnv *  env,
jobject  obj 
)

Definition at line 1006 of file Native.cpp.

JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_projectedLights_NativeLibrary_uninit ( JNIEnv *  env,
jobject  obj 
)

Definition at line 999 of file Native.cpp.

static void renderFrame ( void  )
static

Function called to render the new frame into the back buffer.

Definition at line 566 of file Native.cpp.

static void setupGeometryData ( )
static

Prepare the geometry data that will be used while rendering the scene.

Store data in the buffer objects so that it can be used during draw calls.

Definition at line 646 of file Native.cpp.

static void setupGraphics ( int  width,
int  height 
)
static

Prepare the OpenGLES environment to start the animation.

Note
There are OpenGLES objects created and filled with data needed for rendering.
Parameters
widthWindow width.
heightWindow height.

Definition at line 702 of file Native.cpp.

static void uninit ( )
static

Delete created objects and free allocated memory.

Definition at line 872 of file Native.cpp.

static void updateSpotLightDirection ( )
static

Calculate the updated direction of the spot light and update the corresponding OpenGLES object settings so that the new spot light direction will be used.

Definition at line 935 of file Native.cpp.

Variable Documentation

CameraViewProperties cameraViewProperties

Definition at line 147 of file Native.cpp.

GeometryProperties cubeGeometryProperties

Definition at line 148 of file Native.cpp.

DirectionalLightProperties directionalLightProperties

Definition at line 149 of file Native.cpp.

SpotLightViewProperites lightViewProperties

Definition at line 150 of file Native.cpp.

GeometryProperties planeGeometryProperties

Definition at line 151 of file Native.cpp.

RenderSceneObjects renderSceneObjects

Definition at line 152 of file Native.cpp.

ProgramAndShaderObjectIds renderSceneProgramAndShadersIds

Definition at line 153 of file Native.cpp.

RenderSceneProgramLocations renderSceneProgramLocations

Definition at line 154 of file Native.cpp.

GLsizei shadowMapHeight

Definition at line 155 of file Native.cpp.

GLsizei shadowMapWidth

Definition at line 156 of file Native.cpp.

SpotLightProperties spotLightProperties

Definition at line 157 of file Native.cpp.

Timer timer

Definition at line 158 of file Native.cpp.

GLsizei windowHeight

Definition at line 159 of file Native.cpp.

GLsizei windowWidth

Definition at line 160 of file Native.cpp.