【发布时间】:2011-07-15 02:45:06
【问题描述】:
我刚开始在 android 上学习 OpenGL ES(使用 this book),遇到了一个问题,将第 5 章中的 source 代码采用到在 android 中使用 jni 的现有方法(实际上,它还涉及简单地运行本机 GL 应用程序)。我正在尝试编译本机代码以获取 .so 库并在 .apk 存档中进一步使用它。但是,如果某些库不存在(即 GLES/gl.h、EGL/egl.h、GLES/gl.h、GLES/gext.h),则无法编译。
所以问题是如何安装这些库(AFAIU、OpenGL ES 和 EGL 安装)并编译最简单的本机代码? (教程备受推崇)。
提前致谢。
编辑:我已经按照建议尝试了 glbuffer 示例(稍微更改了 .mk 文件),但仍然没有成功。编译器给我的结果和以前一样:
ndk 构建
编译拇指:egl
/path/jni/cube.c:5:21: error: GLES/gl.h: No such file or directory // 包含 gl.h 时 glbuffer 的相同消息
这里是 cube.c 代码:
#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); }
这是非常微不足道的,还没有工作。
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)
【问题讨论】:
-
我翻阅了那本书,它让我无法使用本机代码。当我开始尝试它时,我只是查看了一些示例源代码,获取了一个示例 .mk 文件并重命名了一些东西,然后我就开始运行了。那本书是不是无缘无故地过于复杂了,还是在最近的 NDK 版本发布之前你必须这样做?
-
@Poldie,这并不复杂,它只需要双重修订。此外它有点过时了,所以它告诉了很多对于快速学习来说是多余的东西,尽管知道它很有用。示例可以很好地进行更改,但是当我来到 GL 时,我无法编译它。 Java 部分运行良好。
标签: android c opengl-es compilation android-ndk