This tutorial is applicable to Windows 64 bit operating system
Install VScode:
Download from the official website
VSCode detailed installation tutorial
After installing VScode, start configuring the C + + environment
Install LLVM:
Download LLVM
Turn down the page, find this line, and click windows (64 bit)
After downloading, click next to customize the installation address (remember your installation address) and add it to the environment variable
Installation of MinGW:
Download MinGW
Page down to find x86_64-win32-seh, downloading requires additional methods or patience
After downloading, unzip and paste all the unzipped things into the previous LLVM installation path. You will find that the names of the folders are consistent and the contents do not conflict.
Detect environment variables
Open command line
Enter clang -v
gcc -v
Normal after similar information appears
If xxx is neither an internal or external command nor a program, you need to add an environment variable
Right click my computer - properties - advanced system settings - environment variables - click PATH - Edit - New - under the system variable to fill in the bin folder under the LLVM installation directory, similar to the following
VScode running C + + program Hello World
Check whether VScode can run ordinary C + + programs
VScode installation plug-in code runner, C++ Extension Pack
Then create the file and save it as a C + + file
Write a hello world
#include <iostream> using namespace std; int main() { cout << "Hello, World!"; return 0; }
Click Run in the upper right corner to output hello world
Add openGL related components
openGL Component download
When trying to install openGL, I have seen countless error reports and collected various methods. This is an integrated simplified version after eliminating multiple error reports, so I don't know what is really useful (basically adding one thing at a time), but it can be used together (wonderful)
After downloading and decompressing, you can see five folders
-
Open the installation directory of LLVM
Unzip and paste the bin, include and lib folders in the compressed package into the corresponding bin, include and lib folders under the LLVM directory -
Open C:\Windows\System32 and C:\Windows\SysWOW64
Paste the contents of System32 and SysWOW64 in the compressed package into the above folder respectively -
Create a folder to write openGL projects anywhere
Paste the. vscode folder in the vscode configuration folder in the compressed package into the above folder
Test openGL under VScode
Open VScode, file - Open Folder - select the folder just created to write openGL project, create a new file - save as a C + + file, and draw a triangle
#define FREEGLUT_STATIC // Define a static library for calling functions #include <GL/freeglut.h> // Include the header file void renderScene(void) // Function for geometric creation { // Clear the buffer to the predefined color and depth value glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Move origin of current user coordinate system to the screen center: similar to a reset operation glLoadIdentity(); glBegin(GL_TRIANGLES); // Start draw TRIANGLE function glVertex3f(-0.5, -0.5, 0.0); // Set coordinates of first vertex glVertex3f(0.5, 0.0, 0.0); // Set coordinates of second vertex glVertex3f(0.0, 0.5, 0.0); // Set coordinates of last vertex glEnd(); // End draw TRIANGLE function glutSwapBuffers(); // Refresh the screen to display the graphics } int main(int argc, char* argv[]) // Standard main function { glutInit(&argc, (char**)argv); // Initialization // Define display mode: depth buffer, double buffer and RGBA color glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100, 100); // Define the location of the window glutInitWindowSize(320, 320); // Define the size of the window glutCreateWindow("Hello OpenGL"); // Create a window called "Hello OpenGL" glutDisplayFunc(renderScene); // Set the first function glutMainLoop(); // Enter the GLUT event processing loop return 0; // Return an integer value }
Click the triangle in the upper right corner to run, or right-click the code area and select run code to finish
summary
In most cases, it is OK to follow the online tutorial step by step. If an error is reported halfway, it can be solved by directly searching the error content.
But there are some problems that cannot be solved by direct search. At this time, you need to use your brain
For example, after running test.cpp according to the online tutorial at the beginning, there was an error that cannot find -lglut32. Search for the error and no solution was found. However, it can be found that there is a lack of glut32.lib library file, so directly search glut32.lib and download it and put it in the Lib file folder to solve the problem
reference resources:
VSCode detailed installation tutorial
Configuring the C + + environment in vscode (clang compiler) fool Configuration Wizard
OpenGL program running prompt glut32.dll missing problem