opengles2 glGenVertexArrays ... glGenVertexArraysOES

时间:2015-08-17 07:29:31

标签: android c android-ndk opengl-es-2.0 ndk-build

我在解决这个问题时遇到了一些麻烦。我在mac os x 10.9上使用cmake构建我的SDL opengl应用程序它可以正常使用这个包含头文件

#if defined(__IPHONE__) || defined(__ANDROID__)
    #include "SDL_opengles2.h"
    #include "SDL_opengles2_gl2.h"
    #include "SDL_opengles2_gl2ext.h"
#elif defined(__APPLE__)
#include <OpenGL/gl3.h>
#include <SDL2/SDL_opengl.h>
#endif

尝试使用ndk-build

进行构建时出现此错误
jni/src/mandelbrot.c:100:5: warning: implicit declaration of function 'glGenVertexArrays' [-Wimplicit-function-declaration]
     glGenVertexArrays(1, &vao);
     ^
jni/src/mandelbrot.c:106:5: warning: implicit declaration of function 'glBindVertexArray' [-Wimplicit-function-declaration]
     glBindVertexArray(vao); //bind vertex array buffer

我被告知在android openles2上它是一个扩展名according to official opengl documentation

你像这样使用它:glGenVertexArraysOES(...)产生与上面相同的错误,除非它隐含声明函数glGenVertexArraysOES。

完整的android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_CFLAGS += -std=c99

LOCAL_MODULE := main

SDL_PATH := ../SDL
SDL_IMG_PATH := ../SDL2_image

LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SDL_IMG_PATH)/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SDL_IMG_PATH)/external/jpeg-9/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SDL_IMG_PATH)/external/libpng-1.6.2/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SDL_IMG_PATH)/external/libwebp-0.3.0/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/utils/time_utils/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/utils/resource_utils/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/ren_opengl/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/core_math/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/core_math/commons_math/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/core_math/mat4_scalar/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/core_math/vec3_scalar/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/components/renderable2d/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/core_engine/

# Add your application source files here...
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
                utils/time_utils/time_utils.c \
                utils/resource_utils/resource_utils.c \
                ren_opengl/ren_opengl.c \
                core_math/core_math.c \
                core_math/mat4_scalar/mat4_scalar.c \
                core_math/vec3_scalar/vec3_scalar.c \
                components/renderable2d/renderable2d.c \
                core_engine/core_engine.c \
                mandelbrot.c


LOCAL_SHARED_LIBRARIES := SDL2 SDL2_image

LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog

include $(BUILD_SHARED_LIBRARY)

手动删除对opengl1的引用不会影响构建的结果。

根据@Michaels回复进行修改 这样做:

PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOES;
glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress ( "glGenVertexArraysOES" );

我收到以下错误消息:

Brother:android-project blubee$ ndk-build
Android NDK: WARNING: APP_PLATFORM android-21 is larger than android:minSdkVersion 10 in ./AndroidManifest.xml    
[armeabi] Install        : libSDL2.so => libs/armeabi/libSDL2.so
[armeabi] Install        : libSDL2_image.so => libs/armeabi/libSDL2_image.so
[armeabi] Compile thumb  : main <= mandelbrot.c
jni/src/mandelbrot.c:35:1: warning: data definition has no type or storage class [enabled by default]
 glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress ( "glGenVertexArraysOES" );
 ^
jni/src/mandelbrot.c:35:1: warning: type defaults to 'int' in declaration of 'glGenVertexArraysOES' [enabled by default]
jni/src/mandelbrot.c:35:1: error: conflicting types for 'glGenVertexArraysOES'
jni/src/mandelbrot.c:34:29: note: previous declaration of 'glGenVertexArraysOES' was here
 PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOES;
                             ^
jni/src/mandelbrot.c:35:1: warning: implicit declaration of function 'eglGetProcAddress' [-Wimplicit-function-declaration]
 glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress ( "glGenVertexArraysOES" );

如果我将名称完全更改为OES1之类的内容,那么该错误就会消失,但我会收到这些错误。

jni/src/mandelbrot.c:54: error: undefined reference to 'eglGetProcAddress'
jni/src/mandelbrot.c:55: error: undefined reference to 'eglGetProcAddress'
jni/src/mandelbrot.c:56: error: undefined reference to 'eglGetProcAddress'
jni/src/mandelbrot.c:57: error: undefined reference to 'eglGetProcAddress'
     ^
    jni/src/mandelbrot.c:35:24: warning: initialization makes integer from pointer without a cast [enabled by default]
     glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress ( "glGenVertexArraysOES" );
                            ^
    jni/src/mandelbrot.c:35:1: error: initializer element is not constant
     glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress ( "glGenVertexArraysOES" );
     ^
    jni/src/mandelbrot.c: In function 'initialized':
    jni/src/mandelbrot.c:102:5: warning: implicit declaration of function 'glGenVertexArrays' [-Wimplicit-function-declaration]
         glGenVertexArrays(1, &vao);
         ^
    jni/src/mandelbrot.c:108:5: warning: implicit declaration of function 'glBindVertexArray' [-Wimplicit-function-declaration]
         glBindVertexArray(vao); //bind vertex array buffer
         ^
    make: *** [obj/local/armeabi/objs/main/mandelbrot.o] Error 1

1 个答案:

答案 0 :(得分:0)

使用dlopen而不是eglGetProcAddress检查此答案:https://stackoverflow.com/a/24878621/1762681

另外,检查标题。除了gl.h和glext.h中定义的定义之外,SDL头可以包括定义。它们是否包括EGL / egl.h和EGL / eglext.h?