On Mac OS X, the Leap Motion C++ API is provided in the dynamic library, libLeap.dylib. It is simplest to run the Visual C++ compiler from the Visual Studio command prompt. This section illustrates how to create a project from scratch.
. (for window management and user interactions). You need Freeglut to run many OpenGL samples. I also recommend you use Freeglut to write your own OpenGL programs. To compile Freeglut, you also need to install. (for OpenGL extension management). You need this library to build OpenGL programs on Windows.
On Linux and Mac, it'll be different libraries. (for math functions). You need this library for transformations, view, and projections. (for loading images).
(for loading 3D models). You need Assimp to load complicated 3D models into your program. To compile Assimp, you also need to install. When you install Visual Studio 2015, use Custom installation and make sure you select ' Visual C' and ' Common Tools for Visual C 2015'.
Don't use 'Typical' installation. The reason is that if you choose 'Typical', then you can't use Visual Studio to develop in C. A C compiler is needed to compile OpenGL, Freeglut, Glew, and other related libraries. For more information, please read this. If you have already installed Visual Studio 2015 using the 'Typical' option, install it again, choose the 'Repair' option, and add Visual C. You can also download Visual Studio Community for free, but also make sure you install Visual C. Older versions of Visual Studio install Visual C by default.
Visual Studio 2017. In Visual Studio, create a Visual C 'Win32 Console Application'. In the 'Win32 Application Wizard', under 'Application Settings', check 'Empty project'. (The default is 'Precompiled header'. You don't need it.).
After the project is created, select Tools - NuGet Package Manager - Package Manager Console. In the Package Manager Console, type 'install-package nupengl.core'. The NupenGL Core package will be installed for your project. Note that you must create an empty project before installing NupenGL. NupenGL package will install Freeglut and Glew. Drag and drop a sample program to the 'Source Files' folder of the Visual Studio project. Build and run the project.
Download the latest version of and unzip it. Install if you don't already have it. You need to use CMake to generate Visual Studio project files for freeglut. Follow the instructions laid out in 'xxxx freeglut-3.0.0 README.cmake' to build Visual Studio project files.
The following is a short description of that process. Start CMake GUI. In 'Where is the source code' field, select the folder where you unzip the freeglut package (see figure below). In 'Where to build the binaries' field, choose a folder where you want the binary files (e.g. Freeglutd.lib and freeglutd.dll) to be.
For example, I use 'xxxx freeglut-3.0.0 build'. Press Configure, and then select a C compiler (e.g. Visual Studio 2015). If you get an error message saying that a C compiler cannot be found, the most likely reason is that you have not installed Visual C.
For Visual Studio 2015, you need to explicitly select Visual C for installation. See the previous section 'Notes on Visual Studio 2015' for more details. If 'Configure' is successful, press 'Generate' to generate Visual Studio project files. CMake interface for building Freeglut. Go to the folder that you selected for 'Where to build the binaries' in CMake GUI (e.g. 'xxxx freeglut-3.0.0 build') and you will find freeglut.sln, a Visual Studio solution file.
Open the file with Visual Studio. You will find many projects in the 'Solution Explorer' window. You don't need to build them all. Just building the 'freeglut' project is good enough. After building the project(s), go to folder 'xxxx freeglut-3.0.0 build bin Debug' and you will find freeglutd.dll.
(The file names end with 'd' because it's debug build. If you choose release build, then there is no 'd' at the end.). Copy freeglutd.dll to 'c: windows system32” (32 bit OS) or “c: windows sysWOW64” (64 bit OS). Go to folder 'xxxx freeglut-3.0.0 build lib Debug' and you will find freeglutd.lib.
(The file names end with 'd' because it's debug build. If you choose release buidl, then there is no 'd' at the end.). Copy freeglutd.lib (Object File Library) to Visual C's lib directory. (It's usually ' C: Program Files (x86) Microsoft Visual Studio 14.0 VC lib'. ). Keep note of the exact file name. You'll need it later.
Go to folder 'freeglut-3.0.0 include GL' and copy freeglut.h, freeglutext.h, and freeglutstd.h to Visual C's 'include GL' folder (usually 'C: Program Files (x86) Microsoft Visual Studio 14.0 VC include GL'). If the 'GL' sub-folder doesn't exist, create it. There are other README files under 'xxxx freeglut-3.0.0' that explain how to build freeglut with other tools. How to build Glew?. Download the source code of GLEW from and unzip it.
I recommend that you compile from the source code. The binary files may be outdated. Build GLEW using the project files at 'xxxx glew-2.0.0 build vc12'. If you use Visual Studio 2015, the program will ask you to upgrade the project files.
Copy glew32d.lib under 'xxxx glew-2.0.0 lib Debug Win32' to Visual C's lib directory (usually ' C: Program Files (x86) Microsoft Visual Studio 14.0 VC lib' ). Keep note of the exact file name. You'll need it later.
Copy glew32d.dll under 'xxxx glew-2.0.0 bin Debug Win32' to 'c: windows system32” (32 bit OS) or “c: windows sysWOW64” (64 bit OS). Copy glew.h and wglew.h from ' xxxx glew-2.0.0 include GL' to Visual C's include directory (usually ' C: Program Files (x86) Microsoft Visual Studio 14.0 VC include GL'). If the 'GL' sub-folder doesn't exist, create it. Please note that the information at is a little outdated. Follow the above steps instead. I've attached an at the bottom of this page. In this file, I've replaced glGetString(GLEXTENSIONS) with a new function that uses glGetStringi(GLEXTENSIONS, i).
You should replace the SOIL.c file in the folder 'Simple OpenGL Image Library src' with this one. Go to 'Simple OpenGL Image Library projects VC9' folder and open the SOIL project solution file with Visual Studio. Build the project, and if successful, you'll find SOIL.lib under 'Simple OpenGL Image Library projects VC9 Debug'.
Copy SOIL.lib to VC/lib. Add the folder 'Simple OpenGL Image Library src' to your Visual Studio project. See Figure 2. This will help Visual Studio find SOIL.h. Remember to add SOIL.lib to the 'Additional Dependencies' list in Visual Studio project's Linker - Input page. See Figure 6. How to build Assimp?
Build Assimp source files. Here is the for building Assimp with Cmake.
The following are more detailed steps. Download Assimp from (choose source code). Download and install it, if you haven't done so. Start Cmake-gui,. Set 'Where is the source code' to the assimp-xxx (xxx is the current version number) folder (not assimp-xxx/code). Set 'Where to build the binaries' to the 'build' folder of your choice.
Press the Configure button and select the generator for this project. Select the appropriate compiler. Usually it's Visual Studio. Make sure you choose the Visual Studio version that matches the one installed on your computer. If you choose the 64-bit compiler to build Assimp, then you need to consistently use the 64-bit compiler to build your own program and all the libraries (e.g. Freeglut, Glew, SOIL, etc.).
On many computers, the default Visual Studio compiler is the 32-bit one. My suggestion is to use the default (32-bit) compiler to build everything. Press Finish. Cmake will parse the cmake configuration files under the assimp-xxx folder. Usually there is one cmake file under each source code folder. Use CMake to create Visual Studio project files for ASSIMP.
If you don't get any error message, ignore this. In case you get an error message complaining about not being able to find DirectX. The reason is that Assimp tools and Assimp test packages both require DirectX. But the main Assimp library does not need DirectX. So you can avoid the error message by not building Assimp tools and Assimp test. To do this, open the CMakeLists file under the the assimp-xxx folder and make the following changes: set both ASSIMPBUILDASSIMPTOOLS and ASSIMPBUILDTESTS to OFF (highlighted in red in the figure below).
To redo Configure after you have changed the cmakelists file, select File - Delete cache, and then press Configure. ENDIF ( ASSIMPBUILDTESTS ). If Configure is successful, then press Generate to generate Visual Studio project files. Go to the assimp-xxx/build folder (or the build folder you choose) and open Assimp.sln in Visual Studio. Build Assimp in Visual Studio.
You may choose to build everything, what you really need is to build assimp. If successful, under assimp-xxx build code Debug, you'll find assimp-vc140-mt.dll and assimp-vc140-mt.lib. (Your file names may be slightly different based on your compiler.). Copy assimp-vc140-mt.dll to “c: windows sysWOW64” (64 bit OS). Copy assimp-vc140-mt.lib to Visual C's library folder VC/lib.
In Visual Studio, create a Visual C 'Win32 Console Application'. In the 'Win32 Application Wizard', under 'Application Settings', check 'Empty project'. (The default is 'Precompiled header'. You don't need it.). After the project is created, right click on the project name and select 'Properties'.
In the 'Property Pages' window, click Linker - Input, and add the following files to the 'Additional Dependencies' line: freeglutd.lib glew32d.lib SOIL.lib assimp-vc140-mt.lib. Don't just copy the file names above. Your file name may be different from this example. For example, your files may be freeglut.lib and glew32.lib. So make sure your file names are correct.
Note that since Visual Studio 2015, you no longer need to include opengl32.lib in 'Additional Dependencies'. Configure a Visual Studio project for OpenGL. If you use Assimp, glm, or SOIL in your program, you also need to add search paths to Visual Studio (VS) so that VS can find the header files from Assimp, glm, and SOIL. In the 'Property Pages' window, select 'VC Directories' and then select 'Include Directories'. Click on 'Edit', then add the following paths: 'assimp-xxx include', 'glm', 'Simple OpenGL Image Library src'.
(Note that I only give the relative path here. You'll need to add the complete path.).
For newer version of Assimp, you also need to include assimp-4.1.0/build/include. Assume your program builds successfully, and your program needs to load shader files from your disk.
When you run the program from within Visual Studio (VS), VS will look for these files in the 'Working Directory'. To find the 'Working Directory', open Project Properties, select 'Debugging' - 'Working Directory', you'll find the macro $(ProjectDir).
Click on the down arrow icon on the right hand side of this text box, and select, the 'Working Directory' window will pop up. Click on the button 'Macros', and scroll down to find the full path for the macro $(ProjectDir). By default, the 'Working Directory' is the macro $(ProjectDir), which is the folder in which your VS project file resides. Solution #1: Set all file paths relative to the 'Working Directory'. This is the recommended practice. Solution #2: Copy all the external files into the 'Working Directory'.
The code will be simpler - you just need to specify the file name, without having to worry about setting the correct file path. But all the external files are placed in one directory, along with the VS project files. It's not well organized. Solution #3: Specify full path for all the external files in your program. You don't need to know where the 'Working Directory' is.
But this is the least flexible solution. If you share the program with others, then they'll need to reset the path. If you move your project to another folder or reset your folder name, you'll need to reset the path. For example, on my computer there is a sample program whose VS project file 'sample.vcxproj' is at 'D: Work Teaching Courses 2014 CSC4820-6820 Homework Homework1 sample sample'. When I create this project in VS, VS automatically sets $(ProjectDir) to this folder.
This is the 'Working Directory' for this project. In the following code sample, the program tries to load two external files (e.g. Shader files) with no path specified, VS will look for them in the 'Working Directory' ( 'D: Work Teaching Courses 2014 CSC4820-6820 Homework Homework1 sample sample'). Download the source code from by pressing the button 'Clone or download'. Unzip the files.
Install and open. In CMake GUI, specify 'Where is the source code', which is the folder where you unzipped the OpenGL sample programs.
Also specify 'Where to build the binaries', which is usually a new folder called 'build'. Press the 'Configure' button, wait for it to finish, and then press the 'Generate' button.
After 'Generate' is finished, the Visual Studio projects will be generated and stored in the 'build' folder you specified earlier. When you 'Configure' for the first time, CMake may ask you to identify a compiler.
You need to find and select the proper Visual C/C compiler file in CMake. If you have installed a new version of Visual Studio after you installed the CMake, you may want to install CMake again so the new Visual Studio is identified. Or you can manually add the C/C compiler in CMake.