See OpenGL Write code (10) using an attribute array

Source: Internet
Author: User

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 (&AMP;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

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.