I have a basic Visual C++ environment in Visual Studio Code. I've recently started to read about OpenGL and have been trying to set up GLEW and GLFW in VS Code. Almost all of the tutorials I find fall into one of the 2 categories:
- GLEW and GLFW setup with MSVC, but in Visual Studio.
- GLEW and GLFW setup in VS Code, but with minGW.
I've read the documentation for MSVC command line and its options a few times and can't figure it out. I'm not familiar with Cmake and such, so I've been trying to do it via VS Code tasks.json file.
My tasks.json file is as follows:
{
"version": "2.0.0",
"tasks": [
// BUILD TASK
{
"type": "shell",
"label": "C/C++: build project",
"command": "cl.exe",
"args": [
// exception handling args
"/EHsc",
// including additional headers
"/I${workspaceFolder}\\include\\glew\\include",
"/I${workspaceFolder}\\include\\glfw\\include",
// obj files path
"/Fo${workspaceFolder}\\bin\\",
// exe file path
"/Fe:", "${workspaceFolder}\\bin\\program.exe",
// source files
"${workspaceFolder}\\src\\*.cpp",
// library files
"opengl32.lib",
"${workspaceFolder}\\include\\glew\\lib\\Release\\x64\\glew32s.lib",
"${workspaceFolder}\\include\\glfw\\lib-vc2019\\glfw3.lib"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
}
},
// CLEAN TASK
{
"type": "shell",
"label": "C/C++: clean project",
"command": "del",
"args": [
"${workspaceFolder}\\bin\\*",
],
"options": {
"cwd": "${workspaceFolder}"
}
}
]
}
And my main.cpp file has a few lines of code to open a window.
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
using namespace std;
int main()
{
if (!glfwInit())
{
cout << "Failed to initialize GLFW" << endl;
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window;
window = glfwCreateWindow(1000, 700, "Test window 01", NULL, NULL);
if (window == NULL)
{
cout << "Failed to open GLFW window" << endl;
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = true;
if(glewInit() != GLEW_OK)
{
cout << "Failed to initialize GLEW" << endl;
return -1;
}
}
Full terminal output while running build task at this pastebin