win7 + vs2010 under opengl development environment

glut Download:

http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip

 

1. unpack the glut.h into "C: \ Program Files (x86 ) \ Microsoft SDKs \ Windows \ v7.0A \ Include \ gl" ( related to the specific installation location, the installation directory should be \ microsoft sdks \ windows \ v7.0A \ the include \ GL)
      2. Extract the resulting glut.lib and glut32.lib into "" Programfiles (x86) \ Microsoft Visual studio 10.0 \ VC \ lib " in (the specific location of the installation, ibid)
      3. Extract the resulting glut.dll into "C: \ Windows \ System32"
      4. the glut32.dll into "Programfiles (x86) \ Microsoft Visual studio 10.0 \ VC \ bin" under (note this, some people say the internet system32 put in, but I tried, it will error) (related to the specific installation location, ibid)
      5. open vs2010, not open or create a new project. select project-> project property-> Configuration Properties-> Linker-> Input -> Additional Dependencies in add opengl32.lib glu32.lib glut32.lib

 

Create the Application Console the Win32 , (not a win32 application). Select a name, then press OK. Talking out of the box on the left point Application Settings, find and hook on Empty project, select Finish. Then add a code to the project file, named "OpenGL.c", pay attention .c as the end of the file. (In fact, need not necessarily end with .c, .cpp also)
get, just the usual engineering is no different.

#include <gl\glut.h> void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); glRectf(-0.5f, -0.5f, 0.5f, 0.5f); glFlush(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(100, 100); glutInitWindowSize(400, 400); glutCreateWindow("第一个OpenGL程序"); glutDisplayFunc(&myDisplay); glutMainLoop(); return 0; }


The action program is in the middle of a black draw a white rectangle window. The following statement on each line will be described.


First, the need to include header file #include <GL / glut.h>, which is the first document GLUT.
Originally OpenGL program in general also contain <GL / gl.h> and <GL / glu.h>, but the header file has been automatically GLUT in these two files contain, do not contain again.


Then look at the main function.
int main (int argc, char * argv []), this is with the command line parameter of the main function, you should have seen it? I have not seen comrades like him looking through the book, and so figured out and then look down.
Note that each statement in the main function, in addition to the final return, the rest all begin with a glut. Such a function is a function of the GLUT glut beginning toolkit provided below for several functions used are described.
1, glutInit, for GLUT is initialized, this function must be called once before any other use of GLUT. Which form more rigid, generally copy phrase glutInit (& argc, argv) on it.
2, glutInitDisplayMode, set the display mode in which RGB color GLUT_RGB indication, as well as the corresponding GLUT_INDEX (indexed color indication). GLUT_SINGLE represents single buffering, there are corresponding GLUT_DOUBLE (double buffering). For more information, please own Google. Of course after course there will be some explanation.
3, glutInitWindowPosition, this simple, set the position of the window in the screen.
4, glutInitWindowSize, this is simple, set the window size.
5, glutCreateWindow, create a window based on information previously set. Parameters will be used as the title of the window. Note: After the window is created, is not displayed on the screen immediately. GlutMainLoop need to call to see the window.
6, glutDisplayFunc, setting a function, when the need for drawing, this function is called. (This statement is not accurate enough, but probably accurate to say that beginners do not really understand, being so to speak).
7, glutMainLoop, for a message loop. (This may beginners do not quite understand, and now just need to know this function can display window, and wait will not return after the window is closed, it was enough.)

In glutDisplayFunc function, we set up "when you need to draw upon, please call myDisplay function. " Thus myDisplay function can be used to draw. MyDisplay observed in the three function calls and found that they all begin with gl. This is beginning to function gl OpenGL standard functions , the following function used to be introduced.
1, glClear, clear. GL_COLOR_BUFFER_BIT Clears the color, glClear function can also remove other things, but not introduced here.
2, glRectf, draw a rectangle. Four parameters represent the horizontal and vertical coordinates of two points positioned on a diagonal line.
3, glFlush, to ensure that the previous OpenGL commands executed immediately (instead of having them wait in the buffer). Its role is similar with fflush (stdout).

 

 

If this error then should note the following:
Added sometimes under construction console application when cpp file suffix .c sentence should read
some programs require glaux toolkit, this download, you can add (basic operating steps above the same)

Reproduced in: https: //www.cnblogs.com/moiyer/archive/2011/11/06/2316156.html

Guess you like

Origin blog.csdn.net/weixin_33912453/article/details/94693175