How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio
This guide will help you get over the first challenge of using OpenGL, GLFW, GLEW, and GLM: Installing and setting them up, and creating your first project with GLFW-GLEW-GLM Template in Visual Studio 2019. It will assume your platform is...
Method 1 of 7:
Downloading GLFW, GLEW, and GLM
- Create folder GL. In directory (disk) C: right click > select New > Folder > type GL > hit ↵ Enter.
- Download GLFW. Right click on the following address and select Open Link in New Window https://www.glfw.org/download.html, click 32-bit Windows binaries. You will get "glfw-3.3.bin.WIN32" or the latest version.
- Click the download > right click > select copy.
- Navigate to C: > GL > right click > select paste.
- Click on "glfw-3.3.bin.WIN32" and rename it to glfw.
- Now in "GL" folder, you have folder glfw.
- Download GLEW. Right click on the following link and select Open Link in New Window http://glew.sourceforge.net/. Below Downloads, find Binaries and click Windows 32-bit and 64-bit.
- In the window where it has downloaded, click the folder glew-2.1.0 > right click > select Copy.
- Navigate to C: > GL > right click > select Paste. Rename glew-2.1.0 to glew.
- If the folder glew-2.1.0-win32 has downloaded, double click it for get glew-2.1.0.
- Download GLM. Right click on the following address and select Open Link in New Window glm OpenGL mathematics library. In the upper left corner click Download GLM 0.9.9.7 or latest version (see picture above).
- In the download window click folder "glm" > right click > Copy.
- Navigate to C:GL > right click > Paste.
Method 2 of 7:
Creating a Visual Studio Project
- Create an empty project.
- If Visual Studio is not opened. Open it > Click Create a new project > Empty Project > Next.
- In Configure your new project wizard, for "Project name", type: Project-0. Next to "Location" text field click ....
- Navigate to C: > GL > click Select folder. Now the "Location" is C:GL.
- Check "Place solution and project in the same directory" > click Create.
- Wait until Visual Studio instance appears.
- If it has already been opened. Click File > New > Project… > Empty Project > Next.
- If Visual Studio is not opened. Open it > Click Create a new project > Empty Project > Next.
- Add your source file to the project.
- In the Solution Explorer window, right click the Source Files entry (the last one) > select Add > New Item….
- In the Add New Item - Project-0 window, click C++ File (.cpp) (the first one) from the middle of the window. In Name text box type Main.cpp.
- The Location is C:GLProject-0.
- Click the Add button. The file will open in the main text editor but leave the file blank for now.
Method 3 of 7:
Installing GLFW, GLEW and GLM on the Project
- Configure "Additional Include Directories".
- In Solution Explorer, right click on the name of your project, that is Project-0, and select Properties. Leave default settings: Configuration: Active(Debug), and Platform: Active(Win32).
- Open the C/C++ drop-down menu. Click General > Additional Include Directories. > find the down arrow at the right of the field > click in the drop down menu. .
- Copy this C:GLglfwinclude > in Additional Include Directories wizard click the first icon > paste.
- Copy this C:GLglewinclude > again click first icon > paste.
- Copy this C:GLglm > once more click first icon > paste.
- On Additional Include Directories wizard click OK.
- Copy this C:GLglfwinclude > in Additional Include Directories wizard click the first icon > paste.
- Configure the Linker "Additional Library Directories". Open the Linker drop-down menu, and click General. Click Additional Library Directories entry > down arrow at the right of the field > click in the drop-down menu.
- Copy this C:GLglfwlib-vc2019 > in "Additional Library Directories" wizard click the first icon > paste.
- Copy this C:GLglewlibReleaseWin32 > click first icon > paste > click OK.
- Configure "Additional Dependencies".
- In the Linker drop down menu click "Input". Click Additional Dependencies entry > the down arrow at the right of the field > in the drop-down menu.
- Copy opengl32.lib; glfw3.lib; glfw3dll.lib; glew32.lib and paste on the top-most text box of the Additional Dependencies wizard. Click OK in the Additional Dependencies wizard.
- Set the Linker "SubSystem" to "Console". In the Linker drop-down menu, click System > SubSystem > click the down arrow at the end of the field > select Console(/SUBSYSTEM:CONSOLE) from the dropdown menu > click Apply, then OK on the Project Property Pages wizard.
- Copy glew32.dll file and paste to Project-0 folder
- Navigate to C: > GL > glew > bin > Release > Win32. Click glew32.dll > right-click > Copy.
- Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
- The glew32.dll file should now be in Project-0 folder along with Main.cpp, and 4 other files created by Visual Studio.
- Test your project. Right click on following address and select Open Link in New Window tutorial01.cpp. Copy the code and paste in Main.cpp code area. Hit Ctrl+F5. Two windows should appear. One will be black and the other will be blue.
- If only the black window (the console) appears with message: "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorial.", set up is okay, but function glfwCreateWindow did not work.
- Correct any errors. If you see any errors in the "Error List" check the following:
- File with extension .h go to Part (Method) 3, step 1, "Configure the "Additional Include Directories"" and follow instructions.
- File with extension .lib go to Part (Method) 3, step 2, "Configure the linker "Additional Library Directories"", and follow instructions. Also to step 3, "Configure the linker "Additional Library Directories"".
- File with extension .dll go to step 5, "Copy glew32.dll file and paste to Project folder" and follow instructions.
- "Entry point must be defined" go to step 4, Set the linker "SubSystem" to "CONSOLE" and follow instructions.
- For other errors, if you cannot correct them, close Visual Studio > delete project folder Projetc-0 which lives in C:GL > open Visual Studio > repeat set up from Part 2. Good job.
Method 4 of 7:
Creating a Project with GLFW-GLEW-GLM Template
- Create Template. Go to Visual Studio main menu and, while Project-0 is open, click Project > Export Template.... On Export template Wizard check Project Template, if it's not checked. Click Next >. On Select Template Options, in Template name text box type: GLFW-GLEW-GLM. Click Finish. The Template has been created.
- Create your project.
- Click File > New > Project....
- In Create a new project wizard scroll down the list of templates and select GLFW-GLEW-GLM > click Next.
- In the Configure your new project wizard, in "Project name" text field type Project-1.
- Location should be C:GL. If it's not, click ... > navigate C:GL > Folder's name should be GL > click Select a folder.
- Be sure Place solution and project in the same directory is checked. Click Create.
- Add source File. In Solution Explorer menu double click Source Files > click Main.cpp. Code should appear on V.S. code area. You can modify or change code if you desire.
- Copy glew32.dll file and paste in Project-1 folder
- Navigate to C: > GL > glew > bin > Release > Win32. Click glew32.dll > right-click > Copy.
- Navigate to C: > GL > Project-1. Right-click an empty area in Project-1 folder, and select Paste.
- The glew32.dll file should now be in Project-1 folder along with Main.cpp, and 4 other files created by Visual Studio.
- Run program. Good job.
Method 5 of 7:
Creating Project to target x64 Platform
- Create folder GL as above.
- Download GLFW 64 bits. Right click on following address and select Open Link in New Window https://www.glfw.org/download.html, click 64-bit Windows binaries. You get "glfw-3.3.bin.WIN64" or latest version.
- Download GLEW and GLM as above.
- Create project with name Project-2 and add Main.cpp file as above.
- Project's Property Pages main settings. Go to "Solution Explorer" > right click on the name of your project > select "Properties". In Platform: entry, choose x64 > Click Configuration manager...
- In Active solution platform: select x64
- In Platform entry, x64 is automatically selected.
- Click Close
- Additional Include Directories. As above.
- Additional Library Directories. Open the "Linker" drop-down menu, and click "General". Click "Additional Library Directories" entry > down arrow at the end of the field > "Edit" in the drop-down menu.
- Copy this C:GLglfwlib-vc2019 > in "Additional Library Directories" wizard click the first icon > paste.
- Copy this C:GLglewlibReleasex64 > click first icon > paste > click OK.
- Additional Dependencies. As above.
- Subsystem. As above.
- Copy glew32.dll file and paste into Project-2. In Windows's "File Explorer" navigate to
- C: > GL > glew > bin > Release > x64. In "x64" folder click "glew32.dll" file > right-click > "Copy".
- C: > GL > Project-2. Right-click on empty area in "Project-2" folder, and select "Paste".
- Test project and correct errors if any. As above.
- TIP: Even if in Property Pages main settings it is Platform: x64, click Configuration manager..., and in Active solution platform: select x64.
- Create template. As above Method 4.
- TIP: In every project you create with this template, select x64 (next to Debug) in Visual Studio's GUI.
Method 6 of 7:
Setting up Built GLFW, Built GLEW, and Built GLM
- In directory C, create folder GL. If folder GL exists in directory C:, close Visual Studio > in File Explorer > C: > right click GL folder > select Delete > again right click > select New > Folder > type: GL > hit ↵ Enter.
- Install CMake. Right-click on following link and select Open Link in New Window Use CMake to Get Binaries from Source Code. Follow Method 1 Installing CMake.
- Download GLFW source. Right-click on following address and select Open Link in New Window https://www.glfw.org/download.html. Select "Source package".
- In downloading window click zip folder glfw-3.3 (or latest version) > right click > select Copy.
- In File Explorer navigate to C: > GL > right click > select Paste. Click twice on folder's name > delete name > type: glfw > hit ↵ Enter.
- Download GLEW source. Right-click on following address and select Open Link in New Window http://glew.sourceforge.net/. Beside Source click ZIP.
- In downloading window click folder glew-2.1.0 (or latest) > right click > Copy.
- Navigate to C: > GL. Right click > Paste. Click twice on folder's name and rename glew > hit ↵ Enter. Now in folder GL you have folders glew and glfw.
- Download GLM. Go to Method 1 and follow step 4.
- Build GLFW by CMake and Visual Studio. Go to CMake GUI.
- Copy C:/GL/glfw and paste in first text field.
- Copy C:/GL/glfw/build and paste in second text field.
- Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes > select Visual Studio 16 2019 > click Finish.
- When, in CMake GUI, you read: "Configuring done", click Generate. You should read: "Generating done".
- Close CMake GUI.
- Build your solution.
- Navigate to C: > GL > glfw > build. Double click "GLFW.sln", or "GLFW", or "ALL_BUILD.vcxproj". An instance of Visual Studio appears. Wait until in main menu Build entry appears. Click it > "Build Solution".
- Wait till you read the last line in "Output" window: ========== Build: XX succeeded, 0 failed, 0 up-to-date, 2 skipped" ==========
- Number XX of "succeeded" changes in glfw versions. Today (31-12-2019) is 32.
- Navigate to C: > GL > glfw > build > src > Debug. Inside you should see file glfw3.lib.
- Build GLEW by CMake and Visual Studio. Follow above step but
- In first text field paste C:/GL/glew/build/cmake
- In second paste C:/GL/glew/build
- Navigate to C: > GL > glew > build. Double click "glew.sln", or "glew", or "ALL_BUILD.vcxproj".
- In V.S. Output wizard, number of succeded today (31-1-2020) is 6, may change in later version though.
- Navigate to C: > GL > glew > build > lib > Debug. Inside you should see file glew32d.lib among two other files.
- Build GLM by CMake and Visual Studio. Follow step 6, Build GLFW by CMake and Visual Studio but...
- In first text field paste C:/GL/glm
- In second paste C:/GL/glm/build
- Navigate to C: > GL > glm > build. Double click "glm.sln", or "glm", or "ALL_BUILD.vcxproj".
- In V.S. Output wizard, number of succeeded today (31-1-2020) is 165, may change in later version though.
- Navigate to C: > GL > glm > build > glm > Debug. Inside you should see file glm_static.lib among 4 other files.
- Set up built GLFW, built GLEW and built GLM in project.
- Create empty project and add source file according to Method 2.
- Configure project's Properties. In Solution Explorer wizard, right click Project's name that is Project-0 > select Properties.
- (1) Project-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
- In Active solution platform: select x64.
- In Platform entry, x64 is automatically selected.
- Click Close.
- (2) Additional Include Directories. Click C/C++ > General > In beside menu select the first one, Additional Include Directories > click the down arrow at the end of the field > click Edit... > first icon > three dots ...
- Navigate to C: > GL > glfw > include > click include > click Select a folder > click OK.
- Click again first icon > three dots > navigate to C: > GL > glew > include > click include > click Select a folder > click OK.
- Click once more first icon > three dots > navigate to C: > GL > glm, click Select a folder > click OK.
- (3) Additional Library Directories. Double click Linker > click General > Additional Library Directories > click the down arrow at the end of the field > click Edit... > first icon.
- Copy C:GLglfwbuildsrcDebug and paste in upper-most text field.
- Click again first icon > copy C:GLglewbuildlibDebug and paste in upper-most text field.
- Click once more first icon > copy C:GLglmbuildglmDebug and paste in upper-most text field > click OK.
- (4) Additional Dependencies. In Linker drop-down menu select Input > in beside menu select the first one, Additional Dependencies > click the down arrow at the end of the field > Edit... > copy opengl32.lib; glfw3.lib; glew32d.lib; glm_static.lib and paste in Additional Dependencies wizard's upper-most text box > click OK.
- (5) Set System to SubSystem CONSOLE. In Linker drop-down menu select System > in beside menu select the first one, SubSystem > click the down arrow at the end of the field > select Console (/SUBSYSTEM:CONSOLE). Click Apply and OK.
- (1) Project-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
- Copy glew32d.dll file and paste into Project-0 folder.
- Navigate to C: > GL > glew > build > bin > debug. Click glew32d.dll > right-click > Copy.
- Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
- Copy glm_shared.dll file and paste into Project-0 folder.
- Navigate to C: > GL > glm > build > glm > Debug. Click glm_shared.dll > right-click > Copy.
- Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
- glew32d.dll and glm_shared.dll files should now be in Project-0 folder along with Main.cpp, and 4 other files created by Visual Studio.
- Test your project and correct errors if any. Go to Method 3, and follow steps 7 and 8.
- Create Template. As above Method 4. Remember, in every project you create with this template click x64 in V.S. GUI's main menu.
Method 7 of 7:
Choosing Set Up
- In this tutorial you learn 3 was to set GLFW, GLEW and GLM in Project with Visual Studio.
- Set up binaries x86 (32 bits). It's the easiest. You should start learning set up from here.
- Set up binaries x64 (64 bits). It targets x64 platform. Choose it only when you have specific reason for doing so.
- Compile GLFW source, GLEW source, GLM source, and set up them in project. Targets x64 too.The most difficult. The best though.
3.9 ★ | 29 Vote
You should read it
- How to Create an Executable File from Eclipse
- How to Set Up an OpenGL SDL GLEW Template Project in Visual Studio
- How to Set Up an OpenGL FreeGLUT GLEW Template Project in Visual Studio
- How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio
- How to Open an MPP File on PC or Mac
- How to Set Up SFML in a Project on Visual Studio
- Toshiba will be the main supplier for Project Ara
- How to Set Up SDL with Visual Studio
- How to Add JARs to Project Build Paths in Eclipse (Java)
- Latest Project XL code and how to enter Project XL code
- How to Play Sounds for Calendar Notifications on a Mac
- How to Make a Bug in GIMP
Maybe you are interested
How to use Auto Clicker Assist to automatically click the mouse
Instructions to fix double click error on computer mouse - Click once becomes twice
PowerToys will soon support creating app spaces and launching with just one click
Turn Windows 11 interface into Windows 10 with just one click
Fix right-click issue on Windows 10
Do not click on strange links or your phone will be hijacked