我刚刚开始在 android 上学习 OpenGL ES(使用这本书 https://rads.stackoverflow.com/amzn/click/com/1430226471)并遇到了采用的问题source http://apress.com/book/view/9781430226475从第 5 章中的代码到在 android 中使用 jni 的现有方法(实际上,它还涉及简单地运行本机 GL 应用程序)。我正在尝试编译本机代码以获取 .so lib 并在 .apk 存档中进一步使用它。但如果某些库不存在(GLES/gl.h、EGL/egl.h、GLES/gl.h、GLES/glext.h),则无法进行编译。
所以问题是如何安装这些库(AFAIU、OpenGL ES 和 EGL 安装)并编译最简单的本机代码? (教程受到高度赞赏)。
提前致谢。
编辑:我已经尝试过glbuffer https://github.com/richq/glbuffer按照建议的示例(稍微更改了 .mk 文件),但仍然没有成功。编译器给出的结果与以前相同:
ndk构建
编译拇指:egl
/path/jni/cube.c:5:21: 错误: GLES/gl.h: 没有这样的文件或目录 // 当包含 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)