The third chapter of openGL is the example of "deploy", and the third chapter is "deploy ".

Source: Internet
Author: User

The third chapter of openGL is the example of "deploy", and the third chapter is "deploy ".

1. I made the same mistake as last time. The GL_DEPTH_BUFFER_BIT OF THE DEEP buffer flag is written as GL_COLOR_BUFFER_BIT. As a result, drawing does not appear in the window

2. Comments are mine.

3. Good news: Use of code compare plug-ins and tools. I was recommended by my friends before, and there was no scenario. Now we know that smartSVN is used for comparison between different versions of svn and files in the same path. For comparison between different files and different paths, the code compare tool is used. Today, we are using this tool to find writing errors. Such errors need to be edited using inverted texts, but we are code designers and should not waste time on unnecessary events.

4. The main function is to implement the Paster drawing and the first 3D project.

5. You can directly use lib as a resource and add it to an existing project (to facilitate the exercise). The following pre-compilation is not required. Of course, pre-compilation is good, cross-platform problems can be solved with a few pieces of code.

# Ifdef WIN32 # pragma comment (lib, "freeglut_static.lib") # endif # include <GLTools. h> # include <GLFrustum. h> # include <GLMatrixStack. h> # include <GLFrame. h> # include <GLBatch. h> // Geometry ry # include <GLGeometryTransform. h> # include <GLFrame. h> # include <math. h> # define FREEGLUT_STATIC # include <GL/glut. h> GLShaderManager shaderManager; GLMatrixStack modelViewMatrix; GLMatrixStack projectionMatrix; GLFrame cameraF Rame; GLFrame objectFrame; GLFrustum viewFrustum; GLBatch pointBatch; GLBatch lineBatch; GLBatch lineStripBatch; GLBatch batch; // transformation pipeline GLGeometryTransform transformPipeline; GLfloat vBlack [] = {0.0f, 0.0f, 0.0f, 1.0f}; GLfloat vGreen [] = {0.0f, 1.0f, 0.0f, 1.0f}; int nStep = 0; void SetupRC (void) {// Black backgroundglClearCol Or (0.7f, 0.7f, 0.7f, 1.0f); // initialize shadershaderManager. initializeStockShaders (); glable (GL_DEPTH_TEST); transformPipeline. setMatrixStacks (modelViewMatrix, projectionMatrix); cameraFrame. moveForward (-15.0f); // if you do not understand it, it is actually the border of Florida .. //////////////////////////////////////// //// // Some points, more or less in the shape of FloridaGLfloat vCoast [24] [3] = {2.80, 1.20, 0.0}, {2.0, 1.20, 0.0}, {2.0, 1.08, 0.0 },{ 2.0, 1.08, 0.0 },{ 0.0, 0.80, 0.0 },{-. 32, 0.40, 0.0 },{-. 48, 0.2, 0.0 },{-. 40, 0.0, 0.0 },{-. 60 ,-. 40, 0.0 },{-. 80 ,-. 80, 0.0 },{-. 80,-1.4, 0.0 },{-. 40,-1.60, 0.0}, {0.0,-1.20, 0.0 },{. 2 ,-. 80, 0.0 },{. 48 ,-. 40, 0.0 },{. 52 ,-. 20, 0.0 },{. 48 ,. 20, 0.0 },{. 80 ,. 40, 0.0 },{ 1.20 ,. 80, 0.0}, {1.60 ,. 60, 0.0}, {2.0 ,. 60, 0.0}, {2.2 ,. 80, 0.0 },{ 2.40, 1.0, 0.0 },{ 2.80, 1.0, 0.0 }}; // Load point batchpointBatch. begin (GL_POINTS, 24); pointBatch. copyVertexData3f (vCoast); pointBatch. end (); // Load as a bunch bundle of line segmentslineBatch. begin (GL_LINES, 24); lineBatch. CopyVertexData3f (vCoast); lineBatch. end (); // Load as a single line segmentlineStripBatch. begin (GL_LINE_STRIP, 24); lineStripBatch. copyVertexData3f (vCoast); lineStripBatch. end (); // Single line, connect first and last pointslineLoopBatch. begin (GL_LINE_LOOP, 24); lineLoopBatch. copyVertexData3f (vCoast); lineLoopBatch. end (); // For Triangles, we'll make a Pyramid: Pyramid, and the Y axis is the top of the tower ., How can I block the bottom? GLfloat vPyramid [12] [3] = {-2.0f, 0.0f,-2.0f, 2.0f, 0.0f,-2.0f, 0.0f, 4.0f, 0.0f, 2.0f, 0.0f,-2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 4.0f, 0.0f, 2.0f, 0.0f, 2.0f,-2.0f, 0.0f, 2.0f, 0.0f, 4.0f, 0.0f,-2.0f, 0.0f, 2.0f,-2.0f, 0.0f,-2.0f, 0.0f, 4.0f, 0.0f}; triangleBatch. begin (GL_TRIANGLES, 12); triangleBatch. copyVertexData3f (vPyramid); triangleBatch. end (); // For a Triangle fan, just a 6 sided hex. raise the center Up a bitGLfloat vPoints [100] [3]; // Scratch array, more than we need // For triangle strips, a little ring or cylinder segmentint iCounter = 0; GLfloat radius = 3.0f; for (GLfloat angle = 0.0f; angle <= (2.0f * M3D_PI); angle ++ = 0.3f) {// takes the Z axis as the center and the length is radius, use the arc to scroll 0.3f to generate the interval GLfloat x = radius * sin (angle); GLfloat y = radius * cos (angle); // from the far point of calculation to the near point, make up strip ring // Specify the point and move the Z value up a little VPoints [iCounter] [0] = x; vPoints [iCounter] [1] = y; vPoints [iCounter] [2] =-0.5; iCounter ++; vPoints [iCounter] [0] = x; vPoints [iCounter] [1] = y; vPoints [iCounter] [2] = 0.5; iCounter ++ ;} // Close up the loopvPoints [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 [iCounte R] [2] = 0.5; iCounter ++; // Load the triangle striptriangleStripBatch. begin (GL_TRIANGLE_STRIP, iCounter); triangleStripBatch. copyVertexData3f (vPoints); triangleStripBatch. end (); int nVerts = 0; GLfloat r = 3.0f; for (GLfloat angle = 0; angle <M3D_2PI; angle ++ = M3D_2PI/6.0f) {nVerts ++; vPoints [nVerts] [0] = float (cos (angle) * r; vPoints [nVerts] [1] = float (sin (angle) * r; vPoints [nVerts] [2] =-0.5f;} // Cl Ose the fannVerts ++; vPoints [nVerts] [0] = r; vPoints [nVerts] [1] = 0; vPoints [nVerts] [2] = 0.0f; // Load it uptriangleFanBatch. begin (GL_TRIANGLE_FAN, 8); triangleFanBatch. copyVertexData3f (vPoints); triangleFanBatch. end () ;}// no field retained, so a pile of code void DrawWireFramedBatch (GLBatch * pBatch) is added later {// draw a green figure shaderManager. useStockShader (GLT_SHADER_FLAT, transformPipeline. getModelViewProjectionMatrix (), vGreen); pBatch-> Dra W (); // Draw a black line sticker // Draw black outlineglPolygonOffset (-1.0f,-1.0f); // shift depth valuesglEnable (GL_POLYGON_OFFSET_LINE ); // enable line offset -- used to Draw the sticker // Draw lines antialiased anti-aliasing attribute glEnable (GL_LINE_SMOOTH); // mixed GL_BLEND; // what kind of effect does this hybrid solution have ?? If you do not enable the hybrid operation, the black line is not completely close to the adjacent existing pixel (that is, the original model), and glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) appears ); // Draw black wireframe version of geometry draws a black line glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); glLineWidth (2.5f); shaderManager. useStockShader (GLT_SHADER_FLAT, transformPipeline. getModelViewProjectionMatrix (), vBlack); pBatch-> Draw (); // Put everything back the way we found itglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); GlDisable (random); glLineWidth (1.0f); glDisable (GL_BLEND); glDisable (GL_LINE_SMOOTH);} void RenderScene (void) {glClear (random | Random ); // Save the information of the current scenario modelViewMatrix. pushMatrix (); // set the state machine to be used // set the camera. I don't understand how to set it, the current status * the camera, and what changes do I make? To be continued, M3DMatrix44f mCamera; cameraFrame. getCameraMatrix (mCamera); modelViewMatrix. multMatrix (mCamera); // The camera acts on the model coordinate system M3DMatrix44f mObjectFrame; objectFrame. getMatrix (mObjectFrame); modelViewMatrix. multMatrix (mObjectFrame); // The rotation is the object coordinate, which must be applied to the model coordinate system // Stock shaderManager. useStockShader (GLT_SHADER_FLAT, transformPipeline. getModelViewProjectionMatrix (), vBlack); switch (nStep) {case 0: glPointSize (4.0f); pointBatch. Draw (); glPointSize (1.0f); break; case 1: glLineWidth (2.0f); lineBatch. draw (); glLineWidth (1.0f); break; case 2: glLineWidth (2.0f); lineStripBatch. draw (); glLineWidth (1.0f); break; case 3: glLineWidth (2.0f); lineLoopBatch. draw (); glLineWidth (1.0f); break; case 4: DrawWireFramedBatch (& triangleBatch); break; case 5: DrawWireFramedBatch (& triangleStripBatch); break; case 6: drawWireFramedBatch (& triangleFanBatch); break;} model ViewMatrix. popMatrix (); // Flush drawing commandsgluswapbuffers ();} void ChangeSize (int w, int h) {glViewport (0, 0, w, h ); // when the drawn image is invisible, most of the problems are the distance between the angle of view or camera. ViewFrustum. setPerspective (35, (float) w/(float) h, 1.0f, 500366f); projectionMatrix. loadMatrix (viewFrustum. getProjectionMatrix (); modelViewMatrix. loadIdentity ();} void KeyPressFunc (unsigned char key, int x, int y) {// 32 is a space if (key = 32) {++ nStep; if (nStep> 6) {nStep = 0 ;}} switch (nStep) {case 0: glusetwindowtitle ("GL_POINTS"); break; case 1: glusetwindowtitle ("GL_LINES "); break; case 2: Maid ("GL _ LINE_STRIPS "); break; case 3: Maid (" GL_LINE_LOOP "); break; case 4: Maid (" GL_TRIANGLES "); break; case 5: Maid (" GL_TRIANGLE_STRIPS "); break; case 6: Maid ("GL_TRIANGLE_FAN"); break;} fig ();} void SpecialKeys (int key, int x, int y) {if (key = fig) {objectFrame. rotateWorld (m3dDegToRad (-5.0f), 1.0f, 0.0f, 0.0f);} if (key = fig) {obje CtFrame. rotateWorld (m3dDegToRad (5.0f), 1.0f, 0.0f, 0.0f);} if (key = fig) {objectFrame. rotateWorld (m3dDegToRad (-5.0f), 0.0f, 1.0f, 0.0f);} if (key = fig) {objectFrame. rotateWorld (m3dDegToRad (5.0f), 0.0f, 1.0f, 0.0f);} fig ();} int main (int argc, char * argv []) {gltSetWorkingDirectory (argv [0]); fig (& argc, argv); fig mode (Fig | H | maid); maid (800,600); maid ("GL_POINTS"); fig (ChangeSize); // window fig (KeyPressFunc); // The blank key SpecialKeys ); // top, bottom, left, and right rotation angle (RenderScene); // re-paint GLenum err = glewInit (); if (GLEW_ OK! = Err) {fprintf (stderr, "GLEW Error: % s \ n", glewGetErrorString (err); return 1 ;}setuprc (); glumainloop (); return 0 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.