How to use GLM in Android NDK Application

前端 未结 2 1362
渐次进展
渐次进展 2021-02-06 12:30

I am currently trying to port my OpenGL application to Android and am stuck on how to import and build GLM http://glm.g-truc.net/ properly. I have no trouble using GLM in standa

相关标签:
2条回答
  • 2021-02-06 12:46

    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

    0 讨论(0)
  • 2021-02-06 13:02

    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

    0 讨论(0)
提交回复
热议问题