I just started learning OpenGL ES on android (using this book ) and ran into the problem of accepting source from chapter 5 for existing methods for using jni in android (in fact, this also applies to simply launching your own GL application). I am trying to compile my own code to get .so lib and use it further in the .apk archive. But compilation is not possible if some libraries are missing (these are GLES / gl.h, EGL / egl.h, GLES / gl.h, GLES / glext.h).
So the question is how to install these libraries (AFAIU, OpenGL ES and EGL) and compile the most trivial native code? (guides really admire).
Thanks in advance.
EDIT: I tried the glbuffer example as suggested (a slightly modified .mk file), but still failed. The compiler gives me the same result as before:
NDK assembly
Compile your thumb: egl <= cube.c
/path/jni/cube.c/10:21: error: GLES / gl.h: no such file or directory // same message for glbuffer when gl.h is turned on
Here is the cube.c code:
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <GLES/gl.h> #define FIXED_ONE 0x10000 #define one 1.0f typedef unsigned char byte; extern void jni_printf(char *format, ...); // Cube static GLfloat vertices[24] = { -one, -one, -one, one, -one, -one, one, one, -one, -one, one, -one, -one, -one, one, one, -one, one, one, one, one, -one, one, one, }; static GLfloat colors[] = { 0, 0, 0, one, one, 0, 0, one, one, one, 0, one, 0, one, 0> , one, 0, 0, one, one, one, 0, one, one, one, one, one, one, 0, one, one, one, }; static byte indices[] = { 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 }; void Cube_draw() { glFrontFace(GL_CW); glVertexPointer(3, GL_FLOAT, 0, vertices); glColorPointer(4, GL_FLOAT, 0 , colors); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices); }
This is terribly trivial and not working.
Android.mk:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_LDLIBS := -lGLESv1_CM.so LOCAL_MODULE := egl LOCAL_SRC_FILES := cube.c cuberenderer.c include $(BUILD_SHARED_LIBRARY)