Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install OpenGL ES and compile code for android

I've just started learning OpenGL ES on android (using this book) and came across an issue of adopting source code from chapter 5 to existing methods of using jni in android (actually, it also concerns simply running a native GL app). I'm trying to compile the native code to get the .so lib and use it further in .apk archive. But compilation is not possible if certain libs are not present (which are GLES/gl.h, EGL/egl.h, GLES/gl.h, GLES/glext.h).

So the question is how do I install those libs (AFAIU, OpenGL ES and EGL installation) and compile the most trivial native code? (tutorials are highly admired).

Thanks in advance.

EDIT: I've tried the glbuffer example as was suggested (slightly changed .mk file), but still no success. Compiler gives me the same result as before:

ndk-build

Compile thumb: egl <= cube.c

/path/jni/cube.c:5:21: error: GLES/gl.h: No such file or directory // same message for glbuffer when gl.h is being included

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); }

It's awfully trivial and not working, yet.

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)
like image 495
Denys S. Avatar asked Mar 14 '11 15:03

Denys S.


People also ask

Does Android use OpenGL ES?

Android includes support for high performance 2D and 3D graphics with the Open Graphics Library (OpenGL®), specifically, the OpenGL ES API. OpenGL is a cross-platform graphics API that specifies a standard software interface for 3D graphics processing hardware.

Is OpenGL the same as OpenGL ES?

The main difference between the two is that OpenGL ES is made for embedded systems like smartphones, while OpenGL is the one on desktops. On the coding level, OpenGL ES does not support fixed-function functions like glBegin/glEnd etc... OpenGL can support fixed-function pipeline (using a compatibility profile).


2 Answers

Those libraries are provided by Android itself. However, setting up your project to find them and compile your JNI (native) code correctly can be daunting.

I recommend using glbuffer as a starting project, as it will provide you with a GLSurfaceView to draw on and set you up with the proper Android libraries.

The details of linking to the Android libraries are contained in jni/Android.mk inside that project if you'd like to give it a shot yourself from scratch.

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

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

Then the ndk will know to look inside the android-8 platform for your includes. You can change this to other versions as needed.

like image 104
Matthew Willis Avatar answered Oct 08 '22 07:10

Matthew Willis


I searched the NDK for instances of the "EGL/egl.h" header file. This particular example will compile and run on Android API level 15, but some other API levels don't have the header.

like image 40
Matt Russell Avatar answered Oct 08 '22 07:10

Matt Russell