Linux OpenGL Practice-2 Creating a window

Source: Internet
Author: User
Tags event listener

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

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.