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.
Steps
-
1Emphasize 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.
-
2Download Visual Studio 2022 Community.
- While downloading, check the box labeled "Desktop development with C++ workload." Scroll down the page if needed (see the image below.
- Select "Language pack" and tick the "English" option.
- Click "General" in the "Development settings" menu of the "Personalize your Visual Studio experience" wizard during installation. > click "Visual C++" > click Start Visual Studio .
-
1Make 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.
-
2Download 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".
-
3Download 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, which is 4.6 as of 26/11/2024.
- 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.
-
1Create 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..
- If it's the first time you open Visual Studio
. Click Create a new project
.
-
Add your Source file to the project.
- 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.
-
3Add 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 .
-
1Test 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.
-
2Correct 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.
- file with extension .h
- 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.
- In "Error List" if you see error about
-
Create Template. Go to Visual Studio main menu and, while GLFWx32-GLAD-0 is open , click Project > Export Template... > in Choose Template Type , confirm "Project template" is selected > 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.
-
2Create 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.
-
3Tips. When you create project with template, remember, in Visual Studio main menu, select x86 .
-
1Create 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.
-
2Download 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.
-
3Download 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.
-
1Create 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..
- If it's the first time you open Visual Studio
. Click Create a new project
.
-
Add your Source file to the project.
- 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.
-
3Add 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 .
-
1Test 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.
-
2Correct 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.
- file with extension .h
- 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.
- In "Error List" if you see error about
-
Create Template. Go to Visual Studio main menu and, while GLFW64-GLAD-0 is open , click Project > Export Template... > in Choose Template Type , confirm "Project template" is selected. Click Next > .
- In Select Template Options , "Template name" should be GLFWx64-GLAD-0 .
- Click Finish .
- Template has been created. Close thrown window with template's path.
-
2Create 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 .
-
1Compiling 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.
-
2Create 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 .
-
3Download 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.31.2)", (or latest). In second "Platform" list (Binary distributions:), find (see image below) "Windows x64 ZIP" and click the beside entry cmake-3.31.2-windows-x86_64.zip (or latest). The unzipped folder ought to appear in a new File Explorer.
-
4Copy and unzip the zip folder.
- Open folder C:\GL.
- In the new File Explorer click folder cmake-3.31.2-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).
-
1Download 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.
-
2Download 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.
-
1Create 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..
- If it's the first time you open Visual Studio
. Open it > click Create a new project
.
-
Add your Source file to the project.
- 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.
-
3Add 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 .
-
1Test 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.
-
2Correct 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.
- file with extension .h
- 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.
- In "Error List" if you see error about
-
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.
-
2Create 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.
-
3TIPS: In every project you create with it, remember, in Visual Studio's GUI, select x64 (next to Debug).
Expert Q&A
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".Thanks
- 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 .Thanks
- 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 .Thanks