PDF download Download Article PDF download Download Article

For graphics, many programmers favor OpenGL. Its creator strongly advises using an OpenGL loading library (like GLAD) and a window toolkit (like GLFW) if you are one of them. This tutorial will assist you with overcoming the initial difficulty of utilizing OpenGL with GLFW and GLAD, which includes installing and configuring them as well as using the OpenGL-GLFW-GLAD Template in Visual Studio 2022 to create your first project. Assumed for this guide are Windows 10 or 11 with Visual Studio 2022 as your IDE. This lesson is meant for the novice. He is able to configure GLFW and GLAD in a Visual Studio project. You learns how to set up GLFW and GLAD on project with Visual Studio by 3 ways: Firstst targeting x32 platform, second targeting x64 platform, and third setup source GLFW that Visual Studio and CMake compiled, as well as binary GLAD that you did not compile. By default Visual Studio 2022 is x64 application. However it runs interchangeably x86 (32 bits) and x64 applications.

Part 1
Part 1 of 19:

Configuring Visual Studio

PDF download Download Article
  1. 1
    Emphasize the actions you plan to take. Highlight a step, a substep, or a section of it, then carry it out. Take a look at the image above.
  2. 2
    Download Visual Studio 2022 Community.
  3. Advertisement
Part 2
Part 2 of 19:

Downloading GLFWx32 and GLAD

PDF download Download Article
  1. 1
    Make the GL and GLP folders. Launch the File Explorer in Windows > Open the directory (disk) C.
    • It's okay if the folders GL and GLP exist.
    • If not, perform a right-click in an empty space > choose "New" > "Folder" > type GL > press Enter . Create the GLP folder in the same manner.
    • Make a folder named GLAD inside the "GL" folder.
  2. 2
    Download GLFW x32. Choose Open Link in New Window by right-clicking on the following address: https://www.glfw.org/download.html .
    • Click 32-bit Windows binaries . You receive the most recent version, glfw-3.4.bin.WIN32 (or latest). The unzipped folder ought to appear in a new File Explorer.
    • Open folder C:\GL.
    • In the new File Explorer click folder glfw-3.4.bin.WIN32 , (or latest) > click it again and drag into C:\GL.
    • Close the new "File Explorer" window > close the GLFW window.
    • Once the folder has completed copying, and pasting, copy GLFWx32 > click folder > right click > click "Rename" (in Windows 11 it is an icon) > paste > hit Enter .
    • Now in "GL" folder you have folders "GLAD" (empty) and "GLFWx32".
  3. 3
    Download GLAD. Right click on following address and select Open Link in New Window https://glad.dav1d.de/ .
    • In Language leave C/C++ .
    • Below API , in gl entry, select the latest version (today is 4.6).
    • In Specification leave OpenGL .
    • In Profile select Core .
    • Ignore the Extensions .
    • Make sure in Options list "Generate a loader" option is ticked.
    • Click GENERATE .
    • In "Glad" window (see picture above), click "glad.zip".
    • In downloading new File Explorer window you have two unzip folders: include and src .
    • Open folder C:\GL\GLAD.
    • Click folder include > click it again and drag into folder GLAD , at C:\GL\GLAD.
    • Click folder src > click it again and drag into folder GLAD , at C:\GL\GLAD.
    • Now in folder GLAD you have two unzip folders: include and src .
    • Go back to GL folder.
    • Close GLAD window > close downloading new File Explorer window.
  4. Advertisement
Part 3
Part 3 of 19:

Creating Project GLFWx32-GLAD-0

PDF download Download Article
  1. 1
    Create empty project.
    • If it's the first time you open Visual Studio . Click Create a new project .
      • In Create a new project wizard, find Empty Project Start from scratch with C++ for Windows. Provides no starting files. (see image above. If it's not visible, enter its name in the search bar above the list and press Enter ) > click it > click Next .
      • In Configure your new project wizard for "Project name" type (or copy and paste) GLFWx32-GLAD-0
      • Copy C:\GLP and paste in "Location" text field.
      • Check "Place solution and project in the same directory".
      • Click Create .
      • Wait till Visual Studio instance appears.
    • If it's not the first time . In main menu click File > New > Project… > the rest as above..
    • In "Solution Explorer" window right click the "Source Files" folder (the last one) > click "Add > "New Item…"
    • In the "Add New Item" wizard instead of "FileName" type Main > hit Enter . The source file Main.cpp will open in the main text editor but leave the file blank for now.
  2. 3
    Add file glad.c . Go to Visual Studio > Solution Explorer > right click Source Files > click Add > Existing Item ... .
    • Copy C:\GL\GLAD\src and paste in "Add Existing Item - GLFWx32-GLAD-0" wizard Address Bar > hit Enter > click glad.c . "File name" should be glad.c . Click Add .
  3. Advertisement
Part 4
Part 4 of 19:

Installing GLFWx32 and GLAD in the Project

PDF download Download Article
  1. 1
    Configure "Property Pages". Go to "Solution Explorer" > right click on the name of your project GLFWx32-GLAD-0 > select "Properties" (the last one). In "GLFWx32-GLAD-0 Property Pages" wizard,
Part 5
Part 5 of 19:

Testing Project GLFWx32-GLAD-0 and Correcting errors

PDF download Download Article
  1. 1
    Test your project. Right click on following address and select Open Link in New Window https://learnopengl.com/code_viewer_gh.php?code=src/1.getting_started/2.1.hello_triangle/hello_triangle.cpp . Copy the code. Go to Visual Studio and paste in Main.cpp code area > in main menu select x86 > hit Ctr + F5 or in Visual Studio's main menu click the green triangle with phrase "Local Windows Debugger", and wait... Two windows should appear: One is black, while the other has the words "LearnOpenGL" and an orange triangle inside of it.
    • If only the black window (the console) appears with message: "Failed to create GLFW window", set up is okay, function glfwCreateWindow did not work.
  2. 2
    Correct any errors. Files are missing. Copy GLFWx32-GLAD-0 and paste in File Explorer Address Bar. You should see file you added Main.cpp , and 4 other files added by Visual Studio. If they are missing you missed add file Main.cpp . Go to Part 3, step 2, and add it now.
    • In "Error List" if you see error about
      • file with extension .h
        • Check whether folders GLFWx32 and GLAD exist in C:\GL. If they exist,
        • go to previous Part, step 1, sub step 2. Additional Include Directories and follow instructions.
      • file with extension .lib go to previous Part, step 1, sub step 3. Additional Library Directories , and follow instructions. Also to step 1, sub step 4. Additional Dependencies .
      • file glad.c go to Part 3, step 3, and follow instructions.
    • For other errors, if you cannot correct them, close Visual Studio > delete project folder GLFWx32-GLAD-0 which lives in C:\GLP > open Visual Studio > repeat set up from Part 3. Good job.
  3. Advertisement
Part 6
Part 6 of 19:

Creating a Project with GLFWx32-GLAD-0 Template

PDF download Download Article
  1. 2
    Create Project. In Visual Studio main menu, click File > New > Project... .
    • In Create a new project wizard in the list of templates select GLFWx32-GLAD-0 , (if it's not visible, enter its name in the search bar above the list and press Enter ) > click Next .
    • In Configure your new project wizard, "Project name" should be GLFWx32-GLAD-01 .
    • "Location" should be C:\GLP .
    • Make sure "Place solution and project in the same directory" is checked. Click Create , and wait for the project to be finished.
    • In Visual Studio main menu, select x86 .
    • Hit Ctr + F5 or in Visual Studio's main menu click the green triangle with phrase "Local Windows Debugger". Good job.
  2. 3
    Tips. When you create project with template, remember, in Visual Studio main menu, select x86 .
  3. Advertisement
Part 7
Part 7 of 19:

Downloading GLFW x64 and GLAD

PDF download Download Article
  1. 1
    Create folders GL, GLP and GLAD. Open Windows's File Explorer > Navigate to disk (directory) C.
    • If folders GL and GLP exist it's okay.
    • If they do not, right click in empty area > select New > Folder > type GL > hit Enter . By same way create folder GLP .
    • Within the GL folder make the GLAD folder.
  2. 2
    Download GLFW x64. 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.4.bin.WIN64" or latest version. The unzipped folder ought to appear in a new File Explorer.
    • Open folder C:\GL, if it's not already open.
    • In the new File Explorer click folder glfw-3.4.bin.WIN64 , (or latest) > click it again and drag into C:\GL.
    • Once the folder has completed copying and pasting, copy GLFWx64 > click folder > right click > click "Rename" (in Windows 11 it is an icon) > Paste > hit Enter .
    • Close the new "File Explorer" window > close the GLFW window.
  3. 3
    Download GLAD. Right click on following address and select Open Link in New Window https://glad.dav1d.de/ .
    • In Language leave C/C++ .
    • Below API , in gl entry, select the latest version (today is 4.6).
    • In Specification leave OpenGL .
    • In Profile select Core .
    • Ignore the Extensions .
    • Make sure in Options list "Generate a loader" option is ticked.
    • Click GENERATE .
    • In "Glad" window (see picture above), click "glad.zip".
    • In downloading new File Explorer window you have two unzip folders: include and src .
    • Open folder C:\GL\GLAD.
    • Click folder include > click it again and drag into folder GLAD , at C:\GL\GLAD.
    • Click folder src > click it again and drag into folder GLAD , at C:\GL\GLAD.
    • Now in folder GLAD you have two unzip folders: include and src .
    • Go back to GL folder.
    • Close GLAD window > close downloading new File Explorer window.
  4. Advertisement
Part 8
Part 8 of 19:

Creating project for platform x64

PDF download Download Article
  1. 1
    Create empty project.
    • If it's the first time you open Visual Studio . Click Create a new project .
      • In Create a new project wizard, find Empty Project Start from scratch with C++ for Windows. Provides no starting files. (see image above. If it's not visible, enter its name in the search bar above the list and press Enter ) > click it > click Next .
      • In Configure your new project wizard for "Project name" type (or copy and paste) GLFWx64-GLAD-0
      • Copy C:\GLP and paste in "Location" text field.
      • Check "Place solution and project in the same directory".
      • Click Create .
      • Wait till Visual Studio instance appears.
    • If it's not the first time . In main menu click File > New > Project… > the rest as above..
    • In "Solution Explorer" window right click the "Source Files" folder (the last one) > click "Add > "New Item…"
    • In the "Add New Item" wizard, instead of "FileName", type Main > hit Enter . The source file Main.cpp opens in the main text editor but leave the file blank for now.
  2. 3
    Add file glad.c . Go to Visual Studio > Solution Explorer > right click Source Files > click Add > Existing Item ... .
    • Copy C:\GL\GLAD\src and paste in "Add Existing Item - GLFWx64-GLAD-0" wizard Address Bar > hit Enter > click glad.c . "File name" should be glad.c . Click Add .
  3. Advertisement
Part 9
Part 9 of 19:

Installing GLFWx64 and GLAD in the Project

PDF download Download Article
  1. 1
    Configure "Property Pages". Go to "Solution Explorer" > right click on the name of your project GLFWx64-GLAD-0 > select "Properties" (the last one). In "GLFWx64-GLAD-0 Property Pages" wizard, .
Part 10
Part 10 of 19:

Testing and Correcting project GLFWx64-GLAD-0

PDF download Download Article
  1. 1
    Test your project. Right click on following address and select Open Link in New Window https://learnopengl.com/code_viewer_gh.php?code=src/1.getting_started/2.1.hello_triangle/hello_triangle.cpp . Copy the code. Go to Visual Studio and paste in Main.cpp code area > in main menu select x64 > hit Ctr + F5 or in Visual Studio's main menu click the green triangle with phrase "Local Windows Debugger", and wait... Two windows should appear: One is black, while the other has the words "LearnOpenGL" and an orange triangle inside of it.
    • If only the black window (the console) appears with message: "Failed to create GLFW window", set up is okay, function glfwCreateWindow did not work.
  2. 2
    Correct errors if any. Files are missing. Copy GLFWx64-GLAD-0 and paste in File Explorer Address Bar. You should see file you added Main.cpp , and 4 other files added by Visual Studio. If they are missing you missed add file Main.cpp . Go to Part 7, step 5, and add it now.
    • In "Error List" if you see error about
      • file with extension .h
        • Check whether folders GLFWx64 and GLAD exist in C:\GL. If they exist,
        • go to previous Part, step 2, sub step 2. Additional Include Directories and follow instructions.
      • file with extension .lib go to previous Part, step 2, sub step 3. Additional Library Directories , and follow instructions. Also to step 2, sub step 4. Additional Dependencies .
      • file glad.c go to Part 7, step 6, and follow instructions.
    • For other errors, if you cannot correct them, close Visual Studio > delete project folder GLFWx64-GLAD-0 which lives in C:\GLP > open Visual Studio > repeat set up from Part 7. Good job.
  3. Advertisement
Part 11
Part 11 of 19:

Creating Project with GLFWx64-GLAD-0 Template

PDF download Download Article
  1. 2
    Create project. In Visual Studio main menu > Click "File" > "New" > "Project...".
    • In Create a new project wizard in the list of templates select "GLFWx64-GLAD-0" (if it's not visible, enter its name in the search bar above the list and press Enter ) > click Next .
    • In Configure your new project wizard, "Project name" should be GLFWx64-GLAD-01 .
    • If Location is C:\GLP , it's okay. If it's not, copy C:\GLP , and paste.
    • Be sure "Place solution and project in the same directory" is checked. Click Create , and wait till project be created.
    • In Visual Studio's GUI main menu, select x64 > hit Ctrl + F5 or in Visual Studio's main menu click the green triangle with phrase "Local Windows Debugger".
    • TIP. When you create project with this template remember in Visual Studio GUI's main menu select x64 .
  2. Advertisement
Part 12
Part 12 of 19:

Installing CMake

PDF download Download Article
  1. 1
    Compiling a library from the source code guarantees that the resulting library is perfectly tailored for your CPU/OS, a luxury pre-compiled binaries don't always provide. It is also important that binaries you get target x64 platform.
  2. 2
    Create folders GL, GLP and GLAD. Open Windows's File Explorer > Navigate to disk (directory) C.
    • If folders GL and GLP exist it's okay.
    • Make a folder named GLAD inside the "GL" folder.
    • If they do not, right click in empty area > select New > Folder > type GL > hit Enter . By same way create folder GLP .
  3. 3
    Download CMake. Right-click on following address and select Open Link in New Window https://cmake.org/download/ .
  4. 4
    Copy and unzip the zip folder.
    • Open folder C:\GL.
    • In the new File Explorer click folder cmake-3.29.6-windows-x86_64 , (or latest) > click it again and drag into C:\GL.
    • Once the folder has completed copying and pasting, copy CMake > click folder > right click > click "Rename" (in Windows 11 it is an icon) > paste > hit Enter .
    • Close the new "File Explorer" window > close the "CMake" window.
    • Double click folder "CMake" > double click folder bin > inside you should see CMake's logo next to file name cmake-gui > double click this file. Now on your screen you have CMake GUI > go back to GL folder.
    • Each time you need CMake, navigate to C:\ > GL > double click folder CMake > double click "bin" > double click file cmake-gui (the one with CMake's logo).
  5. Advertisement
Part 13
Part 13 of 19:

Downloading Source GLFW and binaries GLAD

PDF download Download Article
  1. 1
    Download GLFW source code. Right-click on following address and select Open Link in New Window https://www.glfw.org/download.html .
    • Select "Source package". The unzipped folder ought to appear in a new File Explorer.
    • Open folder C:\GL.
    • In the new File Explorer click folder glfw-3.4 , (or latest) > click it again and drag into C:\GL.
    • Once the folder has completed copying and pasting, copy GLFWsrc > click folder > right click > click "Rename" > paste > hit Enter .
    • Close the downloading new File Explorer window > close "GLFW" window.
  2. 2
    Download GLAD. Right click on following address and select Open Link in New Window https://glad.dav1d.de/ .
    • In Language leave C/C++ .
    • Below API , in gl entry, select the latest version (today is 4.6).
    • In Specification leave OpenGL .
    • In Profile select Core .
    • Ignore the Extensions .
    • Make sure in Options list "Generate a loader" option is ticked.
    • Click GENERATE .
    • In "Glad" window (see picture above), click "glad.zip".
    • In downloading new File Explorer window you have two unzip folders: include and src .
    • Open folder C:\GL\GLAD.
    • Click folder include > click it again and drag into folder GLAD , at C:\GL\GLAD.
    • Click folder src > click it again and drag into folder GLAD , at C:\GL\GLAD.
    • Now in folder GLAD you have two unzip folders: include and src .
    • Go back to GL folder.
    • Close GLAD window > close downloading new File Explorer window.
  3. Advertisement
Part 14
Part 14 of 19:

Compiling Source GLFW

PDF download Download Article
  1. 1
    Go to CMake GUI. See image above.
    • Copy (attention: do not copy any space) C:\GL\GLFWsrc and paste in CMake GUI first text field.
    • Copy (attention: do not copy any space) C:\GL\GLFWsrc\build an paste in the second text field.
    • Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes > in wizard "Specify the generator for this project" select "Microsoft Visual Studio 17 2022" > click Finish .
      • When, in CMake GUI, you read: "Configuring done", click Generate . You should read: "Generating done".
    • Build your solution.
      • Copy C:\GL\GLFWsrc\build and paste in File Explorer Address Bar > hit Enter > Double click "GLFW.sln", or "GLFW", or "ALL_BUILD.vcxproj". In thrown wizard "Microsoft Visual Studio Version Selector" select "Microsoft Visual Studio 17 2022" > click OK . An instance of Visual Studio appears. Wait until in main menu "Build" entry appears. Click it > click "Build Solution".
      • Wait till you read the last line in "Output" window: ========== Build: X succeeded, 0 failed, 0 up-to-date, Y skipped" ==========
        • Numbers of succeeded (X) and skipped (Y) change in glfw versions. Today (29-June-2024) are 34 and 3 respectively.
      • Copy C:\GL\GLFWsrc\build\src\Debug and paste in File Explorer Address Bar > hit Enter . You should see file "glfw3.lib".
      • Close this instance of Visual Studio > Close CMake GUI.
Part 15
Part 15 of 19:

Creating Project GLFWsrc-GLAD-0

PDF download Download Article
  1. 1
    Create empty project.
    • If it's the first time you open Visual Studio . Open it > click Create a new project .
      • In Create a new project wizard, find Empty Project Start from scratch with C++ for Windows. Provides no starting files. (see image above. If it's not visible, enter its name in the search bar above the list and press Enter ) > click it > click Next .
      • In Configure your new project wizard for "Project name" type (or copy and paste) GLFWsrc-GLAD-0
      • Copy C:\GLP and paste in "Location" text field.
      • Check "Place solution and project in the same directory".
      • Click Create .
      • Wait till Visual Studio instance appears.
    • If it's not the first time . In main menu click File > New > Project… > the rest as above..
    • In "Solution Explorer" right click the "Source Files" folder (the last one) > click "Add > "New Item…"
    • In the "Add New Item" wizard instead of "FileName" type Main > hit Enter . The source file Main.cpp opens in the main text editor but leave the file blank for now.
  2. 3
    Add file glad.c . Go to Visual Studio > Solution Explorer > right click Source Files > click Add > Existing Item ... .
    • Copy C:\GL\GLAD\src and paste in "Add Existing Item - GLFWsrc-GLAD-0" wizard Address Bar > click glad.c . "File name" should be glad.c . Click Add .
    • In Solution Explorer , below Source Files you should see two files: glad.c and Main.cpp .
  3. Advertisement
Part 16
Part 16 of 19:

Installing GLFWsrc and GLAD in the Project

PDF download Download Article
  1. In Solution Explorer right click Project's name that is GLFWsrc-GLAD-0 > select Properties (the last one). In GLFWsrc-GLAD-0 Property Pages wizard,
Part 17
Part 17 of 19:

Testing and Correcting project GLFWsrc-GLAD-0

PDF download Download Article
  1. 1
    Test your project. Right click on following address and select Open Link in New Window https://learnopengl.com/code_viewer_gh.php?code=src/1.getting_started/2.1.hello_triangle/hello_triangle.cpp . Copy the code. Go to Visual Studio and paste in Main.cpp code area > in main menu select x64 > hit Ctr + F5 or in Visual Studio's main menu click the green triangle with phrase "Local Windows Debugger", and wait... Two windows should appear: One is black, while the other has the words "LearnOpenGL" and an orange triangle inside of it.
    • If only the black window (the console) appears with message: "Failed to create GLFW window", set up is okay, function glfwCreateWindow did not work.
  2. 2
    Correct errors if any. Files are missing. Copy GLFWsrc-GLAD-0 and paste in File Explorer Address Bar. You should see file you added Main.cpp , and 4 other files added by Visual Studio. If they are missing you missed add file Main.cpp . Go to previous Part, step 6, and add it now.
    • In "Error List" if you see error about
      • file with extension .h
        • Check whether folders GLFWsrc and GLAD exist in C:\GL. If they exist,
        • go to previous Part, step 8, sub step 2. Include and follow instructions.
      • file with extension .lib go to previous Part, step 8, sub step 3. Library , and follow instructions. Also to step 8 sub step 4. Dependencies .
      • file glad.c go to previous Part, step 7, and follow instructions.
    • For other errors, if you cannot correct them, close Visual Studio > delete project folder GLFWsrc-GLAD-0 which lives in C:\GLP > open Visual Studio > repeat set up from Part 11. Good job.
  3. Advertisement
Part 18
Part 18 of 19:

Creating Project with GLFWsrc-GLAD Template

PDF download Download Article
  1. Go to Visual Studio main menu and, while GLFWsrc-GLAD-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 , Template name should be GLFWsrc-GLAD-0 > click Finish .
    • Template has been created. Close thrown window with template's path.
  2. 2
    Create Project. In Visual Studio main menu click File > New > Project... .
    • In Create a new project wizard in the list of templates select GLFWsrc-GLAD-0 (if it's not visible, enter its name in the search bar above the list and press Enter ) > click Next .
    • In Configure your new project wizard, "Project name" should be GLFWsrc-GLAD-01 .
    • If "Location" is C:\GLP it's okay. If it's not, copy and paste.
    • Be sure Place solution and project in the same directory is checked. Click Create , and wait till Visual Studio GUI appears.
    • In Visual Studio main menu, select x64 .
    • Hit Ctr + F5 or in Visual Studio's main menu click the green triangle with phrase "Local Windows Debugger". Good programming.
  3. 3
    TIPS: In every project you create with it, remember, in Visual Studio's GUI, select x64 (next to Debug).
  4. Advertisement
Part 19
Part 19 of 19:

Choosing Set Up

PDF download Download Article
  1. 1
    In this tutorial you learn 3 was to set up GLFW and GLAD 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, and set up, together with GLAD, in project. Targets x64 too.The most difficult. The best though.

Expert Q&A

Ask a Question
      Advertisement

      Tips

      • You can create a folder in folder C:\GL for place in there your projects. When you create a project select this folder for "Location".
      • General way for configure Additional Include Directories is that, after clicking first icon, click three dots ... , navigate to the folder where .h file(s) live(s) (in this tutorial C:\GL\glfw\include and C:\GL\glad\include ) and click Select a folder .
      • General way for configure Additional Library Directories is that, after clicking first icon, click three dots ... , navigate to the folder where .lib file(s) live(s) (in this tutorial for x86 platform, C: > GL > glfw > lib-vc2019 ) and click Select a folder .
      Show More Tips
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      Thanks to all authors for creating a page that has been read 59,593 times.

      Is this article up to date?

      Advertisement