I am trying to setup visual studio code for opengl development. I already have it working for plain c/c++ development I am now trying to add in opengl development to the mix. I know how to setup opengl on other platforms (i.e. Eclipse, Xcode, Visual Studio, CodeBlocks). The root of my problem is more how to setup dependencies in visual studio code. My best guess would be running a task in the task.json file. Right now it is just filled with the code to compile the project every time I run the program.
In Visual Studio, right-click on your project, and select "Open Folder in File Explorer...". A folder will appear that contains the files for your project. Drag the openGL files from the folder you created in step 1, into this folder.
Windows comes with OpenGL, and Visual Studio comes with the OpenGL libraries, but neither of them comes with GLUT. Get the newest version of GLUT here: GLUT 3.7. 6 for Windows.
1.2 Writing Your First OpenGL ProgramCreate a new C++ project: Select "File" menu ⇒ New ⇒ Project... ⇒ C/C++ ⇒ C++ Project ⇒ Next. In "Project name", enter " Hello " ⇒ In "Project type", select "Executable", "Empty Project" ⇒ In "Toolchain", select "Cygwin GCC" or "MinGW GCC" (depending on your setup) ⇒ Next ⇒ Finish.
Came across the same problem. Note that there are two issues here:
launch.json
and tasks.json
files?
tasks
in greater detail.The main issue for me was that I am on MAC and many explanations were only targeted at Linux and Windows (which don't have the framework
parameter) or they explain how to set it all up in the Xcode GUI.
As this Github Gist and this StackOverflow post both suggest:
<gl/*>
(e.g. Mac has <OpenGL/*>
for part of it, and <GLUT/*>
for glut files)framework
to your build arguments (to include external libraries), e.g...
gcc -o ex1 ex1.c -framework GLUT -framework OpenGL -Wno-deprecated
cc <your_file.c> -framework GLUT -framework OpenGL
frameworks
to your C/C++ extension settings and/or tasks.json
as well(and again: it would be very similar when using clang
or clang++
)
Integrate that insight with the official documentation on C/C++ tasks
, and it's all done! :)
The above is just a shorter version of my overall journey, detailed below:
<gl/*>
(e.g. <OpenGL/*>
for core files and <GLUT/*>
for glut files).OpenGL
and other libraries via the framework
flag. frameworks
to your C/C++ extension settings as well-Wno-deprecated
)brew install glew
and brew install glfw
and/or whatever other external libraries you use.The VSCode setup is mostly the same. Make sure that, once you have setup the C/C++ extension correctly, to look at the documentation for your environment, which are at the bottom of the official "C/C++ for Visual Studio Code" documentation page.
However, the bigger problem is usually how to get it to compile. I don't have recent examples or experiences of compiling on non-MAC systems; but here are some relevant references:
Apparently cross-platform development still might cause some headaches, according to this (as of yet) open github issue #1083.
I also found an example by someone taking a jab at OpenGl cross-platform compilation using VSCode here. You might want to check out their entire .vscode/
folder (if not their entire project setup).
These days, it's very easy to add any amount of Launch (Run and/or Debug) configurations to the built-in Launch + Debugger UI by following these instructions.
Before the debugger UI was a thing (or at least before I noticed it), you could install the Code Runner extension, you will get a neat little "Run Code" button at the top right (or Command+Alt+N
).
This works fine if you just want to use it to run a single executable. If you want to run individual files individually, it gets a bit harder. I have not tried it, but as they suggest, for that, you could use a special file naming pattern, i.e. a glob pattern (e.g. *.gl.cpp
) and use the code-runner.executorMapByGlob
setting to have different compile+run parameters based on file names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With