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.
Learn more...
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.
Steps
Configuring Visual Studio
-
1Highlight what you expect to do. Highlight step or sub-step or part of it and then do it. For example see picture above.
-
2Download Visual Studio 2022. If you have not done so, you can download it from https://www.visualstudio.com/downloads.
- Check the Desktop development with C++ workload box as you download. If necessary scroll down the page (see below image).
- Click "Language pack" and check "English" box.
- During installation, in "Personalize your Visual Studio experience" wizard, in "Development settings" menu, click "General" > click "Visual C++" > hit Start Visual Studio.
Downloading GLFWx32 and GLAD
-
1Create 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
-
2Download 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".
-
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.
- 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.
Creating Project GLFWx32-GLAD-0
-
1Create 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.
-
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.
-
2Add 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.
-
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.
Testing Project GLFWx32-GLAD-0 and Correcting errors
-
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, 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.
-
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 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.
Creating a Project with an GLFWx32-GLAD-0 Template
-
1Create 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.
-
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 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.
-
3Tips. When you create project with template, remember, in Visual Studio main menu, select x86.
Downloading GLFW x64 and GLAD
-
1Create 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.
-
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.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.
-
3Download 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.
Creating project for platform x64
-
1Create 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.
-
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.
-
2Add 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.
-
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.
Testing and Correcting project GLFWx64-GLAD-0
-
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, 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.
-
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 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.
- In "Error List" if you see error about
Creating Project with GLFWx64-GLAD-0 Template
-
1Create 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.
-
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 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.
Installing CMake
-
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 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.
-
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.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.
-
4Copy 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).
Downloading Source GLFW and GLAD
-
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". In opened wizard select Save File.
-
2Unzip 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.
-
3Download 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.
- 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.
Creating Project GLFWsrc-GLAD-0
-
1Create 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.
-
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.
-
2Add 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.
-
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 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.
Testing and Correcting project GLFWsrc-GLAD-0
-
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, 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.
-
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 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.
- In "Error List" if you see error about
Creating Project with GLFWsrc-GLAD Template
-
1Create 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 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.
-
3TIPS: In every project you create with it, remember, in Visual Studio's GUI, select x64 (next to Debug).