Install OpenGL ES and compile Android code

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) 
+8
c android compilation android-ndk opengl-es
source share
4 answers

These libraries are provided by Android itself. However, setting up your project to find them and compiling your JNI (native) code can be complicated.

I recommend using glbuffer as your starting project, as it will provide you with GLSurfaceView for drawing and customization with the appropriate Android libraries.

Details of binding to Android libraries are contained in jni/Android.mk inside this project if you want to do it yourself from scratch.

Edit - it is obvious that glbuffer is missing jni/Application.mk . Create it and put inside:

 APP_ABI := armeabi armeabi-v7a APP_PLATFORM := android-8 

Then ndk will know what to look inside the Android-8 platform. You can change this to other versions as needed.

+17
source share

I searched the NDK for instances of the header file "EGL / egl.h". This specific example will compile and run at the Android 15 API level, but some other API levels do not have a header.

+5
source share

I just added

 #include <jni.h> 

in cube.c and cuberenderer.c

Modified

 (*g_VM)->AttachCurrentThread (g_VM, (void **) &env, NULL); 

to

 (*g_VM)->AttachCurrentThread (g_VM, (const struct JNINativeInterface ***) &env, NULL); 

My Android.mk:

 LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libgltest_jni LOCAL_CFLAGS := -Werror LOCAL_SRC_FILES := cube.c cuberenderer.c LOCAL_LDLIBS := -llog -lGLESv1_CM include $(BUILD_SHARED_LIBRARY) 

My Application.mk:

 # The ARMv7 is significanly faster due to the use of the hardware FPU APP_ABI := armeabi armeabi-v7a APP_PLATFORM := android-9 

And built it on android-ndk-r6

+3
source share

You used the GLES / glext.h file name twice.

-2
source share

All Articles