Many programmers prefer OpenGL for graphics. If you are one of them, you are strongly advised by its producer to use a window toolkit (such as GLFW) and an OpenGL loading libraries (such as GLAD). This guide will help you get over the first challenge of using OpenGL with GLFW and GLAD: Installing and setting them up, and creating your first project with OpenGL-GLFW-GLAD Template in Visual Studio 2022. This guide will assume your platform is Windows 10 or 11, and your IDE is Visual Studio 2022. During Visual Studio installation, check the Desktop development with C++ workload box. Also click "Language pack" and check "English" box. It is addressing the beginner. He can set up GLFW and GLAD in project with Visual Studio by 3 ways: 1st targeting x32 platform, 2nd targeting x64 platform, and 3rd set up GLFW source compiled by CMake and Visual studio, and GLAD.

Part 1
Part 1 of 19:

Configuring Visual Studio

  1. 1
    Highlight what you expect to do. Highlight step or sub-step or part of it and then do it. For example see picture above.
  2. 2
    Download Visual Studio 2022. If you have not done so, you can download it from https://www.visualstudio.com/downloads.
  3. Advertisement
Part 2
Part 2 of 19:

Downloading GLFWx32 and GLAD

  1. 1
    Create folders GL and GLP. 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.
    • Into folder GL create folder with name GLAD
  2. 2
    Download GLFW x32. Right click on following address and select Open Link in New Window https://www.glfw.org/download.html, click 32-bit Windows binaries. You get "glfw-3.3.8.bin.WIN32" or latest version.
    • Click it > right click > select Copy.
    • Navigate to C: > GL > right click > select paste.
    • (Alternatively click folder "glfw-3.3.8.bin.WIN32", or latest version, in window where is downloaded and drag into folder C:\GL).
    • Click on "glfw-3.3.8.bin.WIN32" > right click > select "Rename" > type GLFWx32 > 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.
    • Scroll down the page and click GENERATE.
    • In "Glad" window (see picture above), click "glad.zip".
    • In downloading window you have two folders: include and src.
    • Click folder include > right click > Copy.
      • Navigate to C: > GL > GLAD. In GLAD folder right click > select Paste.
    • (Alternatively click folder include and drag into folder GLAD, at C:\GL\GLAD).
    • Go back to downloading window > click folder src > right click > Copy.
      • Navigate to C: > GL > GLAD. In GLAD folder right click > select Paste.
    • (Alternatively click folder src and drag into folder GLAD, at C:\GL\GLAD).
    • Now in folder GLAD you have two (unzipped) folders: include and src.
  4. Advertisement
Part 3
Part 3 of 19:

Creating Project GLFWx32-GLAD-0

  1. 1
    Create empty project.
    • If Visual Studio is not open. Open it > click Create a new project > find (see image above, if necessary scroll down the list. Icon is different than in image, it doesn't matter though) Empty Project Start from scratch with C++ for Windows. Provides no starting files., click it > click Next.
      • In "Project name" text field type (or copy and paste) GLFWx32-GLAD-0
      • In "Location" text field type C:\GLP
      • Check "Place solution and project in the same directory".
      • Click Create.
      • Wait till Visual Studio instance appears.
    • If it's open. Click File > New > Project… > Empty Project > Next. The rest as above.
  2. 2
    Add your Source file to the project.
    • In "Solution Explorer" window right click the "Source Files" folder (the last one) > click "Add > "New Item…"
    • Copy Main > in the "Add New Item" wizard delete "FileName" > paste > click Add. The source file Main.cpp will opens in the main text editor but leave the file blank for now.
  3. 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.
  4. Advertisement
Part 4
Part 4 of 19:

Installing GLFWx32 and GLAD in the Project

  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

  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, and wait... Two windows should appear: One black and other with name "LearnOpenGL" and inside an orange triangle.
    • 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 go to previous Part, step 1, sub step 2. Additional Include Directories and follow instructions. Also check whether folders GLFWx32 and GLAD exists in C:\GL.
      • 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.
      • "entry point must be defined" go to previous Part step 1, sub step 5. System and follow instructions.
      • 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 an GLFWx32-GLAD-0 Template

  1. 1
    Create Template. Go to Visual Studio main menu and, while GLFWx32-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 GLFWx32-GLAD-0 > Click Finish. The Template has been created. Close the 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 GLFWx32-GLAD-0, (if necessary scroll down the list) > click Next.
    • In Configure your new project wizard, "Project name" should be GLFWx32-GLAD-01.
    • If "Location" is C:\GLP it's okay. If it's not, copy it 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 main menu, select x86.
    • Hit Ctr+F5. Good job.
  3. 3
    Tips. When you create project with template, remember, in Visual Studio main menu, select x86.
  4. Advertisement
Part 7
Part 7 of 19:

Downloading GLFW x64 and GLAD

  1. 1
    Create folders GL and GLP. 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.
  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.3.8.bin.WIN64" or latest version.
    • Click it > right click > select Copy.
    • Navigate to C: > GL > right click > select paste.
    • (Alternatively click folder "glfw-3.3.8.bin.WIN64", or latest version, in window where is downloaded and drag into folder C:\GL).
    • Copy GLFWx64 > click twice (not double) on "glfw-3.3.8.bin.WIN64" > delete name > Paste.
  3. 3
    Download GLAD. If already you have downloaded it, it's okay. If not, right click on following address and select Open Link in New Window https://glad.dav1d.de/.
    • In Language leave C/C++.
    • In API/gl entry, select the latest version (today is 4.6).
    • In Specification leave OpenGL.
    • In Profile select Core.
    • Scroll down the page and click GENERATE.
    • In "Glad" window (see picture above), click "glad.zip".
    • In downloading window you have two folders: include and src.
    • Click folder include > right click > Copy.
      • Navigate to C: > GL > GLAD. In GLAD folder right click > select Paste.
    • (Alternatively click folder include and drag into folder GLAD, at C:\GL\GLAD).
    • Go back to downloading window > click folder src > right click > Copy.
      • Navigate to C: > GL > GLAD. In GLAD folder right click > select Paste.
    • (Alternatively click folder src and drag into folder GLAD, at C:\GL\GLAD).
    • Now in folder GLAD you have two (unzipped) folders: include and src.
  4. Advertisement
Part 8
Part 8 of 19:

Creating project for platform x64

  1. 1
    Create empty project.
    • If Visual Studio is not open. Open it > click Create a new project > find (see image above, if necessary scroll down the list. Icon is different than in image, it doesn't matter though) Empty Project Start from scratch with C++ for Windows. Provides no starting files., click it > click Next.
      • In "Project name" text field type (or copy and paste) GLFWx64-GLAD-0
      • In "Location" text field type C:\GLP
      • Check "Place solution and project in the same directory".
      • Click Create.
      • Wait till Visual Studio instance appears.
    • If it's open. Click File > New > Project… > Empty Project > Next. The rest as above.
  2. 2
    Add your Source file to the project.
    • In "Solution Explorer" window right click the "Source Files" folder (the last one) > click "Add > "New Item…"
    • Copy Main > in the "Add New Item" wizard delete "FileName" > paste > click Add. The source file Main.cpp opens in the main text editor but leave the file blank for now.
  3. 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.
  4. Advertisement
Part 9
Part 9 of 19:

Installing GLFWx64 and GLAD in the Project

  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

  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, and wait... Two windows should appear: One black and other with name "LearnOpenGL" and inside an orange triangle.
    • 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 go to previous Part, step 2, sub step 2. Additional Include Directories and follow instructions. Also check whether folders GLFWx64 and GLAD exists in C:\GL.
      • 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.
      • "entry point must be defined" go to previous Part step 2, sub step 5. System and follow instructions.
      • 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

  1. 1
    Create Template. Go to Visual Studio main menu and, while GLFW64-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 GLFWx64-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 GLFWx64-GLAD-0 (if necessary scroll down the list) > 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.
    • TIP. When you create project with this template remember in Visual Studio GUI's main menu select x64.
  3. Advertisement
Part 12
Part 12 of 19:

Installing CMake

  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 and GLP. 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.
  3. 3
    Download CMake. Right-click on following address and select Open Link in New Window https://cmake.org/download/. Scroll down the page and find "Latest Release (3.26.0)", (or latest). In second "Platform" list, find (see image above) "Windows x64 ZIP" and click the beside entry cmake-3.26.0-windows-x86_64.zip (or latest) > in opening wizard select Save file.
  4. 4
    Copy and unzip the zip folder.
    • If the downloaded folder doesn't contain line with stripes (unzipped folder) click it > right click > Copy.
    • If downloaded folder's icon contains vertical line with stripes (zipped folder), double click it for get unzipped folder, (or alternatively, click folder > right click > in drop-down menu select Extract all).
      • When unzipping (extracting files) is finished, click unzip folder cmake-3.26.0-windows-x86_64.zip (or latest) > right click > Copy.
    • Go to drive (directory) C: > GL > right click > Paste.
    • (Alternatively click folder "cmake-3.26.0-windows-x86_64" and drag into folder "GL").
    • When copying is finished click folder "cmake-3.26.0-windows-x86_64" > right click > select "Rename" > type CMake > hit Enter > double click it > double click folder bin > inside you should see CMake's logo next to file name cmake-gui > double click this file. If wizard "Windows protect your PC" appears, click More information > Run anyway. Now on your screen you have CMake GUI.
    • 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 GLAD

  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". In opened wizard select Save File.
  2. 2
    Unzip and copy folder.
    • In downloading window click zip folder glfw-3.3.8 (or latest) > click it, if you get no stripped (unzipped) icon, it's okay. If not, right click > select Extract all.
    • Copy unzip folder and paste in C:\GL.
    • Now in directory C:\GL, you have unzip folder glfw-3.3.8 (or latest). Click on its name > delete name > type: GLFWsrc > hit Enter.
  3. 3
    Download GLAD. If you have already downloaded it, it's okay. If not, in folder GL create folder GLAD. In folder C:\GL right click > select New > Folder > type: GLAD > hit Enter.
  4. Advertisement
Part 14
Part 14 of 19:

Compiling Source GLFW

  1. 1
    Go to CMake GUI. See above image.
    • Where is the source code. Copy (attention: do not copy any space)C:\GL\GLFWsrc and paste in CMake GUI beside text field.
    • Where to build the binaries. Copy (attention: do not copy any space)C:\GL\GLFWsrc\build an paste in beside text field.
    • Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes > in wizard "Specify the generator for this project" click Finish.
      • When, in CMake GUI, you read: "Configuring done", click Generate. You should read: "Generating done".
      • If, instead, wizard "Error" is thrown, click OK > click "File" > click "Delete Cache" > in thrown wizard "Delete Cache", click Yes.
    • 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". 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: 32 succeeded, 0 failed, 0 up-to-date, 3 skipped" ==========
        • Numbers of "succeeded" and skipped change in glfw versions. Today (8-Nov-2022) is 32 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 cmake GUI.
Part 15
Part 15 of 19:

Creating Project GLFWsrc-GLAD-0

  1. 1
    Create empty project.
    • If Visual Studio is not open. Open it > click Create a new project > find (see image above, if necessary scroll down the list. Icon is different than in image, it doesn't matter though) Empty Project Start from scratch with C++ for Windows. Provides no starting files., 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 Visual Studio is open. In main menu click File > New > Project… > the rest as above.
  2. 2
    Add your Source file to the project.
    • In "Solution Explorer" window right click the "Source Files" folder (the last one) > click "Add > "New Item…"
    • Copy Main > in the "Add New Item" wizard delete "FileName" > paste > click Add. The source file Main.cpp opens in the main text editor but leave the file blank for now.
  3. 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 File Explorer's 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.
  4. Advertisement
Part 16
Part 16 of 19:

Installing GLFWsrc and GLAD in the Project

  1. 1
    Configure project's Properties. In Solution Explorer wizard, 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

  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, and wait... Two windows should appear: One black and other with name "LearnOpenGL" and inside an orange triangle.
    • 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 go to previous Part, step 8, sub step 2. Include and follow instructions. Also check whether folder GLFWsrc and GLAD exists in C:\GL.
      • 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.
      • "entry point must be defined" go to previous Part step 8, sub step 5. System and follow instructions.
      • 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

  1. 1
    Create Template. 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 necessary scroll down the list) > 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 project be created.
    • In Visual Studio main menu, select x64.
    • Hit Ctr+F5. 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

  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.

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 14 people, some anonymous, worked to edit and improve it over time. This article has been viewed 44,126 times.
How helpful is this?
Co-authors: 14
Updated: March 21, 2023
Views: 44,126
Advertisement