This project template is designed for OpenGL development on Linux, specifically tested on Windows running WSL (Windows Subsystem for Linux) with Ubuntu. However, it should work on any Ubuntu-based distribution with the required libraries installed.
- Setting Up WSL on Windows
- Installing Required Libraries on Ubuntu
- Setting Up VS Code
- Running the Project
- Project Configuration
- Git Configuration
- Disclaimer
If you're using Windows, follow these steps to install WSL and set up Ubuntu:
-
Open PowerShell or Command Prompt in administrator mode (right-click and select "Run as administrator").
-
Run the following command to install WSL and the Ubuntu distribution of Linux:
wsl --install
-
After the installation is complete, restart your machine.
For more information, visit the official WSL documentation:
https://learn.microsoft.com/en-us/windows/wsl/install
To run and compile the OpenGL project, you need to install the following libraries:
sudo apt update
sudo apt install build-essential libglew-dev libglfw3-dev libgl1-mesa-devThese commands will install:
libglew-dev(for GLEW)libglfw3-dev(for GLFW)libgl1-mesa-dev(for OpenGL)
You also need GCC with C++17 support, which is included in the build-essential package.
This section covers how to set up Visual Studio Code for C++ development and to use it with WSL (Windows Subsystem for Linux).
Before running the project, you need to install the C++ extension for Visual Studio Code, which provides support for debugging, IntelliSense, and more.
- Open VS Code.
- Press
Ctrl+Shift+Xto open the Extensions panel. - In the search bar, type C++ and install the C/C++ extension by Microsoft (it should be the first result).
- Once installed, you will have support for IntelliSense, code navigation, and debugging in C++.
To set up Visual Studio Code to work with WSL, follow these steps:
-
Install Visual Studio Code: Download and install VS Code from https://code.visualstudio.com/.
-
Install the WSL Extension:
- Open VS Code.
- Press
Ctrl+Shift+Xto open the Extensions panel. - Search for and install the Remote - WSL extension (official Microsoft extension). This extension allows you to open folders in WSL directly from VS Code.
-
Access WSL in File Explorer:
- Open File Explorer in Windows.
- In the sidebar, you should see Linux (under Quick Access) with the name of your Ubuntu distribution. If it's not there, you can manually access it by navigating to:
\\wsl.localhost\Ubuntu
(This assumes you installed the default Ubuntu distribution using
wsl --install). -
It’s good practice to navigate to your home directory inside the WSL filesystem. This is usually located at:
\\wsl.localhost\Ubuntu\home\<your-username>
You can create a Documents folder, a vscode folder, or any directory of your choice where you can store your projects.
To compile and run the project, follow either of the two methods below:
- Open VS Code in your project folder.
- Install the C++ Extension (see instructions above if you haven't done so already).
- Select a source file (e.g.,
main.cpp). - Click the Run button on the top right (the play icon).
- Select Run ProjectName from the drop-down menu.
- Open VS Code in your project folder.
- Press
Ctrl+Shift+Bto run the build task. This will compile the project using the build configuration specified in thetasks.jsonfile. - After the project builds successfully, press
F5to start debugging or run the project.
This template is specifically made for VS Code and includes .vscode configuration files for build and debugging.
After cloning this repository, make sure to replace the placeholder ProjectName with your own project name in the following files:
-
.vscode/launch.json:"name": "Run ProjectName" "program": "${workspaceFolder}/ProjectName"
-
.vscode/tasks.json:"-o ProjectName" (In the g++ command for the build task)
-
main.cpp:Window window(800, 600, "ProjectName"); // Change the window title
-
.gitignore:Replace
ProjectNamewith the name of your executable to ignore it during Git operations.
When using Git for your project, you may want to exclude your .vscode folder. Add the following line to your .gitignore file:
.vscode/This will prevent VS Code-specific settings from being pushed to your repository.
I am not a professional developer but someone who struggled to get C++ projects running on Windows using VS Code. After some trial and error, I found this setup to work well and decided to share it. Hopefully, it helps others in a similar situation!