OpenGL ES SDK for Android
ARM Developer Center
|
#include <jni.h>
#include <android/log.h>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include "Common.h"
#include "Matrix.h"
#include "Native.h"
#include "Texture.h"
#include "Timer.h"
#include "Shader.h"
Go to the source code of this file.
Functions | |
void | initialize3DTexture () |
Initializes OpenGL ES texture components. More... | |
void | initializeAttribArrays () |
Initializes input vertex data for shaders. More... | |
void | initializeProgram () |
Creates program and attaches shaders to it. More... | |
void | initializeTextureData () |
Fills 3D texture with images. More... | |
void | initializeUniformData () |
Initializes uniform variables in program. More... | |
void | loadImages () |
Loads imagesCount images located in resourceDirectory. More... | |
void | loadUniformTextures (int count) |
Creates and loads count unicolor layers to a 3D texture. More... | |
void | renderFrame () |
Renders single frame. More... | |
void | setBlendEquation (GLboolean isMinBlending) |
Sets current blending equation. More... | |
void | setNextTextureImage (GLvoid *textureData) |
Fills next empty 3D texture layer with textureData. More... | |
void | setupGraphics (int width, int height) |
Initializes OpenGL ES context. More... | |
void | uninit () |
Releases OpenGL ES objects. More... | |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_minMaxBlending_NativeLibrary_init (JNIEnv *, jobject, jint width, jint height) |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_minMaxBlending_NativeLibrary_step (JNIEnv *, jobject) |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_minMaxBlending_NativeLibrary_uninit (JNIEnv *, jobject) |
Variables | |
const string | resourceDirectory = "/data/data/com.arm.malideveloper.openglessdk.minMaxBlending/files/" |
const string | imagesFilename = "MRbrain" |
const int | imagesCount = 109 |
Timer | timer |
int | windowWidth = 0 |
int | windowHeight = 0 |
const GLint | textureWidth = 256 |
const GLint | textureHeight = 256 |
const GLint | textureDepth = 128 |
const GLfloat | minBlendingThreshold = 0.37f |
const short | fillerLuminance = 4 |
GLuint | textureID = 0 |
GLuint | programID = 0 |
GLuint | verticesBufferID = 0 |
GLuint | uvwBufferID = 0 |
GLuint | vaoID = 0 |
GLint | isMinBlendingLocation = -1 |
GLint | rotationVectorLocation = -1 |
GLint | textureZOffset = 0 |
GLboolean | isMinBlending = GL_FALSE |
const float | resetTimeInterval = 5.0f |
const float | squareVertices [] |
const float | uvwCoordinates [] |
The application demonstrates behaviour of blending in GL_MIN and GL_MAX mode. It renders a 3D texture which consists of a series of greyscaled images obtained from magnetic resonance of a human head. The images are placed one after another in Z axis, so when blending is enabled they imitate a 3D model of the head.
Texture coordinates are then rotated, so viewers can see the model from different perspectives and after each 5 seconds, blending equation is changed. Since U/V/W coordinates are taken from interval <0.0, 1.0> and they are clamped to edge, there might occure some distortions for specific angles of rotation. That is why, the application adds a few blank layers behind and in the front of the original images. Now, if rotated coordinates exceed the interval, only the additional edge layers are repeated creating a noiseless background.
Because images contain a lot of black color, regular min blending would result in having black square on the screen. Hence, there is a threshold applied in fragment shader which prevents rendering fragments that are not bright enough. Additionally, for both types of blending, contrast of output luminance had to be modified to see more details.
To use your own input images, it is check their format and adjust values of min blending threshold, luminance of additional edge layers and contrast modifier.
Definition in file Native.cpp.
void initialize3DTexture | ( | ) |
Initializes OpenGL ES texture components.
Definition at line 149 of file Native.cpp.
void initializeAttribArrays | ( | ) |
Initializes input vertex data for shaders.
Definition at line 183 of file Native.cpp.
void initializeProgram | ( | ) |
Creates program and attaches shaders to it.
Definition at line 220 of file Native.cpp.
void initializeTextureData | ( | ) |
Fills 3D texture with images.
Definition at line 250 of file Native.cpp.
void initializeUniformData | ( | ) |
Initializes uniform variables in program.
Definition at line 274 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_minMaxBlending_NativeLibrary_init | ( | JNIEnv * | , |
jobject | , | ||
jint | width, | ||
jint | height | ||
) |
Definition at line 534 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_minMaxBlending_NativeLibrary_step | ( | JNIEnv * | , |
jobject | |||
) |
Definition at line 539 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_minMaxBlending_NativeLibrary_uninit | ( | JNIEnv * | , |
jobject | |||
) |
Definition at line 544 of file Native.cpp.
void loadImages | ( | ) |
Loads imagesCount images located in resourceDirectory.
Definition at line 333 of file Native.cpp.
Creates and loads count unicolor layers to a 3D texture.
count | Number of layers to be filled. |
Definition at line 362 of file Native.cpp.
Renders single frame.
Definition at line 385 of file Native.cpp.
Sets current blending equation.
isMinBlending | True, if GL_MIN blending mode should be used. |
Definition at line 433 of file Native.cpp.
void setNextTextureImage | ( | GLvoid * | textureData | ) |
Fills next empty 3D texture layer with textureData.
It is called by the functions which prepare texture data either by creating it inside the application or loading it from from a file.
textureData | Data the 3D texture is filled with. |
Definition at line 459 of file Native.cpp.
Initializes OpenGL ES context.
width | Window resolution: width. |
height | Window resolution: height. |
Definition at line 486 of file Native.cpp.
void uninit | ( | ) |
Releases OpenGL ES objects.
It should be called before leaving the application.
Definition at line 518 of file Native.cpp.
const short fillerLuminance = 4 |
Definition at line 84 of file Native.cpp.
const int imagesCount = 109 |
Definition at line 65 of file Native.cpp.
const string imagesFilename = "MRbrain" |
Definition at line 62 of file Native.cpp.
GLboolean isMinBlending = GL_FALSE |
Definition at line 110 of file Native.cpp.
GLint isMinBlendingLocation = -1 |
Definition at line 101 of file Native.cpp.
const GLfloat minBlendingThreshold = 0.37f |
Definition at line 82 of file Native.cpp.
GLuint programID = 0 |
Definition at line 90 of file Native.cpp.
const float resetTimeInterval = 5.0f |
Definition at line 113 of file Native.cpp.
const string resourceDirectory = "/data/data/com.arm.malideveloper.openglessdk.minMaxBlending/files/" |
Definition at line 61 of file Native.cpp.
GLint rotationVectorLocation = -1 |
Definition at line 102 of file Native.cpp.
const float squareVertices[] |
Definition at line 127 of file Native.cpp.
const GLint textureDepth = 128 |
Definition at line 79 of file Native.cpp.
const GLint textureHeight = 256 |
Definition at line 78 of file Native.cpp.
GLuint textureID = 0 |
Definition at line 87 of file Native.cpp.
const GLint textureWidth = 256 |
Definition at line 77 of file Native.cpp.
GLint textureZOffset = 0 |
Definition at line 107 of file Native.cpp.
Timer timer |
Definition at line 68 of file Native.cpp.
GLuint uvwBufferID = 0 |
Definition at line 95 of file Native.cpp.
const float uvwCoordinates[] |
Definition at line 138 of file Native.cpp.
GLuint vaoID = 0 |
Definition at line 98 of file Native.cpp.
GLuint verticesBufferID = 0 |
Definition at line 93 of file Native.cpp.
int windowHeight = 0 |
Definition at line 72 of file Native.cpp.
int windowWidth = 0 |
Definition at line 71 of file Native.cpp.