安装的OpenGL ES和编译code为Android [英] Install OpenGL ES and compile code for android

查看:111
本文介绍了安装的OpenGL ES和编译code为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在Android上学习的OpenGL ES(使用这本书)和碰到的问题采用 code,从第5章使用Android的JNI(实际上,这也是现有方法关注只是运行的本地应用程序GL)。我想要编译本土code得到的.so lib和进一步利用它在apk文件归档。不过,在编译是不可能的,如果某些库不是present(这是GLES / gl.h,EGL / egl.h,GLES / gl.h,GLES / glext.h)。

所以,问题是我怎么安装这些库(AFAIU,OpenGL ES的和EGL安装)和编译最琐碎的本土code? (教程非常难受)。

在此先感谢。

编辑:我已经试过了 glbuffer 例如作为建议(稍有变化的.mk文件),但还是没有成功。编译器给了我同样的结果和以前一样:

  

NDK建造

     

编译大拇指:EGL< = cube.c

     

/path/jni/cube.c:5:21:错误:GLES / gl.h:没有这样的文件或目录//相同的消息glbuffer时被包含gl.h

下面是cube.c code:

 的#include< unistd.h中>
#包括< stdlib.h中>
#包括< stdio.h中>

#包括< GLES / gl.h>

#定义FIXED_ONE 0x10000处
#定义1 1.0F

的typedef无符号字节字符;

EXTERN无效jni_printf(字符*格式,...);

//立方静
GLfloat顶点[24] = { - 酮,酮,酮,1, - 酮,
酮,1,1, - 酮,酮,1, - 酮,酮,酮,一,一,酮,一,一,一,一,酮,一,一,};

静态GLfloat颜色[] = {0,0,0,1,1,0,0,1,1,1,0,1,0,1,0>一,0,0,1,1,1,0,1,1,1,1,1,1,0,1,1,1,};

静态字节索引[] = {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};


无效Cube_draw(){
glFrontFace(GL_CW);
的glVertexPointer(3,GL_FLOAT,0,顶点);
glColorPointer(4,GL_FLOAT,0,颜色);
与glDrawElements(GL_TRIANGLES,36,GL_UNSIGNED_BYTE,索引); }
 

这是非常琐碎和没有工作,但。

Android.mk:

  LOCAL_PATH:= $(叫我-DIR)

包括$(CLEAR_VARS)

LOCAL_LDLIBS:= -lGLESv1_CM.so
LOCAL_MODULE:= EGL
LOCAL_SRC_FILES:= cube.c cuberenderer.c

包括$(BUILD_SHARED_LIBRARY)
 

解决方案

这些库由机器人本身提供。然而,设置项目找到他们,正确编译JNI(本机)code可以是艰巨的。

我建议使用 glbuffer 为起点的项目,因为它会为你提供一个 GLSurfaceView 来借鉴,并为您设置适当的Andr​​oid库。

链接到了Android库的详情载于 JNI / Android.mk 的项目中,如果你想从头开始,给它一个镜头自己

修改 - 显然glbuffer缺少 JNI / Application.mk 。创建并放在这里面的:

  APP_ABI:= armeabi armeabi,V7A
APP_PLATFORM:=机器人-8
 

那么NDK就知道看在Android-8平台里面的包含。您可以根据需要更改为其他版本。

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)

解决方案

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.

这篇关于安装的OpenGL ES和编译code为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆