Setup OpenGL with VS Code

Being a game dev I always wanted to learn some basics of OpenGL, so going by the recommendation of my colleague I went straight to Learn OpenGL and its a really great place to start with. So, I started with the introductions and then setting up the environment to run OpenGl programs, and there i got stuck at a point. Well I am a big fan of VSCode, and the Learn OpenGL site only helps you in setting up your environment with Visual Studio. So, I started looking around, to find ways to run the hello world program in VSCode. It took me quite some time, but I did figure it out at last. And, tada

The Setup

  • GLFW: Now if you have read the getting started section of LearnOpenGL, then you know we also need GLFW, download the pre-compiled binaries from here.
  • GLAD: Similarly, download GLAD from this link. If you are downloading GLAD for first time, make sure you have set language to c/c++ and specification to OpenGL. In the API section set gl version 3.3 or above, profile to core and leave extensions empty. Tick the Generate a loader option and click on Generate.
  • Visual Studio Code and MinGW: Yes, of course we would need Visual Studio Code installed in our system. We would also need a c++ compiler, in this case we will use GCC. Follow the prerequisites section of this page step by step to setup the compiler and the c/c++ extension. Also, you should learn how to create the tasks.json file for the c++ project. This would come handy at later stage.

Organizing Workspace

Workspace preview

Now we will follow the Hello Window steps from LearnOpenGL and create our first script main.cpp, add it to the src folder (I like things organised 😊).

Hello World

"args": [
"-g",
"-std=c++17",
"-I./include",
"-L./lib",
"src/\\*.cpp",
"src/glad.c",
"-lglfw3dll",
"-o",
"${workspaceFolder}/myprogram.exe"
]

Now, goto VSCode menu, select Run/Run Without Debugging and voila you should see a blank window popup appear just like the image below

opengl hello world preview
opengl hello world preview

Congratulations!! You are now all setup to dive in OpenGL world with VSCode. You can also find the whole source code at this repo

Doing insignificant things, hoping they become significant one day.