Setting up OpenGL and Creating a Window - hls333555/OpenGL GitHub Wiki
GLFW is a library which provides appropriate platform layers - the implementation of the window creation and management for Windows, MacOS and Linux. All it's going to do for us is to create a window, create a OpenGL context and give us access to some basic things like input.
Here are the main steps:
-
Download GLFW precompiled binaries from GLFW (If your application is being built for Win64/x64, choose 64-bit Windows Binaries, otherwise choose 32-bit one)
-
Create a vs project, add a "Dependencies" folder into your solution directory, inside which create a "GLFW" folder and copy include folder and lib folder from the downloaded content here
-
Create a cpp file named "Application", copy and paste the example code from GLFW Documentation
-
Open the project property window
- Make sure Configuration is set to All Configurations and check the Platform setting next to it
- Add include path to Additional Include Directories (the path should look like this
$(SolutionDir)Dependencies\GLFW\include
) - Add lib path to Additional Library Directories (the path should look like this
$(SolutionDir)Dependencies\GLFW\lib-vc2019
) - Remove all contents in Additional Dependencies and Add
glfw3.lib
to it (we use static linking here and below)
-
When we compile this file, no error occurs; however if we build(compile and link) the project, a bunch of link errors appear
-
Let's address the issue related to glClear first. Basically, what linker is trying to do is to find a definition for that glClear function which is inside OpenGL library files. We have to link that - add
opengl32.lib
to Additional Dependencies, now the glClear issue should go away -
For the remaining platform specific issues, you can copy the function signature name for short and search it online, for example, "RegisterDeviceNotificationW", you will find library requirements for this function in MSDN pages like this:
Add that to Additional Dependencies and the related issues should go away
-
-
After fixing all other issues using the above method, you will see a black window like below when you run the program: