Thank you for visiting the page for my C++ & OpenGL visual studio code project setup. As the title says this is a setup, there is nothing special about this project other than that you can use it to have a base in OpenGL programming.
Thanks to Guylian Gilsing for creating this template. This template has been modified to work with mingw-w64 and 64 bit libraries. It is highly advised you check that the MingW type and version are compatible with libraries that you are including. If in doubt that this modified template will work with your install, do check the original template and fork it.
Warning: this readme file does assume that you have some experience with Visual Studio Code, g++ and OpenGL programming.
- Introduction
- Prerequisites
- Directory Layout
- Building
- Running
- Executable
- Debug Mode
- Library Versions
- Helpful links
As you may know by now this project is a setup, you need to have Visual Studio Code installed before you can actually run this in the way I have intended it to.
NOTE: Visual studio code is not required since you can use the g++ to run the project, all visual studio code does for you is a give an environment in which you can write, run and build your code.
The following extensions are needed:
- C/C++ (Microsoft)
This project compiles using the g++ command, on Windows computers this means that you need to have the MinGW Instalation Manager installed, from there you can install the following packages:
- mingw32-gcc-g++
These can all be accessed from the Basic Setup tab of the installer.
When these packages are installed you need to add the directory where the g++ command is located to your PATH variable.
when all of that is finished you should be able to run the project.
The project directory is layed out like this:
- .vscode
- builds
- dependencies
- src
- shaders
this directory houses the visual studio code project setup and options. in here you can add your own files to the build process (tasks.json) and edit your include path (c_cpp_properties.json)
this directory houses platform specific builds, the current supported builds are Windows and Linux.
This folder contains all of the libraries that your project may use, it loads in and sets up the following libaries:
- GLFW
- GLAD
- GLM
The main layout of this directory is a folder with the name of the dependency in UPPERCASE with the library contents located within that folder.
Any other dependencies that you may want to add need to be added to the build process (.vscode/tasks.json)
This folder contains all of your source code files ( for example, .cpp and .h files). it also houses your glsl shaders (src/shaders)
The src folder also provides you with 3 .cpp and 2 .h files, these are:
- main.cpp
- engine.cpp + engine.h
- shader.cpp + shader.h
engine.cpp + engine.h
These files are your main files from where you can write your code. It gives you some functions in which you can do some initialization, input, update and render logic.
shader.cpp + shader.h
This file is a basic shader class in which you can load your shaders.
Sample Code:
Shader basicShaderProgram;
// Set vertex and fragment shader, then compile it to a program
basicShaderProgram.setVertexShader("src/shaders/basicVertexShader.glsl");
basicShaderProgram.setFragmentShader("src/shaders/basicFragmentShader.glsl");
basicShaderProgram.compile();
// Bind the shader
basicShaderProgram.use();
Note: This project does not include .glsl shader files into the executable, this is up to the developer and this project does not provide the tools or functionality to do that.
To build your project you use the default building hotkey of Visual Studio Code (CTRL + SHIFT + BUILD), if your build hotkey is different please check within Visual Studio Code which combination it is.
Executable
To run you project you first need to build your project and then execute the .exe file located within your builds/[PLATFORM] folder.
Note: This project does not include .glsl shader files into the executable, this is up to the developer and this project does not provide the tools or functionality to do that. In order to run the executable successfully you need to create the following folders within your builds/[PLATFORM] folder: src/shaders/[YOUR_SRC/SHADERS_FOLDER_CONTENTS]. after that just paste the contents of your shader folder, that is located in the src folder, into the newly created folder structure.
Debug Mode
To run the project in debug mode you use the default debug hotkey of Visual Studio Code (CTRL + F5), if your debug hotkey is different please check within Visual Studio Code which combination it is.
- GLFW (Version 3.3.bin.win32)
- GLAD (gl: 4.6, profile: Core, extensions: none)
- GLM (Version 0.9.9.6)
This whole setup works on the latest version of Visual Studio Code as of 29-12-2019, which is version 1.14.1 (user setup)