How to use GLM in Android NDK Application

时光总嘲笑我的痴心妄想 提交于 2019-12-03 03:38:23

Sam Hocevar's answer to codemonkeys problem is correct. it's not glm that's the problem. It's the "limits" header file used by glm that's the problem.

If Sam's answer does not solve your problem, try changing the toolchain to an earlier version by adding the following to your Application.mk file:

NDK_TOOLCHAIN_VERSION=4.4.3

And make sure that the STL includes for your project in Eclipse correspond with the toolchain. Go to project->properties->C/C++ General->Paths and Symbols

make sure the following directories are included:

EDIT : these are only examples; make sure you use the correct platform and abi

/Path/To/NDK/sources/platforms/android-9/arch-arm/usr/include
/Path/To/NDK/sources/cxx-stl/gnu-libstdc++/4.4.3/include
/Path/To/NDK/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi-v7a/include

EDIT : remark on first directory removed; seems glm looks for the limits file provided by the current stl implementation

Follow this solution if you are using Android Studio.

First, download OpenGL Mathematics library here

Second, extract and copy folder "../glm/glm" to your project location at "../app/src/main/cpp"

Third, on CMakeList.txt, add the following:

# Import the CMakeLists.txt for the glm library
add_subdirectory(glm) # if your CMakeLists is at '../cpp'
# add_subdirectory(src/main/cpp/glm) # if your CMakeLists is at '../app'

# add lib dependencies
target_link_libraries(
# Specifies the target library.
native-lib
# Links the target library to the log library included in the NDK.
GLESv2
glm)

Fourth, on 'buidl.griddle' (Mobile App), make sure you have right path to your CMakeList

 externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
 }

Fifth, include glm headers to your source file:

// open GL libs
#include <GLES2/gl2.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/closest_point.hpp>

Sample is available at android-ndk, see Android Endless Tunnel Game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!