23 #include <android/log.h>
25 #include <GLES2/gl2.h>
26 #include <GLES2/gl2ext.h>
32 #define LOG_TAG "libNative"
33 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
34 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
39 "attribute vec4 vPosition;\n"
42 " gl_Position = vPosition;\n"
48 "precision mediump float;\n"
51 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
58 GLuint shader = glCreateShader(shaderType);
61 glShaderSource(shader, 1, &shaderSource, NULL);
62 glCompileShader(shader);
65 glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
70 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
74 char *
buf = (
char*) malloc(infoLen);
78 glGetShaderInfoLog(shader, infoLen, NULL, buf);
79 LOGE(
"Could not Compile Shader %d:\n%s\n", shaderType, buf);
83 glDeleteShader(shader);
112 glAttachShader(program , vertexShader);
113 glAttachShader(program, fragmentShader);
115 glLinkProgram(program);
116 GLint linkStatus = GL_FALSE;
118 glGetProgramiv(program , GL_LINK_STATUS, &linkStatus);
120 if( linkStatus != GL_TRUE)
124 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
128 char*
buf = (
char*) malloc(bufLength);
132 glGetProgramInfoLog(program, bufLength, NULL, buf);
133 LOGE(
"Could not link program:\n%s\n", buf);
137 glDeleteProgram(program);
156 LOGE (
"Could not create program");
162 glViewport(0, 0, w, h);
177 glClearColor(0.0
f, 0.0
f, 0.0
f, 1.0
f);
178 glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
182 glDrawArrays(GL_TRIANGLES, 0, 3);
189 JNIEnv * env, jobject obj, jint
width, jint
height);
191 JNIEnv * env, jobject obj);
196 JNIEnv * env, jobject obj, jint
width, jint
height)
202 JNIEnv * env, jobject obj)
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_simpletriangle_NativeLibrary_init(JNIEnv *env, jobject obj, jint width, jint height)
GLint GLsizei GLsizei height
GLuint createProgram(const char *vertexSource, const char *fragmentSource)
GLfloat GLfloat GLfloat w
GLuint loadShader(GLenum shaderType, const char *shaderSource)
GLfloat GLfloat GLfloat GLfloat h
const GLfloat triangleVertices[]
GLuint simpleTriangleProgram
static const char glFragmentShader[]
GLenum GLuint GLenum GLsizei const GLchar * buf
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_simpletriangle_NativeLibrary_step(JNIEnv *env, jobject obj)
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
static const char glVertexShader[]