How To Install Glm For Mac

Download this app from Microsoft Store for Windows 10 Mobile, Windows Phone 8.1, Windows Phone 8. See screenshots, read the latest customer reviews, and compare ratings for GLM System. OpenGL Mathematics GLSL + Optional features = OpenGL Mathematics (GLM) A C mathematics library for graphics programming OpenGL Mathematics (GLM) is a header only C mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications. GLM software is being updated to be compatible with Mac OS X Catalina (10.15). The work is progressing well. Initially, the software becomes available as a Beta for end-customer evaluation.

In this chapter we'll set up your environment for developing Vulkan applicationsand install some useful libraries. All of the tools we'll use, with theexception of the compiler, are compatible with Windows, Linux and MacOS, but thesteps for installing them differ a bit, which is why they're describedseparately here.

Windows

If you're developing for Windows, then I will assume that you are using VisualStudio to compile your code. For complete C++17 support, you need to use eitherVisual Studio 2017 or 2019. The steps outlined below were written for VS 2017.

Vulkan SDK

The most important component you'll need for developing Vulkan applications isthe SDK. It includes the headers, standard validation layers, debugging toolsand a loader for the Vulkan functions. The loader looks up the functions in thedriver at runtime, similarly to GLEW for OpenGL - if you're familiar with that.

How To Install Glm For Macbook Pro

The SDK can be downloaded from the LunarG websiteusing the buttons at the bottom of the page. You don't have to create anaccount, but it will give you access to some additional documentation that maybe useful to you.

Proceed through the installation and pay attention to the install location ofthe SDK. The first thing we'll do is verify that your graphics card and driverproperly support Vulkan. Go to the directory where you installed the SDK, openthe Bin directory and run the vkcube.exe demo. You should see the following:

If you receive an error message then ensure that your drivers are up-to-date,include the Vulkan runtime and that your graphics card is supported. See theintroduction chapter for links to drivers from the majorvendors.

There is another program in this directory that will be useful for development. The glslangValidator.exe and glslc.exe programs will be used to compile shaders from thehuman-readable GLSL tobytecode. We'll cover this in depth in the shader moduleschapter. The Bin directory also contains the binaries of the Vulkan loaderand the validation layers, while the Lib directory contains the libraries.

Lastly, there's the Include directory that contains the Vulkan headers. Feel free to explore the other files, but we won't need them for this tutorial.

GLFW

As mentioned before, Vulkan by itself is a platform agnostic API and does notinclude tools for creating a window to display the rendered results. To benefitfrom the cross-platform advantages of Vulkan and to avoid the horrors of Win32,we'll use the GLFW library to create a window, whichsupports Windows, Linux and MacOS. There are other libraries available for thispurpose, like SDL, but the advantage of GLFW is thatit also abstracts away some of the other platform-specific things in Vulkanbesides just window creation.

You can find the latest release of GLFW on the official website.In this tutorial we'll be using the 64-bit binaries, but you can of course alsochoose to build in 32 bit mode. In that case make sure to link with the VulkanSDK binaries in the Lib32 directory instead of Lib. After downloading it, extract the archiveto a convenient location. I've chosen to create a Libraries directory in theVisual Studio directory under documents.

GLM

Unlike DirectX 12, Vulkan does not include a library for linear algebraoperations, so we'll have to download one. GLM is anice library that is designed for use with graphics APIs and is also commonlyused with OpenGL.

GLM is a header-only library, so just download the latest versionand store it in a convenient location. You should have a directory structuresimilar to the following now:

Setting up Visual Studio

Now that you've installed all of the dependencies we can set up a basic VisualStudio project for Vulkan and write a little bit of code to make sure thateverything works.

Start Visual Studio and create a new Windows Desktop Wizard project by entering a name and pressing OK.

Make sure that Console Application (.exe) is selected as application type so that we have a place to print debug messages to, and check Empty Project to prevent Visual Studio from adding boilerplate code.

Press OK to create the project and add a C++ source file. You shouldalready know how to do that, but the steps are included here for completeness.

Now add the following code to the file. Don't worry about trying tounderstand it right now; we're just making sure that you can compile and runVulkan applications. We'll start from scratch in the next chapter.

Let's now configure the project to get rid of the errors. Open the projectproperties dialog and ensure that All Configurations is selected, because mostof the settings apply to both Debug and Release mode.

Go to C++ -> General -> Additional Include Directories and press <Edit...>in the dropdown box.

Add the header directories for Vulkan, GLFW and GLM:

Next, open the editor for library directories under Linker -> General:

And add the locations of the object files for Vulkan and GLFW:

Go to Linker -> Input and press <Edit...> in the Additional Dependenciesdropdown box.

Enter the names of the Vulkan and GLFW object files:

And finally change the compiler to support C++17 features:

You can now close the project properties dialog. If you did everything rightthen you should no longer see any more errors being highlighted in the code.

Finally, ensure that you are actually compiling in 64 bit mode:

Press F5 to compile and run the project and you should see a command promptand a window pop up like this:

The number of extensions should be non-zero. Congratulations, you're all set forplaying with Vulkan!

Linux

These instructions will be aimed at Ubuntu users, but you may be able to followalong by changing the apt commands to the package manager commands that are appropriate for you. You should have a compiler that supports C++17 (GCC 7+ or Clang 5+). You'll also need make.

Vulkan Packages

The most important components you'll need for developing Vulkan applications on Linux are the Vulkan loader, validation layers, and a couple of command-line utilities to test whether your machine is Vulkan-capable:

  • sudo apt install vulkan-tools: Command-line utilities, most importantly vulkaninfo and vkcube. Run these to confirm your machine supports Vulkan.
  • sudo apt install libvulkan-dev: Installs Vulkan loader. The loader looks up the functions in the driver at runtime, similarly to GLEW for OpenGL - if you're familiar with that.
  • sudo apt install vulkan-validationlayers-dev spirv-tools: Installs the standard validation layers and required SPIR-V tools. These are crucial when debugging Vulkan applications, and we'll discuss them in the upcoming chapter.

If installation was successful, you should be all set with the Vulkan portion. Remember to runvkcube and ensure you see the following pop up in a window:

If you receive an error message then ensure that your drivers are up-to-date,include the Vulkan runtime and that your graphics card is supported. See theintroduction chapter for links to drivers from the majorvendors.

GLFW

As mentioned before, Vulkan by itself is a platform agnostic API and does notinclude tools for creation a window to display the rendered results. To benefitfrom the cross-platform advantages of Vulkan and to avoid the horrors of X11,we'll use the GLFW library to create a window, whichsupports Windows, Linux and MacOS. There are other libraries available for thispurpose, like SDL, but the advantage of GLFW is thatit also abstracts away some of the other platform-specific things in Vulkanbesides just window creation.

We'll be installing GLFW from the following command:

GLM

Unlike DirectX 12, Vulkan does not include a library for linear algebraoperations, so we'll have to download one. GLM is anice library that is designed for use with graphics APIs and is also commonlyused with OpenGL.

It is a header-only library that can be installed from the libglm-dev package:

Shader Compiler

We have just about all we need, except we'll want a program to compile shaders from the human-readable GLSL to bytecode.

Two popular shader compilers are Khronos Group's glslangValidator and Google's glslc. The latter has a familiar GCC- and Clang-like usage, so we'll go with that: download Google's unofficial binaries and copy glslc to your /usr/local/bin. Note you may need to sudo depending on your permissions. To test, run glslc and it should rightfully complain we didn't pass any shaders to compile:

glslc: error: no input files

We'll cover glslc in depth in the shader modules chapter.

Setting up a makefile project

Now that you have installed all of the dependencies, we can set up a basicmakefile project for Vulkan and write a little bit of code to make sure thateverything works.

Create a new directory at a convenient location with a name like VulkanTest.Create a source file called main.cpp and insert the following code. Don'tworry about trying to understand it right now; we're just making sure that youcan compile and run Vulkan applications. We'll start from scratch in the nextchapter.

How

Next, we'll write a makefile to compile and run this basic Vulkan code. Create anew empty file called Makefile. I will assume that you already have some basicexperience with makefiles, like how variables and rules work. If not, you canget up to speed very quickly with this tutorial.

We'll first define a couple of variables to simplify the remainder of the file.Define a CFLAGS variable that will specify the basic compiler flags:

We're going to use modern C++ (-std=c++17), and we'll set optimization level to O2. We can remove -O2 to compile programs faster, but we should remember to place it back for release builds.

Similarly, define the linker flags in a LDFLAGS variable:

The flag -lglfw is for GLFW, -lvulkan links with the Vulkan function loader and the remaining flags are low-level system libraries that GLFW needs. The remaining flags are dependencies of GLFW itself: the threading and window management.

Specifying the rule to compile VulkanTest is straightforward now. Make sure touse tabs for indentation instead of spaces.

Verify that this rule works by saving the makefile and running make in thedirectory with main.cpp and Makefile. This should result in a VulkanTestexecutable.

We'll now define two more rules, test and clean, where the former willrun the executable and the latter will remove a built executable:

Glm

Running make test should show the program running successfully, and displaying the number of Vulkan extensions. The application should exit with the success return code (0) when you close the empty window. You should now have a complete makefile that resembles the following:

You can now use this directory as a template for your Vulkan projects. Make a copy, rename it to something like HelloTriangle and remove all of the code in main.cpp.

You are now all set for the real adventure.

MacOS

These instructions will assume you are using Xcode and the Homebrew package manager. Also, keep in mind that you will need at least MacOS version 10.11, and your device needs to support the Metal API.

Vulkan SDK

The most important component you'll need for developing Vulkan applications is the SDK. It includes the headers, standard validation layers, debugging tools and a loader for the Vulkan functions. The loader looks up the functions in the driver at runtime, similarly to GLEW for OpenGL - if you're familiar with that.

The SDK can be downloaded from the LunarG website using the buttons at the bottom of the page. You don't have to create an account, but it will give you access to some additional documentation that may be useful to you.

The SDK version for MacOS internally uses MoltenVK. There is no native support for Vulkan on MacOS, so what MoltenVK does is actually act as a layer that translates Vulkan API calls to Apple's Metal graphics framework. With this you can take advantage of debugging and performance benefits of Apple's Metal framework.

After downloading it, simply extract the contents to a folder of your choice (keep in mind you will need to reference it when creating your projects on Xcode). Inside the extracted folder, in the Applications folder you should have some executable files that will run a few demos using the SDK. Run the vkcube executable and you will see the following:

GLFW

For

As mentioned before, Vulkan by itself is a platform agnostic API and does not include tools for creation a window to display the rendered results. We'll use the GLFW library to create a window, which supports Windows, Linux and MacOS. There are other libraries available for this purpose, like SDL, but the advantage of GLFW is that it also abstracts away some of the other platform-specific things in Vulkan besides just window creation.

To install GLFW on MacOS we will use the Homebrew package manager to get the glfw package:

GLM

Vulkan does not include a library for linear algebra operations, so we'll have to download one. GLM is a nice library that is designed for use with graphics APIs and is also commonly used with OpenGL.

It is a header-only library that can be installed from the glm package:

Setting up Xcode

Now that all the dependencies are installed we can set up a basic Xcode project for Vulkan. Most of the instructions here are essentially a lot of 'plumbing' so we can get all the dependencies linked to the project. Also, keep in mind that during the following instructions whenever we mention the folder vulkansdk we are refering to the folder where you extracted the Vulkan SDK.

Start Xcode and create a new Xcode project. On the window that will open select Application > Command Line Tool.

Select Next, write a name for the project and for Language select C++.

Press Next and the project should have been created. Now, let's change the code in the generated main.cpp file to the following code:

Keep in mind you are not required to understand all this code is doing yet, we are just setting up some API calls to make sure everything is working.

Xcode should already be showing some errors such as libraries it cannot find. We will now start configuring the project to get rid of those errors. On the Project Navigator panel select your project. Open the Build Settings tab and then:

  • Find the Header Search Paths field and add a link to /usr/local/include (this is where Homebrew installs headers, so the glm and glfw3 header files should be there) and a link to vulkansdk/macOS/include for the Vulkan headers.
  • Find the Library Search Paths field and add a link to /usr/local/lib (again, this is where Homebrew installs libraries, so the glm and glfw3 lib files should be there) and a link to vulkansdk/macOS/lib.

It should look like so (obviously, paths will be different depending on where you placed on your files):

Now, in the Build Phases tab, on Link Binary With Libraries we will add both the glfw3 and the vulkan frameworks. To make things easier we will be adding the dynamic libraries in the project (you can check the documentation of these libraries if you want to use the static frameworks).

  • For glfw open the folder /usr/local/lib and there you will find a file name like libglfw.3.x.dylib ('x' is the library's version number, it might be different depending on when you downloaded the package from Homebrew). Simply drag that file to the Linked Frameworks and Libraries tab on Xcode.
  • For vulkan, go to vulkansdk/macOS/lib. Do the same for the file both files libvulkan.1.dylib and libvulkan.1.x.xx.dylib (where 'x' will be the version number of the the SDK you downloaded).

After adding those libraries, in the same tab on Copy Files change Destination to 'Frameworks', clear the subpath and deselect 'Copy only when installing'. Click on the '+' sign and add all those three frameworks here aswell.

Your Xcode configuration should look like:

The last thing you need to setup are a couple of environment variables. On Xcode toolbar go to Product > Scheme > Edit Scheme..., and in the Arguments tab add the two following environment variables:

  • VK_ICD_FILENAMES = vulkansdk/macOS/share/vulkan/icd.d/MoltenVK_icd.json
  • VK_LAYER_PATH = vulkansdk/macOS/share/vulkan/explicit_layer.d

It should look like so:

Finally, you should be all set! Now if you run the project (remembering to setting the build configuration to Debug or Release depending on the configuration you chose) you should see the following:

The number of extensions should be non-zero. The other logs are from the libraries, you might get different messages from those depending on your configuration.

You are now all set for the real thing.

Please enable JavaScript to view the comments powered by Disqus.

I decided to create this tutorial about CMake and OpenGL since I couldn’t find many articles about this specific topic on the Internet. Most CMake tutorials focus on the very basic usage - one file main.cpp and then create project with one CMake function add_executable and that’s it. That was not enough for me since setting up an OpenGL project is quite cumbersome and requires some additional libraries to configure.

Therefore, I’ve dived into this topic and with some luck I was able to create working CMake script, that will build a project for IDE of my choice, which in my case is Visual Studio Community.

I would like to state I’m not a CMake expert, so any improvements/comments/etc. to this tutorial and the CMake code are greatly welcome.

Prerequisites

First of all, we have to have CMake installed and added to the system PATH variable. You can download CMake here.

Secondly, we need some project files that we can work with. For this purpose, I’ve prepared a small package with basic OpenGL project that opens a window and renders an object. You can download this sample project here.

What is more, this project contains the following dependencies:

  • GLAD
  • GLFW3
  • GLM
  • stb_image

The one dependency that is missing is Assimp library (responsible for loading 3D models). It was left on purpose - we will learn how to use CMake by building Assimp ourselves.

First step: using CMake

Download sources

To be able to load 3D models with the pre-made project we need Assimp library. Authors of this library don’t distribute binary files. Therefore, we have to build it from given source files. You can download Assimp’s source files from the original page. Then just simply click the Download button, and you will be redirected to their download page. Then, go ahead and download Source code (zip).

At the time, when this article was written, the newest version of Assimp was 4.1.0.

Building Assimp

When we have downloaded the source files, we can extract them. Now, in the location where the extracted files are, create new folder and call it build. This folder will contain the CMake generated Visual Studio files.

To create Visual Studio solution files using CMake, we have to options:

  1. use command line
  2. use CMake GUI

Here, I will show how to use both approaches.

Using command line

Simply open command line tool inside the newly created build directory and type:

And that’s it. Generated Visual Studio solution files should be inside the build folder.

Using CMake GUI

Run CMake-gui application. You should see a window similar to this one:

Then fill two boxes with proper paths:

  • Where is the source code
  • Where to build the binaries

I think that these boxes are self-explanatory. Then, you should have something like this:

Now click on the Configure button and select the generator for our project. In our case it is Visual Studio 15 2017. Then click Finish.

When configuration step has completed, make sure that LIBRARY_SUFFIX is empty:

Now you can click on the Generate button to generate Visual Studio solution files. CMake will save them inside the build folder.

Building binaries

If you generated Visual Studio solution files using one of the above methods, go to the build folder and open Assimp.sln. Then, right click on the assimp project and select Set as StartUp project.

Now select the build configuration to Release and platform to Win32 and build the project (press F7 or choose Build->Build solution).

When everything is ok (I hope it is), you should see a message in Visual Studio console:

One more step

When you have successfully built Assimp binaries, you can do the following steps:

  1. Copy assimp.lib from build/code/Release to lib folder of our Sample project.
  2. Create dlls folder in the root directory of our Sample project.
  3. Copy assimp.dll from build/code/Release to dlls folder of our Sample project.
  4. Copy build/include/assimp folder to include folder of our Sample project.
  5. Copy include/assimp folder to include folder of our Sample project.

That’s it. We can now proceed to writing a CMake script that will build Visual Studio (or any other) solution for Simple project.

Second step: CMake script for our Simple project

Finally, we can talk something about core of this tutorial - creating a CMake script.

First of all, create file CMakeLists.txt in the root directory of Sample project. In this file we will define the build rules for our project.

Every CMake script should define the minimum required version of CMake and name of the project (and in our case also a solution name). Let’s set the minimum CMake version to 3.2 and project name to OpenGLExample.

Source files and libraries

Now we will create two CMake variables to hold *.c/*.cpp and *.h/*.hpp source files. First variable will be called SOURCE_FILES and second HEADER_FILES. To do so, we will use file command with GLOB_RECURSE parameter.

The file command can take as a first parameter a lot of options, but we will focus only on two of them:

  • GLOB - it will generate a list of files that match the globing expression, which is very similar to regular expressions.
  • GLOB_RECURSE - it works the same as the GLOB with exception that it will traverse all subdirectories of the matched directory and will match the files.

So, in our case using GLOB_RECURSE is much convenient as we store source files in different subdirectories. However, if we would like to use GLOB, we should add these subdirectories to the file command ourselves.

You can also notice the global CMAKE_SOURCE_DIR variable. This variable points to the folder where CMakeLists.txt file is located. CMake defines much more global variables which you can view here.

In the next step, we specify where linker should look for static libraries for our project. It’s done using link_directories command and passing the directory as a parameter.

Resources

Every OpenGL project needs some additional resources which hold different data - 3D models, textures, etc. According to my knowledge, CMake doesn’t have a nice and clean way to specify the resources directory. However, the best way to overcome this problem is to use configuration file. This file will moved by CMake to different folder with changed content.

Using this knowledge, we will create a configuration file, that after modified by CMake, will contain a C++ macro that will hold an absolute path to the root directory of our project (where CMakeLists.txt resides).

To do so, create helpers folder inside src folder, and then create file RootDir.h.in in the newly created folder. Then, type the following code to our configuration file.

As you can see, we referenced a CMake variable @CMAKE_SOURCE_DIR@. This variable will be modified by CMake with the absolute path, where the file CMakeLists.txt is located.

We also need to tell CMake where is our configuration file, and where CMake should put it. To do so, we call a command configure_file.

Executable

When we have our source files configured, it’s time to configure our main project that will create the executable. All we need to do is to call the following function:

It will create the project with a name that was specified using project command with source and header files saved in variables SOURCE_FILES and HEADER_FILES.

External libraries

The last big thing that we need to do, in order to complete the CMake script is to tell CMake what additional libraries are required by our project, and where these libraries can be found. All of these can be accomplished with find_package command.

This command take as a parameter a module name. Modules in CMake aid with finding various libraries and packages. CMake, by default, supports a lot of well-known libraries such as OpenGL. You can list all modules that your version of CMake supports by typing:

Unfortunately, CMake doesn’t support by default every library (that would be impossible). However, we can create our modules (or download it from the web). Fortunately, our Simple project comes with 3 modules that will allow us to find Assimp, GLM and GLFW3 libraries.

First we have to tell CMake where our modules are.

Then we can tell CMake to find desired libraries.

What about GLAD and stb_image? These libraries are header-only libraries so for them we will create separate targets (projects) in our solution.

Then, we will save all found directories into a single variable LIBS.

The last thing that we will do is to link selected libraries with our main project and define include directories, that will be used by compiler in order to search for include files.

Visual Studio filters (folders)

All of the above steps create the valid CMake script that will create a valid Visual Studio project. But to make this project look a little bit nicer in our IDE we will create a macro (and then we will run it) to put source and header files in Visual Studio filters (folders).

Auto-copy DLLs

After creating the Visual Studio solution using CMake script defined above, we will have to copy ourselves the required DLLs to correct directories. In order to omit this problem, we can define a custom command that will automatically copy the selected DLLs (or the whole folder) to the correct place. This command will be executed after the process of building the project.

Build the Sample project

In order to test our script, let’s build our Sample project. To do so, you can use command line tool or cmake-gui application. Here, I’m gonna use the command line tool.

So let’s call this set of commands in the root directory of our project.

This will create Visual Studio solution inside the build directory. Now, open OpenGLExample.sln solution and run the OpenGLExample project. You should see a window with rotating statue.

The end

If you had any troubles creating your CMakeLists.txt script you can reference the script created especially for this tutorial here.

You can also download the final Sample project with CMake script from the GitHub repository.

If you noticed any errors or typos, or something wasn’t working just let me know in the comment section down below. Also, any improvements/comments/etc. to this tutorial and the CMake code are greatly welcome.

How To Install Glm For Mac Os

Install

Source code

References

  1. CMake official documentation
  2. CMake Community Wiki