This guide will help you set up a modern, portable C++ OpenGL development environment using FreeGLUT, TDM-GCC, and Visual Studio Code on Windows.
- Prerequisites
- FreeGLUT Installation
- Project Structure
- VS Code Configuration
- Building and Running
- Sample Code
- Troubleshooting
- References
| Screenshot | Demo |
|---|---|
![]() |
![]() |
- TDM-GCC (or MinGW-w64) installed (64-bit recommended)
- Visual Studio Code installed
- C/C++ extension for VS Code (by Microsoft)
- FreeGLUT MinGW package (Download here)
-
Download the latest FreeGLUT MinGW package from TransmissionZero.
-
Extract the ZIP archive.
-
Copy header files:
- From:
freeglut\include\GL\* - To:
C:\TDM-GCC-64\include\GL\ - Files to copy:
freeglut.hfreeglut_ext.hfreeglut_std.hglut.h
- From:
-
Copy library files:
- From:
freeglut\lib\x64\libfreeglut.a - To:
C:\TDM-GCC-64\lib\
- From:
-
Copy DLL file:
- From:
freeglut\bin\x64\freeglut.dll - To:
C:\TDM-GCC-64\bin\ - Do NOT copy to
C:\Windows\System32\unless you want it globally available (not recommended).
- From:
your-project/
├── .vscode/
│ ├── c_cpp_properties.json
│ └── tasks.json
├── build/
├── src/
│ └── main.cpp
└── README.md
{
"version": 4,
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/src",
"C:/TDM-GCC-64/include",
"C:/TDM-GCC-64/include/c++/10.3.0",
"C:/TDM-GCC-64/include/c++/10.3.0/x86_64-w64-mingw32",
"C:/TDM-GCC-64/x86_64-w64-mingw32/include",
"C:/TDM-GCC-64/include/GL"
],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"compilerPath": "C:/TDM-GCC-64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
]
}This setup allows you to:
- Build the currently open C++ file (
${file}) - Output the executable to
build/ - Automatically run the executable after building
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Active C++ File (FreeGLUT)",
"type": "shell",
"command": "g++",
"args": [
"${file}",
"-IC:/TDM-GCC-64/include",
"-LC:/TDM-GCC-64/lib",
"-lfreeglut",
"-lopengl32",
"-lglu32",
"-o",
"${workspaceFolder}/build/${fileBasenameNoExtension}.exe"
],
"group": "build",
"problemMatcher": ["$gcc"]
},
{
"label": "Run Executable",
"type": "shell",
"command": "${workspaceFolder}/build/${fileBasenameNoExtension}.exe",
"dependsOn": "Build Active C++ File (FreeGLUT)",
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new"
}
},
{
"label": "Build and Run",
"dependsOn": ["Build Active C++ File (FreeGLUT)", "Run Executable"],
"dependsOrder": "sequence",
"problemMatcher": ["$gcc"]
}
]
}-
To build and run:
PressCtrl+Shift+P→ "Tasks: Run Task" → select Build and Run. -
To build only:
PressCtrl+Shift+B(default build task). -
The output executable will appear in the
build/folder.
Try this minimal FreeGLUT test:
#include
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutCreateWindow("FreeGLUT Test");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}Compile with:
g++ -o test.exe test.cpp -lfreeglut -lopengl32If you see a window pop up, your setup is working!
-
No window appears:
Ensurefreeglut.dllis inC:\TDM-GCC-64\binor the same folder as your.exe. -
Header not found:
Check that all header files are inC:\TDM-GCC-64\include\GL\. -
Linker errors:
Ensurelibfreeglut.ais inC:\TDM-GCC-64\lib\and you are linking with-lfreeglut -lopengl32 -lglu32. -
IntelliSense not working:
Check yourc_cpp_properties.jsonpaths.
- FreeGLUT for Windows (TransmissionZero)
- TDM-GCC Compiler
- OpenGL/GLUT Programming Guide
- VS Code C++ Extension
Happy Coding!
If you run into any issues, double-check your paths and library files, or ask for help!
- I added GLFW aslo similar way include to include, lib to lib, and dll to bin

