How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio

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...
Method 1 of 7:

Downloading GLFW and GLAD

  1. How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio Picture 1How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio Picture 1
    Highlight what you expect to do. For example see picture above.
  2. Create folder GL. In directory (disk) C:, right click > select New > Folder > type GL > hit Enter.
    1. In folder GL create folder with name glad.
  3. Download GLFW. 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.bin.WIN32" or latest version.
    1. Click it > right click > select Copy.
    2. Navigate to C: > GL > right click > select paste.
    3. Click on "glfw-3.3.bin.WIN32" and rename to glfw.
    4. Now in "GL" folder you have two folders: glad and glfw.
  4. How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio Picture 2How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio Picture 2
    Download GLAD. 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.
    1. In the "Glad" window, click "glad.zip", (see picture above).
    2. After download, in downloading window you have two zip folders: include and src.
    3. Click folder include > right click > Copy.
      1. Navigate to C: > GL > glad. In glad folder right click > select Paste.
    4. (Alternatively click folder include and drag into folder glad, at C:GLglad).
    5. Go back to downloading window > click folder src > right click > Copy.
      1. Navigate to C: > GL > glad. In glad folder right click > select Paste.
    6. (Alternatively click folder src and drag into folder glad, at C:GLglad).
    7. Now in folder glad you have two (unzipped) folders: include and src.
Method 2 of 7:

Creating a Visual Studio Project

  1. Create an empty project.
    1. With Visual Studio 2017
      1. In V.S. main menu, click File. Then go to New > Project…
      2. In the left part of the new project window, click Visual C++ if it is not clicked.
      3. In the center of the screen click Empty Project.
      4. Below that, find the Name text box, type Project-0.
      5. Next to Location text box, click Browse... and navigate to C: > GL. Folder's name should be GL.
      6. Click Select a folder. The Location in New Project window is C:GL.
      7. Make sure the Create directory for solution box is not checked.
      8. Click OK.
    2. With Visual Studio 2019
      1. If it's not opened. Open it > Click Create a new project > Empty Project > Next.
      2. In "Project name" text field type: Project-0. Next to "Location" text field click ....
      3. Navigate to C: > GL. Folder's name should be GL. Click Select folder. Now "Location" is C:GL.
      4. Check "Place solution and project in the same directory" > click Create.
      5. Wait till Visual Studio 2019 instance appears.
      6. If it's opened. Click File > New > Project… > Empty Project > Next. The rest as above.
  2. Add your source file to the Project.
    1. In the "Solution Explorer" window, right click the Source Files entry (the last one).
    2. Click Add > New Item… In the Add New Item - Project-0 wizard, click C++ File (.cpp) (the first one) from the middle of the window. In the Name text box leave Source.cpp.
    3. The Location is C:GLProject-0.
    4. Click the Add button. The file will open in the main text editor but leave the file blank for now.
Method 3 of 7:

Installing GLFW and GLAD in the Project

  1. Add file glad.c. Go to Visual Studio > Solution Explorer > right click Source Files > click Add > Existing Item ... .
    1. Navigate to C: > GL > glad > src > glad.c > click glad.c. "File name" should be glad.c. Click Add.
  2. How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio Picture 3How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio Picture 3
    Configure Project-0 Property Pages. In Solution Explorer, right click on the name of your project, that is Project-0, and select Properties. Select Configuration: Active(Debug), Platform: Active(Win32).
    1. (1) Additional Include Directories. Open C/C++ drop-down menu. Click General > Additional Include Directories. > the down arrow at the right of the field > click in the drop down menu.
      How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio Picture 4How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio Picture 4
      1. Copy C:GLglfwinclude > in Additional Include Directories wizard click first icon > paste.
        How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio Picture 5How to Set Up OpenGL‐GLFW‐GLAD on a Project with Visual Studio Picture 5
        .
      2. Copy C:GLgladinclude > in Additional Include Directories wizard click first icon > paste.
      3. On Additional Include Directories wizard click OK.
    2. (2) Additional Library Directories. Open the Linker drop-down menu, and click General. Click Additional Library Directories entry > down arrow at the right of the field > click in the drop-down menu.
      1. In "Additional Library Directories" wizard click first icon > ....
      2. Navigate to C: > GL > glfw > lib-vc2019 or the latest. In the "Select Directory" window, the "Folder" should be "lib-vc2019" or the latest. Click Select folder.
      3. In "Additional Library Directories," click OK.
    3. (3) Additional Dependencies. In Linker drop down menu click "Input". Click Additional Dependencies entry > the down arrow at the right of the field > in the drop-down menu.
      1. Copy opengl32.lib; glfw3.lib; glfw3dll.lib and paste on the top-most text box of the Additional Dependencies wizard. Click OK in the Additional Dependencies wizard.
    4. (4) Set Linker "SubSystem" to "Console". In the Linker drop-down menu, click System > SubSystem > click the down arrow at the end of the field > select Console(/SUBSYSTEM:CONSOLE) from the dropdown menu > click Apply, then OK on the Project Property Pages wizard.
  3. 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 Source.cpp code area > hit Ctr+F5, and wait... Two windows should appear: One black and other with name "LearnOpenGL" and inside an orange triangle.
    1. If only the black window (the console) appears with message: "Failed to create GLFW window", set up is okay, function glfwCreateWindow did not work.
  4. Correct any errors. In "Error List" if you see error about
    1. file with extension .h go to part (Method) 3, step 1, "Configure the "Additional Include Directories"" and follow instructions.
    2. file with extension .lib go to part (Method) 3, step 2, "Configure the linker "Additional Library Directories"", and follow instructions. Also to step 3, "Configure the linker "Additional Library Directories"".
    3. "entry point must be defined" go to step 4, Set linker "SubSystem" to "CONSOLE" and follow instructions.
    4. file glad.c go to step 5, and follow instructions.
    5. For other errors, if you cannot correct them, close Visual Studio > delete project folder Project-0 which lives in C:GL > open Visual Studio > repeat set up from part Method 2. Good job.
Method 4 of 7:

Creating a Project with an OpenGL-GLFW-GLAD Template

  1. Create Template. Go to Visual Studio main menu and, while Project-0 is open, click Project > Export Template.... On Export template Wizard check Project Template, if it's not checked. Click Next >. On Select Template Options, in Template name text box type: OpenGL-GLFW-GLAD. Click Finish. The Template has been created.
  2. Create Project.
    1. With V.S. 2017. Click File > New > Project....
      1. On the New Project window, click template: OpenGL-GLFW-GLAD.
      2. In Name text field, type: Project-1.
      3. Location should be C:GL. If it's not, click Browse > navigate C:GL > Folder's name should be GL > click Select a folder.
      4. Be sure Create directory for solution is unchecked. Click OK.
    2. With V.S. 2019. Click File > New > Project....
      1. In Create a new project wizard scroll down the list of templates and select OpenGL-GLFW-GLAD > click Next.
      2. In Configure your new project wizard, in "Project name" text field type Project-1.
      3. Location should be C:GL. If it's not, click ... > navigate C:GL > Folder's name should be GL > click Select a folder.
      4. Be sure Place solution and project in the same directory is checked. Click Create.
    3. Type or paste a new code in Source.cpp. Run the program. Good job.
Method 5 of 7:

Creating Project to target x64 Platform

  1. Download GLFW. Right click on following address and select Open Link in New Window https://www.glfw.org/download.html, click 64-bit Windows binaries. You get "glfw-3.3.bin.WIN64" or latest version. The rest as above but with following step.
  2. Project's Property Pages main settings. Go to "Solution Explorer" > right click on the name of your project > select "Properties". In Platform: entry, choose x64 > Click Configuration manager...
    1. In Active solution platform: select x64
    2. In Platform entry, x64 is automatically selected.
    3. Click Close
    4. Tip: Even if in Property Pages main settings it is Platform: x64, click Configuration manager... and in Active solution platform: select x64.
  3. Create template. As above.
    1. TIP: In every project you create with it, select x64 (next to Debug) in Visual Studio's GUI.
Method 6 of 7:

Setting up GLFW built by CMake, and GLAD

  1. Build GLFW by CMake and Visual Studio, and set up in project. Right click on following link and select Open Link in New Window Use CMake to Get Binaries from Source Code. Follow it, but ...
    1. Before Method 3 (Testing Binaries), download GLAD according to present article's Method 1, step 4.
    2. In Method 3 (Testing Binaries), after step 2, add glad.c file: Go to Visual Studio > Solution Explorer > right click Source Files > click Add > Existing Item ....
      1. Navigate to C: > GL > glad > src > glad.c > click glad.c. "File name" should be glad.c. Click Add.
      2. In Solution Explorer, below Source Files you should see two files: glad.c and Main.cpp.
    3. In same Method (3), in step 3 Configure project's Properties, sub-step (2) Additional Include Directories, after configuring C:GLglfwinclude, copy C:GLgladinclude and, in Additional Include Directories wizard, click first icon > paste > click OK.
    4. Test your project and correct errors if any. In present article follow Method 3, steps 3 and 4.
  2. Create template. As above.
    1. TIP: In every project you create with it, select x64 (next to Debug) in Visual Studio's GUI.
Method 7 of 7:

Choosing Set Up

  1. In this tutorial you learn 3 was to set up GLFW and GLAD in Project with Visual Studio.
    1. Set up binaries x86 (32 bits). It's the easiest. You should start learning set up from here.
    2. Set up binaries x64 (64 bits). It targets x64 platform. Choose it only when you have specific reason for doing so.
    3. Compile GLFW source, and set up, together with GLAD, in project. Targets x64 too.The most difficult. The best though.
3.8 ★ | 38 Vote