As is known to all, OPENGL is a state machine with many different states. We can use an array of attributes to save/restore a set of states. There are 20 groups of server property groups and 2 groups of client property groups.
about what properties are in these attribute groups. This website details: http://www.cnblogs.com/oiramario/archive/2010/04/13/1711114.html
Glpushattrib (Mask): The parameter mask represents an attribute group, and the function pushes the current property of the property group into the stack .
Glpopattrib (void): No arguments, stack the top properties of the stack, and set the properties of the out stack to the current state of OPENGL.
The following example uses a stack of attribute groups to switch between a blue matrix and a green matrix.
The following code:
DoubleBuffer.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <gl/glut.h>static bool ischange = false;static int changetimes = 0;void init () {Glclea Rcolor (0.0,0.0,0.0,0.0); Glshademodel (Gl_flat);//Use single coloring glcolor3f (0,1,0); Glpushattrib (gl_current_bit); glColor3f ( 0,0,1);} void display () {printf ("-----------display-------%d----", changetimes); Glclear (gl_color_buffer_bit); if (Ischange = = True) {if (changetimes% 2 = = 1) {glpopattrib ();p rintf ("Change green\n");;} Else{glpushattrib (Gl_current_bit), glcolor3f (0,0,1);p rintf ("Change blue\n");} Ischange = false;} GLRECTF ( -0.5,-0.5,0.5,0.5); Glflush ();} void ChangeColor () {ischange = True;changetimes ++;glutpostredisplay (); printf ("----------chilk------------");} void Mouse (int button,int state,int x,int y) {switch (button) {case Glut_left_button:if (state = = Glut_down) {ChangeColor () ;} Break;case glut_right_button:if (state = = Glut_down) {glutidlefunc (NULL);} Default:break;}} int _tmain (int argc, _tchar* argv[]) {Glutinit (&ARGC, (char**) argv); GlutinitwindowSize (500,500); glutinitwindowposition (0,0); Glutcreatewindow ("attribute group"); Init (); Glutdisplayfunc (display); Glutmousefunc (mouse); Glutmainloop (); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
See OpenGL Write code (10) using an attribute array