【我的OpenGL学习进阶之旅】解决NDK使用OpenGL ES 3.0 的api报错:error: undefined reference to ‘glUnmapBuffer‘

一、错误描述

今天在写一个OpenGL ES 3.0的demo的时候,编译报错,如下所示:

D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp
:162: error: undefined reference to 'glUnmapBuffer'

在这里插入图片描述

完整错误日志,如下所示:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process C:\Android\sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C D:\GitLab Source\OpenGLESDemo\app\.cxx\cmake\debug\armeabi-v7a opengles-lesson-lib}
  ninja: Entering directory `D:\GitLab Source\OpenGLESDemo\app\.cxx\cmake\debug\armeabi-v7a'
  [1/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/lesson1/Native1Lesson.cpp.o
  [2/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle.cpp.o
  [3/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle3.cpp.o
  [4/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/graphics/GLUtils.cpp.o
  [5/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle2.cpp.o
  [6/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangleMapBuffers.cpp.o
  [7/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/graphics/Matrix.cpp.o
  [8/8] Linking CXX shared library "D:\GitLab Source\OpenGLESDemo\app\build\intermediates\cmake\debug\obj\armeabi-v7a\libopengles-lesson-lib.so"
  FAILED: D:/GitLab Source/OpenGLESDemo/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libopengles-lesson-lib.so 
  cmd.exe /C "cd . && C:\Android\SDK\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi16 --gcc-toolchain=C:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -std=c++11 -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libopengles-lesson-lib.so -o "D:\GitLab Source\OpenGLESDemo\app\build\intermediates\cmake\debug\obj\armeabi-v7a\libopengles-lesson-lib.so" CMakeFiles/opengles-lesson-lib.dir/graphics/GLUtils.cpp.o CMakeFiles/opengles-lesson-lib.dir/graphics/Matrix.cpp.o CMakeFiles/opengles-lesson-lib.dir/lesson1/Native1Lesson.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle2.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle3.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangleMapBuffers.cpp.o  -lEGL -lGLESv2 -landroid -llog -latomic -lm && cd ."
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:125: error: undefined reference to 'glMapBufferRange'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:138: error: undefined reference to 'glUnmapBuffer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:150: error: undefined reference to 'glMapBufferRange'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:162: error: undefined reference to 'glUnmapBuffer'
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.
  


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 11s
12 actionable tasks: 7 executed, 5 up-to-date

在这里插入图片描述

二、排查问题

我们排查上面的错误日志,发现有一条命令是

CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangleMapBuffers.cpp.o 
        -lEGL -lGLESv2 -landroid -llog -latomic -lm

咋回事,怎么是-lGLESv2

在这里插入图片描述

查看下CMakeList.txt代码,原来配置GLES版本配置成了GLESv2
在这里插入图片描述

target_link_libraries( # Specifies the target library.
        opengles-lesson-lib

        EGL
        GLESv2
        android

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})

我们将GLESv2改成GLESv3 即可。
在这里插入图片描述

target_link_libraries( # Specifies the target library.
        opengles-lesson-lib

        EGL
        GLESv3  # OpenGL ES 3.0版本
        android

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})

然后重新编译一下。

三、新问题

上面将CMakeList.txt代码,原来配置的GLESv2改成GLESv3,那么error: undefined reference to 'glUnmapBuffer'的问题不存在了。

但是产生了新的问题,如下所示:

D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp
:188: error: undefined reference to 'glDisableVertexAttribArray'

在这里插入图片描述
但是我们点开代码,进入gl3.h 可以看到有这个API的。
在这里插入图片描述

完整错误日志如下所示:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process C:\Android\sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C D:\GitLab Source\OpenGLESDemo\app\.cxx\cmake\debug\armeabi-v7a opengles-lesson-lib}
  ninja: Entering directory `D:\GitLab Source\OpenGLESDemo\app\.cxx\cmake\debug\armeabi-v7a'
  [1/1] Linking CXX shared library "D:\GitLab Source\OpenGLESDemo\app\build\intermediates\cmake\debug\obj\armeabi-v7a\libopengles-lesson-lib.so"
  FAILED: D:/GitLab Source/OpenGLESDemo/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libopengles-lesson-lib.so 
  cmd.exe /C "cd . && C:\Android\SDK\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi16 --gcc-toolchain=C:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -std=c++11 -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libopengles-lesson-lib.so -o "D:\GitLab Source\OpenGLESDemo\app\build\intermediates\cmake\debug\obj\armeabi-v7a\libopengles-lesson-lib.so" CMakeFiles/opengles-lesson-lib.dir/graphics/GLUtils.cpp.o CMakeFiles/opengles-lesson-lib.dir/graphics/Matrix.cpp.o CMakeFiles/opengles-lesson-lib.dir/lesson1/Native1Lesson.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle2.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle3.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangleMapBuffers.cpp.o  -lEGL -lGLESv3 -landroid -llog -latomic -lm && cd ."
  C:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lGLESv3
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:78: error: undefined reference to 'glCreateProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:84: error: undefined reference to 'glAttachShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:87: error: undefined reference to 'glAttachShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:90: error: undefined reference to 'glLinkProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:94: error: undefined reference to 'glGetProgramiv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:99: error: undefined reference to 'glGetProgramiv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:103: error: undefined reference to 'glGetProgramInfoLog'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:109: error: undefined reference to 'glDeleteProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:113: error: undefined reference to 'glDeleteShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:114: error: undefined reference to 'glDeleteShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:31: error: undefined reference to 'glCreateShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:37: error: undefined reference to 'glShaderSource'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:40: error: undefined reference to 'glCompileShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:43: error: undefined reference to 'glGetShaderiv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:48: error: undefined reference to 'glGetShaderiv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:53: error: undefined reference to 'glGetShaderInfoLog'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:59: error: undefined reference to 'glDeleteShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:5: error: undefined reference to 'glGetString'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:131: error: undefined reference to 'glViewport'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:147: error: undefined reference to 'glClearColor'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:148: error: undefined reference to 'glClear'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:151: error: undefined reference to 'glUseProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:154: error: undefined reference to 'glGetUniformLocation'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:155: error: undefined reference to 'glGetAttribLocation'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:156: error: undefined reference to 'glGetAttribLocation'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:10: error: undefined reference to 'glGetError'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:10: error: undefined reference to 'glGetError'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:183: error: undefined reference to 'glVertexAttribPointer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:191: error: undefined reference to 'glEnableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:193: error: undefined reference to 'glVertexAttribPointer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:201: error: undefined reference to 'glEnableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:209: error: undefined reference to 'glUniformMatrix4fv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:211: error: undefined reference to 'glDrawArrays'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:76: error: undefined reference to 'glClearColor'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:8: error: undefined reference to 'glGetString'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:84: error: undefined reference to 'glViewport'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:93: error: undefined reference to 'glClear'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:98: error: undefined reference to 'glUseProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:122: error: undefined reference to 'glVertexAttribPointer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:126: error: undefined reference to 'glEnableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:138: error: undefined reference to 'glDrawArrays'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:8: error: undefined reference to 'glGetString'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:86: error: undefined reference to 'glClearColor'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:94: error: undefined reference to 'glViewport'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:103: error: undefined reference to 'glClear'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:108: error: undefined reference to 'glUseProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:133: error: undefined reference to 'glVertexAttribPointer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:137: error: undefined reference to 'glEnableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:146: error: undefined reference to 'glVertexAttrib4fv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:160: error: undefined reference to 'glDrawArrays'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:163: error: undefined reference to 'glDisableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:8: error: undefined reference to 'glGetString'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:88: error: undefined reference to 'glClearColor'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:96: error: undefined reference to 'glViewport'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:105: error: undefined reference to 'glClear'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:110: error: undefined reference to 'glUseProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:115: error: undefined reference to 'glGenBuffers'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:117: error: undefined reference to 'glBindBuffer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:118: error: undefined reference to 'glBufferData'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:120: error: undefined reference to 'glBindBuffer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:121: error: undefined reference to 'glBufferData'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:123: error: undefined reference to 'glBindBuffer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:124: error: undefined reference to 'glBufferData'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:127: error: undefined reference to 'glBindBuffer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:137: error: undefined reference to 'glDrawElements'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:139: error: undefined reference to 'glDisableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle3.cpp:140: error: undefined reference to 'glDisableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:120: error: undefined reference to 'glGenBuffers'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:123: error: undefined reference to 'glBufferData'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:125: error: undefined reference to 'glMapBufferRange'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:138: error: undefined reference to 'glUnmapBuffer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:150: error: undefined reference to 'glMapBufferRange'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:162: error: undefined reference to 'glUnmapBuffer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:186: error: undefined reference to 'glDrawElements'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:188: error: undefined reference to 'glDisableVertexAttribArray'
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.
  


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s
15 actionable tasks: 3 executed, 12 up-to-date

四、分析新问题

查看上面的完整错误日志,使用的是GLESv3版本,但是感觉gl3.h里面的API都找不到。
在这里插入图片描述

4.1 分析AndroidManifest.xml中声明了OpenGL ES版本

AndroidManifest.xml中声明了OpenGL ES版本,如下所示,应该是没问题的

在这里插入图片描述

 <uses-feature android:glEsVersion="0x00030002"
        android:required="true" />

4.2 查看CMakeList.txt中的OpenGL ES的库

前面的那个问题,我们修复了OpenGL ES的库版本为GLESv3,并且错误日志也显示使用了这个版本,所以应该也不是这里的问题
在这里插入图片描述

4.3 查看 build.gradle 里面的 minSdkVersion

查看官网 https://developer.android.com/guide/topics/graphics/opengl,有如下所示的介绍:

在这里插入图片描述

Android 可通过开放图形库 (OpenGL®)(特别是 OpenGL ES API)来支持高性能 2D 和 3D 图形。OpenGL 是一种跨平台的图形 API,用于为 3D 图形处理硬件指定标准的软件接口。OpenGL ES 是 OpenGL 规范的一种形式,适用于嵌入式设备。Android 支持多版 OpenGL ES API:

  • OpenGL ES 1.0 和 1.1 - 此 API 规范受 Android 1.0 及更高版本的支持。
  • OpenGL ES 2.0 - 此 API 规范受 Android 2.2(API 级别 8)及更高版本的支持。
  • OpenGL ES 3.0 - 此 API 规范受 Android 4.3(API 级别 18)及更高版本的支持。
  • OpenGL ES 3.1 - 此 API 规范受 Android 5.0(API 级别 21)及更高版本的支持。

注意:要使设备支持 OpenGL ES 3.0 API,则需要使用由设备制造商提供的此图形管道的一个实现。搭载 Android 4.3 或更低版本的设备可能不支持 OpenGL ES 3.0 API。如需了解如何检查运行时支持的 OpenGL ES 版本,请参阅检查 OpenGL ES 版本

查看项目的build.gradle文件,发现minSdkVersion 被设置为 16,不支持OpenGL ES 3.0
在这里插入图片描述

我们将minSdkVersion 设置为 18,然后重新编译。
在这里插入图片描述

好吧,重新编译正常。 运行效果如下,一个彩色的三角形。
在这里插入图片描述

五、总结

要是有OpenGL ES 3.0版本,得做如下几件事情。

  1. 在AndroidManifest.xml中声明 OpenGL ES 3.0版本。
  <uses-feature android:glEsVersion="0x00030002"
        android:required="true" />
  1. build.gradle中minSdkVersion得声明为18以上。
  2. CMakeLists.txt里面的target_link_libraries,得添加GLESv3库,不要写成GLESv2库了。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

字节卷动

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值