1, and the same as the last time made a mistake, depth buffer identifier Gl_depth_buffer_bit written gl_color_buffer_bit. Causes the drawing to be drawn without appearing in the window
2. The note is mine.
3. Good news: The use of code compare plugins and tools. Before my friend recommended me to use, there has been no scene. Now know: SVN with different versions of the file in the same path compared to the use of SMARTSVN, different files or different paths in any version of the code compare tools, such as according to other people's tutorials to write code or open source code into their own code this tool is suitable. Today is the use of this tool to find a writing error, this error needs to use inverted school and other text editing methods, but we are coding designers, should not waste time on meaningless events.
4, the main function of the implementation of decals and the first 3D project.
#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 geometry # include < glgeometrytransform.h> #include <GLFrame.h> #include <math.h> #define Freeglut_static#include <gl/ Glut.h>glshadermanager Shadermanager; Glmatrixstack Modelviewmatrix; Glmatrixstack ProjectionMatrix; Glframe Cameraframe; Glframe ObjectFrame; Glfrustum viewfrustum; Glbatch Pointbatch; Glbatch Linebatch; Glbatch Linestripbatch; Glbatch Lineloopbatch; Glbatch Trianglebatch; Glbatch Trianglestripbatch; Glbatch trianglefanbatch;//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 backgroundglclearcolor (0.7f, 0.7f, 0.7f, 1.0f);//Initialize Shadershadermanager.initializestockshaders (); glenable (gl_depth_test); Transformpipeline.setmatrixstacks (MODELVIEWMAtrix, ProjectionMatrix); Cameraframe.moveforward ( -15.0f);//not understanding, is actually the United States Florida terrain border. 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.8 0, 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 .1.0, 0.0}};//load point Batchpointbatch.begin (gl_points);p ointbatch.copyvertexdata3f (vcoast); Pointbatch.end ();//Load as a bunch bunching of line segmentslinebatch.begin (gl_lines); linebatch.copyvertexdata3f (Vcoast) ; Linebatch.end ();//Load as a single line Segmentlinestripbatch.begin (Gl_line_strip); linestripbatch.copyvertexdata3f (Vcoast); Linestripbatch.end ();//single line, connect first and last Pointslineloopbatch.begin (Gl_line_loop); lineloopbatch.copyvertexdata3f (vcoast); Lineloopbatch.end ();//For Triangles, we'll make a Pyramid: Pyramid, y-axis for the tower. , there is a question, how to seal 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};tr Ianglebatch.begin (Gl_triangles), 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) {//z-axis, radius, radii, rolling 0.3f generation between arcs Isolated Glfloat x = radius * sin (angle); Glfloat y = radius * cos (angle);//From the calculation far pointThen closer, make up the Strip ring//Specify the point and move the Z value up a littlevpoints[icounter][0] = x;vpoints[icounter][1] = Y;vpoint S[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[icounter][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;} Close the fannverts++;vpoints[nverts][0] = r;vpoints[nverts][1] = 0;vpoints[nverts][2] = 0.0f;//Load it uptrianglefanb Atch. Begin (Gl_Triangle_fan, 8); trianglefanbatch.copyvertexdata3f (vpoints); Trianglefanbatch.end ();} There is no use of live reservation, so there is a bunch of code behind Drawwireframedbatch (Glbatch * pbatch) {//Draw Green graph Shadermanager.usestockshader (glt_shader_ FLAT, Transformpipeline.getmodelviewprojectionmatrix (), Vgreen);p Batch->draw ();//Draw black line decals//draw Black Outlineglpolygonoffset ( -1.0f, -1.0f);//shift depth valuesglenable (gl_polygon_offset_line);//Turn on line offset--for decals//Draw Lines antialiased anti-aliasing property glenable (Gl_line_smooth);//Mixed glenable (gl_blend);//What kind of effect does this blend have?? Without opening the mixture, the black line is not completely close to the adjacent existing pixels (that is, the original model), and there are some more noticeable intervals glblendfunc (Gl_src_alpha, gl_one_minus_src_alpha);//draw Black Wireframe version of Geometry painted black Glpolygonmode (Gl_front_and_back, gl_line); Gllinewidth (2.5f); Shadermanager.usestockshader (Glt_shader_flat, Transformpipeline.getmodelviewprojectionmatrix (), vBlack);p batch- >draw ();//Put Everything back the the-the-found Itglpolygonmode (Gl_front_and_back, Gl_fill); Gldisable (Gl_polygon_ Offset_line); Gllinewidth (1.0f); gldisable (gl_blend); Gldisable (gl_line_smootH);} void Renderscene (void) {Glclear (Gl_color_buffer_bit | Gl_depth_buffer_bit | Gl_stencil_buffer_bit);//Save the current scene information Modelviewmatrix.pushmatrix ();//Set the state machine to be used//set the camera, do not understand how to set the current status * camera, make what changes? 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);//Rotate the object coordinates to be used in the model coordinate system//stock Inventory Shadermanager.usestockshader (Glt_shader_flat, Transformpipeline.getmodelviewprojectionmatrix (), vblack), switch (nstep) {case 0:glpointsize (4.0f);p Ointbatch.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); ModelViewmatrix.popmatrix ();//flush drawing Commandsglutswapbuffers ();} void Changesize (int w, int h) {glviewport (0, 0, W, h);//When a drawing is found to be invisible, it is mostly a matter of perspective or distance from the camera. Viewfrustum.setperspective (float) w/(float) H, 1.0f, 500.0f);p Rojectionmatrix.loadmatrix ( Viewfrustum.getprojectionmatrix ()); Modelviewmatrix.loadidentity ();} void Keypressfunc (unsigned char key, int x, int y) {//32 is a space if (key = =) {++nstep;if (nstep>6) {nstep = 0;}} Switch (nstep) {case 0:glutsetwindowtitle ("gl_points"); Break;case 1:glutsetwindowtitle ("Gl_lines"); Break;case 2: Glutsetwindowtitle ("Gl_line_strips"); Break;case 3:glutsetwindowtitle ("Gl_line_loop"); Break;case 4: Glutsetwindowtitle ("Gl_triangles"); Break;case 5:glutsetwindowtitle ("gl_triangle_strips"); Break;case 6: Glutsetwindowtitle ("Gl_triangle_fan"); Glutpostredisplay ();} void Specialkeys (int key, int x, int y) {if (key = = glut_key_up) {Objectframe.rotateworld (M3ddegtorad ( -5.0f), 1.0f, 0.0f, 0). 0f);} if (key = = Glut_key_down) {Objectframe.rotateworld (M3ddegtorad (5.0f), 1.0f, 0.0F, 0.0f);} if (key = = Glut_key_left) {Objectframe.rotateworld (M3ddegtorad ( -5.0f), 0.0f, 1.0f, 0.0f);} if (key = = Glut_key_right) {Objectframe.rotateworld (M3ddegtorad (5.0f), 0.0f, 1.0f, 0.0f);} Glutpostredisplay ();} int main (int argc, char * argv[]) {gltsetworkingdirectory (argv[0]); Glutinit (&ARGC, argv); Glutinitdisplaymode (GLUT _double | Glut_rgba | glut_depth | Glutinitwindowsize (Glut_stencil); Glutcreatewindow ("gl_points"); Glutreshapefunc (changesize);// Window Glutkeyboardfunc (keypressfunc);//Blank key Glutspecialfunc (Specialkeys);//up or down rotation angle glutdisplayfunc (renderscene);// Redraw Glenum err = Glewinit (); if (GLEW_OK! = Err) {fprintf (stderr, "Glew Error:%s\n", glewgeterrorstring (Err)); return 1;} SETUPRC (); Glutmainloop (); return 0;}
OpenGL Super Treasure Chapter III Example-decals