22 #include <android/log.h>
24 #include <GLES2/gl2.h>
25 #include <GLES2/gl2ext.h>
34 #define LOG_TAG "libNative"
35 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
36 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
40 "attribute vec4 vertexPosition;\n"
41 "attribute vec2 vertexTextureCord;\n"
42 "varying vec2 textureCord;\n"
43 "uniform mat4 projection;\n"
44 "uniform mat4 modelView;\n"
47 " gl_Position = projection * modelView * vertexPosition;\n"
48 " textureCord = vertexTextureCord;\n"
52 "precision mediump float;\n"
53 "uniform sampler2D texture;\n"
54 "varying vec2 textureCord;\n"
57 " gl_FragColor = texture2D(texture, textureCord);\n"
63 GLuint shader = glCreateShader(shaderType);
66 glShaderSource(shader, 1, &shaderSource, NULL);
67 glCompileShader(shader);
70 glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
72 if (compiled != GL_TRUE)
75 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
79 char * logBuffer = (
char*) malloc(infoLen);
81 if (logBuffer != NULL)
83 glGetShaderInfoLog(shader, infoLen, NULL, logBuffer);
84 LOGE(
"Could not Compile Shader %d:\n%s\n", shaderType, logBuffer);
89 glDeleteShader(shader);
101 if (vertexShader == 0)
107 if (fragmentShader == 0)
116 glAttachShader(program , vertexShader);
117 glAttachShader(program, fragmentShader);
118 glLinkProgram(program);
119 GLint linkStatus = GL_FALSE;
120 glGetProgramiv(program , GL_LINK_STATUS, &linkStatus);
122 if(linkStatus != GL_TRUE)
126 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
130 char* logBuffer = (
char*) malloc(bufLength);
132 if (logBuffer != NULL)
134 glGetProgramInfoLog(program, bufLength, NULL, logBuffer);
135 LOGE(
"Could not link program:\n%s\n", logBuffer);
140 glDeleteProgram(program);
166 LOGE (
"Could not create program");
178 glEnable(GL_DEPTH_TEST);
180 glViewport(0, 0, width, height);
215 -1.0f, - 1.0f, -1.0f,
248 GLushort
indicies[] = {0, 3, 2, 0, 1, 3, 4, 6, 7, 4, 7, 5, 8, 9, 10, 8, 11, 10, 12, 13, 14, 15, 12, 14, 16, 17, 18, 16, 19, 18, 20, 21, 22, 20, 23, 22};
252 glClearColor(0.0
f, 0.0
f, 0.0
f, 1.0
f);
253 glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
275 glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT,
indicies);
288 JNIEnv * env, jobject obj);
292 JNIEnv * env, jobject obj, jint
width, jint
height)
298 JNIEnv * env, jobject obj)
static const char glFragmentShader[]
float projectionMatrix[16]
float modelViewMatrix[16]
GLint GLsizei GLsizei height
void matrixIdentityFunction(float *matrix)
Takes a 4 * 4 and sets the elements to the Identity function.
void matrixPerspective(float *matrix, float fieldOfView, float aspectRatio, float zNear, float zFar)
Create a perspective projection matrix and store the results in the first parameter.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_texturecube_NativeLibrary_step(JNIEnv *env, jobject obj)
GLuint textureCordLocation
void matrixRotateX(float *matrix, float angle)
Rotates a matrix around the x axis by a given angle.
GLuint createProgram(const char *vertexSource, const char *fragmentSource)
GLuint loadSimpleTexture()
Loads a simple 3 x 3 static texture into OpenGL ES.
GLuint loadShader(GLenum shaderType, const char *shaderSource)
static const char glVertexShader[]
void matrixTranslate(float *matrix, float x, float y, float z)
Takes in a 4 * 4 matrix and translates it by the vector defined by x y and z.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_texturecube_NativeLibrary_init(JNIEnv *env, jobject obj, jint width, jint height)
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
GLuint projectionLocation
void matrixRotateY(float *matrix, float angle)
Rotates a matrix around the y axis by a given angle.