OpenGL Programming Guide version Seventh source code bug Page35 lines.c Red Book

Source: Internet
Author: User

Question 1: According to the source code, when I found the time to knock. The effect is not implemented correctly. Where is not correct? There is no source code glpushattrib (gl_line_stipple) Glpopattrib (). So there's going to be a final draw. The information that is provided in the drawing is redrawn each time the updated dash time is overwritten before the line has been developed. The negotiation stack is processed so that the brush frame redraw will not affect the drawing results of other frames. (The reason is I'm not sure at the moment, it is expected to be a state machine management issue.) To understand the internal drawing mechanism.

But every time I manually add the stack and the stack is too much trouble, so I deal with the C_style macro definition form to achieve


Problem 2:reshape The operation of the screen and found that only display in the correct setting of the form parameters, or can be drawn normally.

The question comes, reshape shouldn't I stretch the form to trigger it? However, the situation can still be displayed if the changes are correct. Best of all, please enlighten me.


Change 1 source code such as the following:

#include "stdafx.h" #include <GL/freeglut.h> #define Drawoneline (x1,y1,x2,y2) glbegin (gl_lines); glvertex2f (x1 ), (y1)); glvertex2f ((x2), (y2)); Glend (); void init (void) {Glclearcolor (0.0,0.0,0.0,0.0); Glshademodel (Gl_flat);} void display (void) {//initial initialization definition form, I'm good to move this out. Test reshape function call, problem 2:int w = 400,h =150;glviewport (0,0,static_cast<glsizei > (w),static_cast<glsizei> (h)); Glmatrixmode (gl_projection); glloadidentity (); Gluortho2d (0.0,static_cast <GLfloat> (W),0.0,static_cast<glfloat> (h)); Glmatrixmode (Gl_modelview); glloadidentity ();//int i; Glclear (gl_color_buffer_bit); Glpushmatrix (); glcolor3f (1.0,1.0,1.0); glenable (gl_line_stipple);//1st Rowglpushattrib (gl_line_stipple);//read in binary, draw from low, the first parameter is the stretch parameter gllinestipple (1,0x0101);d Rawoneline ( 50.0,125.0,150,125.0); Glpopattrib (); Glpushattrib (gl_line_stipple); Gllinestipple (1,0X00FF);d Rawoneline ( 150.0,125.0,250.0,125.0); Glpopattrib (); Glpushattrib (gl_line_stipple); Gllinestipple (1,0x1c47);d Rawoneline ( 250.0,125.0,350.0,125.0); Glpopattrib ();//2nd ROwgllinewidth (5.0); Glpushattrib (gl_line_stipple);//read in binary, draw from the low, the first parameter is the tensile parameters Gllinestipple (1,0x0101); Drawoneline (50.0,100.0,150.0,100.0); Glpopattrib (); Glpushattrib (gl_line_stipple); Gllinestipple (1,0X00FF); Drawoneline (150.0,100.0,250.0,100.0); Glpopattrib (); Glpushattrib (gl_line_stipple); Gllinestipple (1,0X1C47); Drawoneline (250.0,100.0,350.0,100.0); Glpopattrib (); Gllinewidth (1.0);//3rd Rowglpushattrib (GL_LINE_STIPPLE); Gllinestipple (1,0X1C47); Glbegin (Gl_line_strip); for (int i = 0; i < 7; i++) {glvertex2f (50.0+static_cast<glfloat > (i*50.0), 75.0);} Glend (); Glpopattrib (); gldisable (gl_line_stipple); Glpopmatrix (); Glflush ();} void reshape (int w,int h) {}int _tmain (int argc, char * argv[]) {glutinit (&AMP;ARGC,ARGV); Glutinitdisplaymode (glut_ single| GLUT_RGB); glutinitwindowsize (400,150); glutinitwindowposition (0,0); Glutcreatewindow (argv[0]); init (); Glutdisplayfunc (display); Glutreshapefunc (NULL); Glutmainloop (); return 0;}



Correct source code demonstration:

Lines_p35.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <GL/freeglut.h> #define Drawoneline (scale,stipple,x1,y1,x2,y2) Glpushattrib (gl_ Line_stipple); gllinestipple (scale), (stipple)); Glbegin (gl_lines); glvertex2f ((x1), (y1)); glvertex2f ((x2), (y2)); Glend (); Glpopattrib (); void init (void) {Glclearcolor (0.0,0.0,0.0,0.0); Glshademodel (Gl_flat);} void display (void) {glclear (gl_color_buffer_bit); Glpushmatrix (); glcolor3f (1.0,1.0,1.0); Glenable (Gl_line_stipple) The//1st row//is read in binary, drawn from the low start. The first parameter is the stretch parameter Drawoneline (1,0x0101,50.0,125.0,150,125.0);d rawoneline (1,0x00ff,150.0,125.0,250.0,125.0);d Rawoneline (1,0x1c47,250.0,125.0,350.0,125.0);//2nd rowgllinewidth (5.0);//read in binary. Draw from the low start. The first parameter is the stretch parameter Drawoneline (1,0x0101,50.0,100.0,150.0,100.0);d rawoneline (1,0x00ff,150.0,100.0,250.0,100.0); Drawoneline (1,0x1c47,250.0,100.0,350.0,100.0); Gllinewidth (1.0);//3rd Rowglpushattrib (Gl_line_stipple); Gllinestipple (1,0X1C47); Glbegin (Gl_line_strip); for (int i = 0; i < 7; i++) {glvertex2f (50.0+static_cast<glfloat > (i*50.0), 75.0);} Glend (); Glpopattrib ();//4thfor (int i = 0; i < 6; i++) {Drawoneline (1,0x1c47,50.0+static_cast<glfloat> (i*50.0)) ,50.0,50.0+static_cast<glfloat> (i+1) *50.0,50.0);} 5thdrawOneLine (5,0x1c47,50.0,25.0,350.0,25.0); gldisable (gl_line_stipple); Glpopmatrix (); Glflush ();} void reshape (int w,int h) {Glviewport (0,0,static_cast<glsizei> (w),static_cast<glsizei> (h)); Glmatrixmode (gl_projection); glloadidentity (); gluortho2d (0.0,static_cast<glfloat> (w),0.0,static_cast< Glfloat> (h)); Glmatrixmode (Gl_modelview); glloadidentity (); int _tmain (int argc, char * argv[]) {glutinit (&AMP;ARGC,ARGV); Glutinitdisplaymode (glut_single| GLUT_RGB); glutinitwindowsize (400,150); glutinitwindowposition (0,0); Glutcreatewindow (argv[0]); init (); Glutdisplayfunc (display); Glutreshapefunc (reshape); Glutmainloop (); return 0;}



Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

OpenGL Programming Guide version Seventh source code bug Page35 lines.c Red Book

Related Article

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.