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
To run OpenGL with VSCode we would need couple of things to setup, but if you want to skip through the whole setup, you can just head over to the end of this article and get the repo, clone it and get started. Else, just hear me out, how did I manage to pull it through.
- 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.
Now, we have everything we need, so, we need to create a cpp workspace in VSCode, if you are doing this for first time follow the “Hello World” section of this page. Make sure you also know how to create a tasks.json file for cpp project, if not then you can check this link. Now we would add all the files we downloaded in previous steps to our workspace.
At this point your cpp workspace should look like this.
The final step, in your tasks.json update your “args” field with the following code
Now, goto VSCode menu, select Run/Run Without Debugging and voila you should see a blank window popup appear just like the image below
Congratulations!! You are now all setup to dive in OpenGL world with VSCode. You can also find the whole source code at this repo