Just a small guide line for using Visual Studio Code, MSYS2 and OpenGL on Windows. Have also a look at some nice instruction on GitHub C++ & OpenGL VSCode Setup or at some other good instruction Setup OpenGL with VS Code which has also a nice template on GitHub opengl-cpp-template.

Install Visual Studio Code

 Have a look at the Setting up Visual Studio Code page to download and install the latest VSCode for your particular platform.

 

Install Extensions

For a basic setup there is only one needed extension: C/C++ for Visual Studio Code

 

c_cpp_properties.json

For the Visual Studio Code environment. It has includePath for adding header files.

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\msys64\\usr\\include\\**",
                "C:\\msys64\\mingw32\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\msys64\\usr\\bin\\gcc.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

 

task.json

For the g++ compiler. Has args to set the include- and library paths.

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\msys64\\usr\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-ID:\\VSC-Projects\\opengltest",
                "-IC:\\msys64\\usr\\include\\**",
                "-IC:\\msys64\\mingw32\\include",
                "-LC:\\msys64\\mingw64\\lib",
                "-lopengl32",
                "-lfreeglut",
                "-lglew32",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:\\msys64\\usr\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: C:\\msys64\\usr\\bin\\g++.exe"
        }
    ]
}

launch.json

 

Debug error in VS Code

 If you get a debug error with a message like that:

Unable to 'main.cpp': File not found (file:///c/Users/.../main.cpp)

add sourceFileMap to launch.json file.


"sourceFileMap": {
    "/c": "C:/"
}

https://github.com/Microsoft/vscode-cpptools/issues/1546#issuecomment-365368570

Install MSYS2

 First follow the steps for installing MSYS2 shown on the project page: MSYS2-installation

Package Management

Searching for packages: pacman -Ss <name_pattern>

Installing new packages: pacman -S <package_names|package_groups>

Removing packages: pacman -R <package_names|package_groups>

Use OpenGL

 

 

Use olcPixelGameEngine

 

 

Comments powered by CComment