1.首先安装android studio。
2.新建项目->选择native c++ ->finish
3.项目加载完成后,先运行下看默认native代码是否生效。
4.查看目录结构,在src/main/cpp 下有CMakeList.txt文件,默认代码为这样:
cmake_minimum_required(VERSION 3.18.1)
project("testndk")
add_library( # Sets the name of the library.
testndk
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp
)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
target_link_libraries( # Specifies the target library.
testndk
# Links the target library to the log library
# included in the NDK.
${log-lib})
5.增加OpenGL相关的库依赖。在CMakeList.txt中的target_link_libraries模块中加入: EGL,GLESv3,android。或者直接粘下面的。
cmake_minimum_required(VERSION 3.18.1)
project("testndk")
add_library( # Sets the name of the library.
testndk
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp//默认生成的cpp
)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
target_link_libraries( # Specifies the target library.
testndk //你自己起的名字
EGL
GLESv3
android
# Links the target library to the log library
# included in the NDK.
${log-lib})
6.编译项目,编译完后在默认的cpp里尝试引入openGL相关的库,如果有提示的话,那就证明成功喽。
#include <GLES3/gl3.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
如果一切顺利的话,你就可以开始android - openGL之路啦。
|