22 #include <android/log.h>
24 #include <GLES2/gl2.h>
25 #include <GLES2/gl2ext.h>
33 #define LOG_TAG "libNative"
34 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
35 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
40 "attribute vec4 vertexPosition;\n"
41 "attribute vec3 vertexColour;\n"
42 "varying vec3 fragColour;\n"
43 "uniform mat4 projection;\n"
44 "uniform mat4 modelView;\n"
47 " gl_Position = projection * modelView * vertexPosition;\n"
48 " fragColour = vertexColour;\n"
52 "precision mediump float;\n"
53 "varying vec3 fragColour;\n"
56 " gl_FragColor = vec4(fragColour, 1.0);\n"
62 GLuint shader = glCreateShader(shaderType);
65 glShaderSource(shader, 1, &shaderSource, NULL);
66 glCompileShader(shader);
68 glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
69 if (compiled != GL_TRUE)
72 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
76 char * logBuffer = (
char*) malloc(infoLen);
78 if (logBuffer != NULL)
80 glGetShaderInfoLog(shader, infoLen, NULL, logBuffer);
81 LOGE(
"Could not Compile Shader %d:\n%s\n", shaderType, logBuffer);
86 glDeleteShader(shader);
98 if (vertexShader == 0)
104 if (fragmentShader == 0)
113 glAttachShader(program, vertexShader);
114 glAttachShader(program, fragmentShader);
115 glLinkProgram(program);
116 GLint linkStatus = GL_FALSE;
117 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
118 if(linkStatus != GL_TRUE)
121 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
124 char* logBuffer = (
char*) malloc(bufLength);
126 if (logBuffer != NULL)
128 glGetProgramInfoLog(program, bufLength, NULL, logBuffer);
129 LOGE(
"Could not link program:\n%s\n", logBuffer);
134 glDeleteProgram(program);
221 static GLushort
indices[] = {0, 2, 3, 0, 1, 3, 4, 6, 7, 4, 5, 7, 8, 9, 10, 11, 8, 10, 12, 13, 14, 15, 12, 14, 16, 17, 18, 16, 19, 18, 20, 21, 22, 20, 23, 22};
229 LOGE (
"Could not create program");
249 glEnable(GL_DEPTH_TEST);
251 glViewport(0, 0, width, height);
258 glClearColor(0.0
f, 0.0
f, 0.0
f, 1.0
f);
259 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
281 glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
294 JNIEnv * env, jobject obj, jint
width, jint
height);
296 JNIEnv * env, jobject obj);
300 JNIEnv * env, jobject obj, jint
width, jint
height)
306 JNIEnv * env, jobject obj)
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.
GLuint vertexColourLocation
static GLuint vboBufferIds[2]
static GLushort vertexBufferSize
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_vbo_NativeLibrary_step(JNIEnv *env, jobject obj)
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.
static GLushort strideLength
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)
GLsizei GLenum const void * indices
GLuint loadShader(GLenum shaderType, const char *shaderSource)
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.
static GLushort vertexColourOffset
static const char glFragmentShader[]
static GLushort elementBufferSize
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.
static const char glVertexShader[]
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_vbo_NativeLibrary_init(JNIEnv *env, jobject obj, jint width, jint height)