OpenGL, as a graphical interface, does not contain the relevant contents of the window, but OpenGL usage must depend on the window, which must be drawn in the window. This requires that we must understand a window system, but different operating systems provide the creation of the window API is not the same, if we are learning OpenGL to learn a complete set of Windows system, which will bring a lot of inconvenience, so there is glut. GLUT full name OpenGL Utility Toolkit, is a set of Windows system-independent software package, provides us with window creation, user input and output processing and other functions. The advantage is: Jane Small, lean. Note glut is not a particularly comprehensive Window System toolkit, so when building a large application, you need to select the appropriate native Window System toolkit as required.
Glut existing two distributions: Freeglut and the original version of GLUT. The update of the original glut has not been updated with the development of OpenGL, so the Freeglut is used in this practice.
The basic process of glut consists of four steps:
1) initialize the glut library;
2) Create GLUT window;
3) Register the display () callback function;
4) Enter glut main cycle;
GLUT initialization
Be sure to initialize the glut library before using glut. The function prototypes are:
void Glutinit (int argc,char **argv);
You can then set some properties of glut.
Configuring Display Properties
void Glutinitdisplaymode (unsigned int mode);
mode defaults to a bitwise combination of glut_index\glut_single and glut_depth.
Configuring the OpenGL version
void glutinitcontextversion (int majorversion, int minorversion);
Configuring context information for creation
void Glutinitcontextprofile (int profile)
CORE version: Glut_core_profile;
Compatibility version: Glut_compatibility_profile;
Create window
int Glutcreatewindow (char* name);
Set window position and size
void glutinitwindowsize (int width,int height);
void glutinitwindowposition (int x, int y);
Set the Render function
void Glutdisplayfunc (void (*func) (void));
Window Change callback function
void Glutreshapefunc (void (*func) (int width, int height));
Keyboard key Event Listener
void Glutkeyboardfunc (void (*func) (unsigned char key, int x, int y));
void Glutkeyboardupfunc (void (*func) (unsigned char key, int x, int y));
Mouse Event Monitoring
void Glutmousefunc (void (*func) (int button, int state, int x, int y)); The mouse is pressed to trigger
void Glutmotionfunc (void (*func) (int x, int y))//press the mouse button and move the trigger within the window
void Glutpassivemotionfunc (void (*func) (int x, int y));//The mouse pointer moves within the window
Window Redraw Marker
void Glutpostredisplay (void); The markup window needs to be redrawn, and the render function is called during the next execution.
Background management
void Glutidlefunc (void (*func) (void))//Func is called when no other event is required to be processed, typical applications such as animations
Event Loops
void Glutmainloop ();//Never return
Linux OpenGL Practice-2 Creating a window