OpenGL graph drawing in a fixed pipeline can be basically divided into the following steps:

Initialize window correlation

1. Initialize the viewport

glViewport(0, 0, w, h);
Copy the code

2. Set perspective projection

(Perspective projection is to convert the left side of a solid to a flat display effect, if only a flat graphic display can not be set.)

ViewFrustum. SetPerspective (35.0 f, float (w)/float (h), 1.0 f, 1000.0 f);Copy the code

3. Get the projection matrix and put it into the matrix stack

 projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());
Copy the code

4. Load the element matrix

    modelViewMatrix.LoadIdentity();
Copy the code

Initialize render related

1. Set the background color

GlClearColor (0.7F, 0.7F, 0.7F, 1.0f);Copy the code

2. Initialize pipeline management

shaderManager.InitializeStockShaders();
Copy the code

3. Enable depth testing

glEnable(GL_DEPTH_TEST);
Copy the code

4. Set transformation pipeline management model matrix and projection matrix

transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);
Copy the code

Initialize vertex data

(Cylinder vertex data)

int iCounter = 0; // radius GLfloat radius = 3.0f; For (GLfloat Angle = 0.0f; Angle < = (2.0 f * M3D_PI); Angle += 0.3f) {// GLfloat X = radius * sin(Angle); GLfloat y = radius * cos(angle); VPoints [iCounter][0] = x; // Draw two triangles (their x and y vertices are the same, but their z points are different). vPoints[iCounter][1] = y; VPoints [iCounter], [2] = 0.5; iCounter++; vPoints[iCounter][0] = x; vPoints[iCounter][1] = y; VPoints [iCounter] [2] = 0.5; iCounter++; } vPoints[iCounter][0] = vPoints[0][0]; vPoints[iCounter][1] = vPoints[0][1]; VPoints [iCounter], [2] = 0.5; iCounter++; vPoints[iCounter][0] = vPoints[1][0]; vPoints[iCounter][1] = vPoints[1][1]; VPoints [iCounter] [2] = 0.5; iCounter++;Copy the code

6. Call the Path class to draw

triangleStripBatch.Begin(GL_TRIANGLE_STRIP, iCounter);
triangleStripBatch.CopyVertexData3f(vPoints);
triangleStripBatch.End();
Copy the code

Scene rendering

1, clear depth cache area, color cache area, etc

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
Copy the code

2. Push the observer coordinate system onto the stack

modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); Matrix multiplied by the matrix, the top of the stack the result of the multiplication Jane then stored on the top of the stack (recovery) facilitate state modelViewMatrix. MultMatrix (mCamera);Copy the code

3. Push the graphic coordinate system onto the stack

M3DMatrix44f mObjectFrame; objectFrame.GetMatrix(mObjectFrame); / / matrix multiply, the top of the stack matrices, the result of the multiplication Jane then stored on the top of the stack modelViewMatrix. MultMatrix (mObjectFrame);Copy the code

4. Shader calls

This method calls for surface shader shaderManager. UseStockShader (GLT_SHADER_FLAT, transformPipeline GetModelViewProjectionMatrix (), vBlack);Copy the code

5. Set the line width

GlLineWidth (2.0 f);Copy the code

6. Start drawing

triangleStripBatch.Draw();
Copy the code

7. Restore the corresponding state

GlLineWidth (1.0 f); / / restore view matrix modelViewMatrix PopMatrix ();Copy the code

8. Exchange context

glutSwapBuffers();
Copy the code

Finish drawing the next time.