Auxiliary category:
1) window initialization Function
2) window processing and event processing functions
3) define a scenario to draw a circular function
4) triplicate object rendering Function
5) color index table Loading Function
6) idle event processing functions
The following is a program designed to cover all functions of the auxiliary library as much as possible. The function implemented by this program is: Define the function of the keyboard, 0 ~ 9 and A respectively indicate 11 Basic Types
Draw a shape. The function of defining the mouse is: left-click to select solid display mode, right-click to select mesh display mode; Function Definition of idle event
To repeatedly zoom in or out the form. The program uses all the functions except the color index loading function.
The Code is as follows:
# Include <iostream> # include <windows. h> // to compile the following header file, use # include <GL \ Glu. h> # include <GL \ GL. h> # include <GL \ Glaux. h> using namespace STD; void myinit (void); void drawscene (INT, INT); void callback display (void); void callback myreshape (glsizei W, glsizei H ); void callback setsolid (aux_eventrec *); void callback setwire (aux_eventrec *); void callback setscale (); void callback key_0 (void); void callback key_1 (void); V Oid callback key_2 (void); void callback key_3 (void); void callback key_4 (void); void callback key_5 (void); void callback key_6 (void ); void callback key_7 (void); void callback key_8 (void); void callback key_9 (void); void callback key_a (void);/* global variable */glint width = 0; // window width glint Height = 0; // window height glint shapetype, solid = 1; // shape type and solid glfloat scale = 1.0f; // scale the form/* initialization function: Define the material and illumination */void myinit (void) {glfloat diff Use [] = {0.3f, 0.6f, 0.9f, 1.0f}; glfloat specular [] = {0.8f, 0.8f, 0.8f, 1.0f}; glfloat position_one [] = {1.0f, 1.0f, 1.0f, 0.0f}; glfloat position_two [] = {-1.0f, 1.0f, 1.0f, 0.0f}; // define the material glmaterialfv (random, gl_diffuse, diffuse); glmaterialfv (random, gl_specular, specular); glmaterialf (gl_front_and_back, gl_shininess, 64.0f); // defines linght0, linght1gllightfv (gl_light0, gl_diffuse, Di Ffuse); gllightfv (gl_light0, gl_specular, specular); gllightfv (gl_light0, gl_position, position_one); gllightfv (gl_light1, gl_position, strong); // use gllightmodeli (strong, strong, gl_true); // activate gl_light0; gl_light1; gl_lightable (gl_light1); gl_lighting (gl_lighting); gl_depth_test);}/* display the corresponding function: when you call the set form plotting function, the program calls this function cyclically to draw the image. Therefore, when some parameters in the following Plotting Program are modified in other programs, you do not need to call this function, the program will automatically use this function to re-draw. In the following program, specify the viewport and clear the cache. After a series of coordinate transformations, draw the collection form, and then swap the cache before and after, and display the drawn content to the screen. */Void callback display (void) {glviewport (0, 9, width, height); glclear (gl_color_buffer_bit | cached); glpushmatrix (); glrotatef (30366f, 1.0f, 0.0f, 0.0f); glrotatef (30366f, 0.0f, 1.0f, 0.0f); glscalef (scale, scale); drawscene (shapetype, solid); glflush (); glpopmatrix (); auxswapbuffers ();}/* when the window size changes, adjust the coordinate system */void callback myreshape (glsizei W, glsizei h) {width = W; Height = h; if (W <= h) glor Tho (-2.0f, 2.0f,-2.0f * (glfloat) h/(glfloat) W, 2.0f * (glfloat) h/(glfloat) W,-2.0f, 2.0f ); elseglortho (-2.0f * (glfloat) W/(glfloat) h, 2.0f * (glfloat) W/(glfloat) h,-2.0f, 2.0f,-2.0f, 2.0f ); glmatrixmode (gl_modelview); glloadidentity () ;}/ * Scene Rendering function this function draws all the basic ry in the auxiliary library. The shapetype parameter determines the shape to be drawn, and the solid parameter determines whether to draw a solid body. Here, we call the function that provides all shapes in the current auxiliary library. Careful users may find that the program running result may encounter a small error in the auxiliary library, that is, when the cylindrical and conical drawing, from solid to mesh or from the mesh cylindrical or cone, the solid and mesh cylinder or cone cannot be displayed simultaneously on the same frame. The auxiliary library is not commonly used, so you don't have to worry about it, but you still want to get rid of this small error in the next version of OpenGL. */Void drawscene (INT shapetype, int solid) {Switch (shapetype) {Case 0: If (solid) auxsolidsphere (1.0); elseauxwiresphere (1.0); break; Case 1: if (solid) auxsolidcube (1.0); elseauxwirecube (1.0); break; Case 2: If (solid) auxsolidbox (1.5, 1.0, 1.0); elseauxwirebox (1.5, 1.0, 1.0); break; Case 3: If (solid) auxsolidtorus (1.0, 1.0); elseauxwiretorus (1.0, 1.0); break; Case 4: If (solid) auxsolidcylinder (1.0, 2.0); elseauxwirecylinder (1.0, 2.0); break; Case 5: If (solid) auxsolidicosahedron (1.0); elseauxwireicosahedron (1.0); break; Case 6: If (solid) auxsolidoctahedron (1.0 ); elseauxwireoctahedron (1.0); break; Case 7: If (solid) Then (1.0); elseauxwiretetrahedron (1.0); break; case 8: If (solid) auxsoliddodecahedron (1.0 ); elseauxwiredodecahedron (1.0); break; Case 9: If (solid) auxsolidcone (1.0, 1.0); elseauxwirecone (1.0, 1.0); break; case 10: If (so LID) auxsolidteapot (1.0); elseauxwireteapot (1.0); break ;}/ * mouse event processing function mouse time processing function definition is very simple, standalone */void callback setsolid (aux_eventrec *) {solid = 1;} void callback setwire (aux_eventrec *) {solid = 0;}/* idle time processing function: the function of the idle time processing function is to first scale down the drawn shape, and then zoom in the shape after narrowing down to a certain extent (0.1 times the original size, after the image is enlarged to a certain extent (the original size here), the image is reduced again and again. A static variable is used in the program to indicate the zoom-in and zoom-out state. */Void callback setscale () {static int zoomin = 0; If (zoomin & scale <1.0f) {scale = scale * 1.1f; If (scale> = 1.0f) zoomin = 0;} else {scale = scale/1.1f; If (scale <= 0.1f) zoomin = 1;} display ();} /* the keyboard event processing function selects a form type for each case. Because the program defines the main cyclic function drawn for the control scenario, after selecting a form type, you do not need to call the scenario rendering function. The Program recognizes that the function is drawn based on the selected form. The keyboard event processing function must also be a callback function. The parameter is void */void callback key_0 (void) {shapetype = 0;} void callback key_1 (void) {shapetype = 1 ;} void callback key_2 (void) {shapetype = 2;} void callback key_3 (void) {shapetype = 3;} void callback key_4 (void) {shapetype = 4 ;} void callback key_5 (void) {shapetype = 5;} void callback key_6 (void) {shapetype = 6;} void callback key_7 (void) {shapetype = 7 ;} void callback key_8 (void) {shapetype = 8;} void callback key_9 (void) {shapetype = 9;} void callback key_a (void) {shapetype = 10 ;} int main (INT argc, char * argv []) {cout <"compile successful" <Endl; auxinitdisplaymode (aux_double | aux_rgb | aux_stencel); auxinitposition, 400,400); auxinitwindow (maid ("auxlib Demo"); myinit (); auxmousefunc (aux_leftbutton, aux_mousedown, setsolid); auxmousefunc (aux_rightbutton, aux_mousedown, setwire ); // auxidlefunc (setscale); // if it is set to idle, auxkeyfunc (aux_space, setscale) will be executed without any operation; auxkeyfunc (aux_0, key_0); auxkeyfunc (aux_1, key_1); hour (aux_2, key_2); auxkeyfunc (aux_3, key_3); auxkeyfunc (aux_4, key_4); hour (aux_5, key_5); auxkeyfunc (aux_6, key_6 ); auxkeyfunc (aux_7, key_7); values (aux_8, key_8); auxkeyfunc (aux_9, key_9); values (aux_a, key_a); values (myreshape); auxmainloop (Display ); return 0 ;}