OpenGL learning notes (2)-a general OpenGL framework

Source: Internet
Author: User
# Include <Gl/glut. h> void display (void) {glclear (gl_color_buffer_bit); glbegin (gl_polygon); glvertex2f (-0.5,-0.5); glvertex2f (-0.5, 0.5); glvertex2f (0.5, 0.5); glvertex2f (0.5,-0.5); glend (); glflush ();} void Init () {glclearcolor (0.0, 0.0, 0.0, 0.0); glcolor3f (1.0, 1.0, 1.0); glmatrixmode (gl_projection); glloadidentity (); glortho (-1.0, 1.0,-1.0, 1.0,-1.0, 1.0);} int main (INT argc, char ** argv) {gluinit (& argc, argv); gluinitdisplaymode (glu_single | glu_rgb); gluinitwindowsize (500,500); gluinitwindowposition (); glucreatewindow ("simple "); gludisplayfunc (Display); Init (); glumainloop (); Return 0 ;}

ThisCodeThe general explanation is as follows:

1. First, add the necessary header file glut. H is included to use the function library provided by OpenGL.
2. display is a callback function written by the Program , used for drawing in a window. After registering it with the help of the main function,
each time the image in the window needs to be refreshed, the display function we wrote is called.
3. The gluinitwindowsize function specifies the width and height of the form.
4. Specify the coordinates in the upper left corner of the window.
5. Create a form in the window.
6. Enter form message loop.
unless otherwise stated, only the content of the display function can be changed in the Code in the following example.

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.