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

  1. Create folder GL. In directory (disk) C: right click > select New > Folder > type GL > hit Enter.
  2. 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.
    1. Click the download > right click > select copy.
    2. Navigate to C: > GL > right click > select paste.
    3. Click on "glfw-3.3.bin.WIN32" and rename it to glfw.
    4. Now in "GL" folder, you have folder glfw.
  3. 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.
    1. In the window where it has downloaded, click the folder glew-2.1.0 > right click > select Copy.
    2. Navigate to C: > GL > right click > select Paste. Rename glew-2.1.0 to glew.
    3. If the folder glew-2.1.0-win32 has downloaded, double click it for get glew-2.1.0.
  4. How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio Picture 1How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio Picture 1
    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).
    1. In the download window click folder "glm" > right click > Copy.
    2. Navigate to C:GL > right click > Paste.
Method 2 of 7:

Creating a Visual Studio Project

  1. Create an empty project.
    1. If Visual Studio is not opened. Open it > Click Create a new project > Empty Project > Next.
      1. In Configure your new project wizard, for "Project name", type: Project-0. Next to "Location" text field click ....
      2. Navigate to C: > GL > click Select folder. Now the "Location" is C:GL.
      3. Check "Place solution and project in the same directory" > click Create.
      4. Wait until Visual Studio instance appears.
    2. If it has already been opened. Click File > New > Project… > Empty Project > Next.
  2. Add your source file to the project.
    1. In the Solution Explorer window, right click the Source Files entry (the last one) > select Add > New Item….
    2. 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.
    3. The Location is C:GLProject-0.
    4. 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

  1. How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio Picture 2How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio Picture 2
    Configure "Additional Include Directories".
    1. 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).
  2. How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio Picture 3How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio Picture 3
    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. .
    1. Copy this C:GLglfwinclude > in Additional Include Directories wizard click the first icon > paste.
      How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio Picture 4How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio Picture 4
      .
    2. Copy this C:GLglewinclude > again click first icon > paste.
    3. Copy this C:GLglm > once more click first icon > paste.
    4. On Additional Include Directories wizard click OK.
  3. 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.
    1. Copy this C:GLglfwlib-vc2019 > in "Additional Library Directories" wizard click the first icon > paste.
    2. Copy this C:GLglewlibReleaseWin32 > click first icon > paste > click OK.
  4. Configure "Additional Dependencies".
    1. 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.
    2. 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.
  5. 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.
  6. Copy glew32.dll file and paste to Project-0 folder
    1. Navigate to C: > GL > glew > bin > Release > Win32. Click glew32.dll > right-click > Copy.
    2. Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
    3. The glew32.dll file should now be in Project-0 folder along with Main.cpp, and 4 other files created by Visual Studio.
  7. 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.
    1. 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.
  8. Correct any errors. If you see any errors in the "Error List" check the following:
    1. File with extension .h go to Part (Method) 3, step 1, "Configure the "Additional Include Directories"" and follow instructions.
    2. 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"".
    3. File with extension .dll go to step 5, "Copy glew32.dll file and paste to Project folder" and follow instructions.
    4. "Entry point must be defined" go to step 4, Set the linker "SubSystem" to "CONSOLE" and follow instructions.
    5. 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

  1. 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.
  2. Create your project.
    1. Click File > New > Project....
    2. In Create a new project wizard scroll down the list of templates and select GLFW-GLEW-GLM > click Next.
    3. In the Configure your new project wizard, in "Project name" text field type Project-1.
    4. Location should be C:GL. If it's not, click ... > navigate C:GL > Folder's name should be GL > click Select a folder.
    5. Be sure Place solution and project in the same directory is checked. Click Create.
  3. 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.
  4. Copy glew32.dll file and paste in Project-1 folder
    1. Navigate to C: > GL > glew > bin > Release > Win32. Click glew32.dll > right-click > Copy.
    2. Navigate to C: > GL > Project-1. Right-click an empty area in Project-1 folder, and select Paste.
    3. The glew32.dll file should now be in Project-1 folder along with Main.cpp, and 4 other files created by Visual Studio.
    4. Run program. Good job.
Method 5 of 7:

Creating Project to target x64 Platform

  1. Create folder GL as above.
  2. 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.
  3. Download GLEW and GLM as above.
  4. Create project with name Project-2 and add Main.cpp file as above.
  5. 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...
    1. In Active solution platform: select x64
    2. In Platform entry, x64 is automatically selected.
    3. Click Close
  6. Additional Include Directories. As above.
  7. 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.
    1. Copy this C:GLglfwlib-vc2019 > in "Additional Library Directories" wizard click the first icon > paste.
    2. Copy this C:GLglewlibReleasex64 > click first icon > paste > click OK.
  8. Additional Dependencies. As above.
  9. Subsystem. As above.
  10. Copy glew32.dll file and paste into Project-2. In Windows's "File Explorer" navigate to
    1. C: > GL > glew > bin > Release > x64. In "x64" folder click "glew32.dll" file > right-click > "Copy".
    2. C: > GL > Project-2. Right-click on empty area in "Project-2" folder, and select "Paste".
  11. Test project and correct errors if any. As above.
    1. TIP: Even if in Property Pages main settings it is Platform: x64, click Configuration manager..., and in Active solution platform: select x64.
  12. Create template. As above Method 4.
    1. 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

  1. 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.
  2. 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.
  3. Download GLFW source. Right-click on following address and select Open Link in New Window https://www.glfw.org/download.html. Select "Source package".
    1. In downloading window click zip folder glfw-3.3 (or latest version) > right click > select Copy.
    2. In File Explorer navigate to C: > GL > right click > select Paste. Click twice on folder's name > delete name > type: glfw > hit Enter.
  4. Download GLEW source. Right-click on following address and select Open Link in New Window http://glew.sourceforge.net/. Beside Source click ZIP.
    1. In downloading window click folder glew-2.1.0 (or latest) > right click > Copy.
    2. 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.
  5. Download GLM. Go to Method 1 and follow step 4.
  6. How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio Picture 5How to Set Up OpenGL GLFW GLEW GLM on a Project with Visual Studio Picture 5
    Build GLFW by CMake and Visual Studio. Go to CMake GUI.
    1. Copy C:/GL/glfw and paste in first text field.
    2. Copy C:/GL/glfw/build and paste in second text field.
    3. Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes > select Visual Studio 16 2019 > click Finish.
      1. When, in CMake GUI, you read: "Configuring done", click Generate. You should read: "Generating done".
      2. Close CMake GUI.
    4. Build your solution.
      1. 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".
      2. Wait till you read the last line in "Output" window: ========== Build: XX succeeded, 0 failed, 0 up-to-date, 2 skipped" ==========
        1. Number XX of "succeeded" changes in glfw versions. Today (31-12-2019) is 32.
    5. Navigate to C: > GL > glfw > build > src > Debug. Inside you should see file glfw3.lib.
  7. Build GLEW by CMake and Visual Studio. Follow above step but
    1. In first text field paste C:/GL/glew/build/cmake
    2. In second paste C:/GL/glew/build
    3. Navigate to C: > GL > glew > build. Double click "glew.sln", or "glew", or "ALL_BUILD.vcxproj".
    4. In V.S. Output wizard, number of succeded today (31-1-2020) is 6, may change in later version though.
    5. Navigate to C: > GL > glew > build > lib > Debug. Inside you should see file glew32d.lib among two other files.
  8. Build GLM by CMake and Visual Studio. Follow step 6, Build GLFW by CMake and Visual Studio but...
    1. In first text field paste C:/GL/glm
    2. In second paste C:/GL/glm/build
    3. Navigate to C: > GL > glm > build. Double click "glm.sln", or "glm", or "ALL_BUILD.vcxproj".
    4. In V.S. Output wizard, number of succeeded today (31-1-2020) is 165, may change in later version though.
    5. Navigate to C: > GL > glm > build > glm > Debug. Inside you should see file glm_static.lib among 4 other files.
  9. Set up built GLFW, built GLEW and built GLM in project.
    1. Create empty project and add source file according to Method 2.
    2. Configure project's Properties. In Solution Explorer wizard, right click Project's name that is Project-0 > select Properties.
      1. (1) Project-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
        1. In Active solution platform: select x64.
        2. In Platform entry, x64 is automatically selected.
        3. Click Close.
      2. (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 ...
        1. Navigate to C: > GL > glfw > include > click include > click Select a folder > click OK.
        2. Click again first icon > three dots > navigate to C: > GL > glew > include > click include > click Select a folder > click OK.
        3. Click once more first icon > three dots > navigate to C: > GL > glm, click Select a folder > click OK.
      3. (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.
        1. Copy C:GLglfwbuildsrcDebug and paste in upper-most text field.
        2. Click again first icon > copy C:GLglewbuildlibDebug and paste in upper-most text field.
        3. Click once more first icon > copy C:GLglmbuildglmDebug and paste in upper-most text field > click OK.
      4. (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. (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.
    3. Copy glew32d.dll file and paste into Project-0 folder.
      1. Navigate to C: > GL > glew > build > bin > debug. Click glew32d.dll > right-click > Copy.
      2. Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
    4. Copy glm_shared.dll file and paste into Project-0 folder.
      1. Navigate to C: > GL > glm > build > glm > Debug. Click glm_shared.dll > right-click > Copy.
      2. Navigate to C: > GL > Project-0. Right-click an empty area in Project-0 folder, and select Paste.
      3. 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.
  10. Test your project and correct errors if any. Go to Method 3, and follow steps 7 and 8.
  11. 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

  1. In this tutorial you learn 3 was to set GLFW, GLEW and GLM in Project with Visual Studio.
    1. Set up binaries x86 (32 bits). It's the easiest. You should start learning set up from here.
    2. Set up binaries x64 (64 bits). It targets x64 platform. Choose it only when you have specific reason for doing so.
    3. 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