Cltools-glew-libgltools. a About the related files above upload cloud disk link:Pan.baidu.com/s/1KhL1xN4W…# 2, create project text and text teaching hand in hand!

Check whether the environment is ok to clear the code block automatically generated by main. CPP, and then copy the following code directly run

#include "glshaderManager. h" /* glshaderManager. h file moves GLTool shaderManager class. Without shaders, we can't do shaders in openGL. The shader manager not only allows us to create and manage shaders, but also provides a set of 'store shaders', */ #include "gltools. h" /* gltools. h file contains most of the separate C-like GLTool functions */ #include <GLUT/ glut.h > /* #include <GLUT/ glut.h > on Windows and Linux, we use the static library version of freeglut and need to add a macro */ / to define a shaderManager GLShaderManager; // A simple batch container is a simple container class of GLTools GLBatch triangleBatch; /* Create a new window, create a new window, create a new window, create a new window, create a new window */ void changeSize(int w,int h) {// the x and y parameters represent the coordinates of the lower left corner of the view in the window. GlViewport (0, 0, w, h); } /* The glutDisplayFunc function is called when the screen changes or renders actively. This function is used to render data to the screen. Void RenderScene(void) {// void RenderScene(void) {// void RenderScene(void) {// void RenderScene(void) { The red, green, blue, and alpha components are usually referenced together as color caches or pixel caches. More than one buffer in OpenGL (color cache, depth cache, and template cache) clears the cache to preset values: GL_COLOR_BUFFER_BIT: indicates the currently active buffer for color writing GL_DEPTH_BUFFER_BIT: indicates the depth buffer GL_STENCIL_BUFFER_BIT: indicates the template buffer */ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); //2, set color GLfloat vColor[] = {1.0,1.0,0.0,1.0f}; GLT_SHADER_IDENTITY shader: Using the specified color on the screen in a cartesian coordinate system by default rendering geometry shaderManager. UseStockShader (GLT_SHADER_IDENTITY vColor); //4, submit the shader triangleBatch.draw (); /* When we set up the openGL window at the beginning, we specified that we want a double buffer rendering environment. This means that the rendering will be done in the background buffer and then swapped out to the foreground. This prevents the viewer from seeing the rendering process that might be accompanied by flicker from animation frame to animation frame. The buffer switching platform will proceed in a platform-specific manner. */ glutSwapBuffers(); } /* Custom function trigger condition: active call processing business in main function: Void setupRC() {//1, set the background color glClearColor(0.98f, 0.4f, 0.7f, 1); / / 2, initializing render manager shaderManager InitializeStockShaders (); / / 3, specify the vertices of the triangle coordinate GLfloat vVerts [] = {0.5 f to 0.0 f to 0.0 f to 0.5 f to 0.0 f to 0.0 f to 0.0 f to 0.5 f to 0.0 f,}; // using the GLBatch triangleBatch class, say the data to the shader trianglebatch.begin (GL_TRIANGLES, 3). triangleBatch.CopyVertexData3f(vVerts); triangleBatch.End(); } public void glutInit(&argc, argv) {public void glutInit(&argc, argv); GLUT_DOUBLE ': a double buffer window, in which a drawing command is actually executed off the screen cache and then quickly converted into a window view, is often used to generate animation effects; GLUT_DEPTH ': the flag allocates a depth cache as part of the display, so we can perform a depth test; GLUT_STENCIL: Make sure we also have a template cache available. */ glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL); // set window size glutInitWindowSize(800, 600); // set window title glutCreateWindow("Triangle"); // 1, glutReshapeFunc(changeSize); GlutDisplayFunc (RenderScene); // Initialize the GLEW library to ensure that OpenGL's API is fully available to the program. GLenum status = glewInit(); GLenum status = glewInit(); if (GLEW_OK ! = status) { printf("GLEW Error:%s\n",glewGetErrorString(status)); return 1; } /* GLUT internally runs a local message loop that intercepts the appropriate message. Then call the callback function that we registered at different times. We registered two callback functions: 1) a callback for window resizing --glutReshapeFunc 2) a callback for OpenGL rendering --glutDisplayFunc */ /1) Set our render environment setupRC(); //2, glutMainLoop(); return 0; }Copy the code

Execution Result:

Because some of the code in the block is earlier code, has been iterated, there will be a lot of warnings, to turn off these disgusting warnings like this: