1. Create an OpenGL project in VS2013
Select File->new->project, then select Win32 Console Application, select a name, then press OK.
On the left side of the dialog box, click Application Settings, find the empty project and tick on it and select Finish.
Then add a code file to the project named "OPENGL.C" and pay attention to using. C as the end of the file.
Done, it is no different from the usual project.
2. First OpenGL Program
1 //Glut's header file2 //originally OpenGL program will generally include <GL/gl.h> and <gl/glu.h>, but the GLUT header file has automatically included these two files, do not have to contain3#include <glut.h>4 5 voidMydisplay (void)6 7 {8 //indicates clear color9 glclear (gl_color_buffer_bit);Ten One //draw a rectangle. The four parameters represent the horizontal and vertical coordinates of two points on the diagonal, respectively. AGLRECTF (-0.5f, -0.5f,0.5f,0.5f); - - //ensure that the previous OpenGL commands execute immediately (instead of having them wait in the buffer) the Glflush (); - - } - + //main function with command-line arguments - intMainintargcChar*argv[]) + A { at //functions that begin with glut are the functions provided by the GLUT Toolkit - - //to initialize the glut, this function must be called once before other glut are used. Its format is more rigid, the general copy of this sentence glutinit (&ARGC, argv) can be -Glutinit (&argc, argv); - - //sets the display mode, where GLUT_RGB indicates the use of RGB colors, and also Glut_index (which indicates the use of indexed colors). in //Glut_single means using a single buffer, corresponding to the glut_double (using double buffering) -Glutinitdisplaymode (Glut_rgb |glut_single); to + //set the position of the window in the screen -Glutinitwindowposition ( -, -); the * //set the size of the window $Glutinitwindowsize ( -, -);Panax Notoginseng - //creates a window based on the information previously set. Parameter will be used as the caption of the window the //Note: When the window is created, it is not immediately displayed to the screen. You need to call Glutmainloop to see the window +Glutcreatewindow ("First OpenGL program"); A the //The callback function registered through GLUTDISPLAYFUNC () is executed whenever glut determines that the contents of a window need to be re-displayed + //all the code needed to redraw the scene should be placed in the display callback function. -Glutdisplayfunc (&mydisplay); $ $ //all the windows that have been created will be displayed at this point, and the rendering of these windows is now in effect . - //The event processing loop starts and the registered display callback function is triggered. Once you enter the loop, it never quits. - Glutmainloop (); the - return 0;Wuyi the}
The function of the program is to draw a white rectangle in the center of a black window. For details, please see the Note ~ ~
This is the simple first OpenGL program ~ ~
OpenGL (ii) Using Glut for display window management