win7 64-bit system, configure OpenGL development environment under vs2010

Glut download address:

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

 

Or: http://user.xmission.com/~nate/glut.html

 

 

 

1. Put the glut.h decompressed into "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl" (depending on the specific installation location, it should be the installation directory\microsoft sdks\windows \v7.0A\include\gl)
      2. Put the unzipped glut.lib and glut32.lib into ""Programfiles(x86)\Microsoft Visual studio 10.0\VC\lib" (related to the specific installation location, same as above)
      3. Put the glut.dll obtained after decompression into "C:\Windows\System32"
      4. Put glut32.dll under "Programfiles(x86)\Microsoft Visual studio 10.0\VC\bin" (note this, someone on the Internet said Put it in system32, but I tried it, and it will report an error) (related to the specific installation location, same as above)
      5. Open vs2010, open or create a new project casually. Select project->project property->Configuration Properties->Linker->Input ->Additional Dependencies add opengl32.lib glu32.lib glut32.lib in it

 

[cpp]  view plain copy Check out code snippets on CODE derived to my code slice
  1. // first_test.cpp : Defines the entry point for the console application.  
  2. //  
  3.   
  4. #include "stdafx.h"  
  5. #include<Windows.h>  
  6. #include <stdio.h>  
  7. //#include "glut.h"//This way of writing puts the header files dll and lib into local files.  
  8. #include <gl/glut.h>  
  9.   
  10. void run()  
  11. {  
  12.       
  13.       
  14.     const  GLubyte* name = glGetString(GL_VENDOR);  //Return the name of the vendor responsible for the current OpenGL implementation  
  15.     const  GLubyte* biaoshifu = glGetString(GL_RENDERER);  // Return a renderer identifier, usually a hardware platform  
  16.     const  GLubyte* OpenGLVersion =glGetString(GL_VERSION);  //Return the version number of the current OpenGL implementation  
  17.     const  GLubyte* gluVersion= gluGetString(GLU_VERSION);  //Return the current GLU tool library version  
  18.     printf( "The name of the OpenGL implementation vendor: %s\n" , name);  
  19.     printf( "Renderer identifier: %s\n" , biaoshifu);  
  20.     printf("OOpenGL实现的版本号:%s\n",OpenGLVersion );  
  21.     printf("OGLU工具库版本:%s\n", gluVersion);  
  22.       
  23. }  
  24.   
  25.   
  26.   
  27. //#include<gl/glu.h>  //glut.h自动包含了glu.h 和 gl.h  
  28.   
  29. //#include<gl/gl.h>  
  30.   
  31.   
  32.   
  33. void renderScene(void)  
  34.   
  35. {  
  36.   
  37.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
  38.   
  39.     glLoadIdentity();  
  40.   
  41.     glBegin(GL_TRIANGLES);  
  42.   
  43.     glVertex3f(-0.5,-0.5,0.0);  
  44.   
  45.     glVertex3f(0.5,0.0,0.0);  
  46.   
  47.     glVertex3f(0.0,0.5,0.0);  
  48.   
  49.     glEnd();  
  50.   
  51.     glutSwapBuffers();  
  52.   
  53. }  
  54.   
  55.   
  56.   
  57. int _tmain(int argc, _TCHAR* argv[])  
  58.   
  59. {  
  60.   
  61.     glutInit(&argc,(char** )argv);  
  62.     //显示模式初始化  
  63.     glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);  
  64.     //定义窗口大小  
  65.     glutInitWindowSize(300,300);  
  66.     //定义窗口位置  
  67.     glutInitWindowPosition(100,100);  
  68.     //创建窗口  
  69.           
  70.     glutCreateWindow("Hello OpenGL");  
  71.   
  72.     glutDisplayFunc(renderScene);  
  73.   
  74.       
  75.     run();  
  76.       
  77.   
  78.     glutMainLoop();//enters the GLUT event processing loop.  
  79.   
  80.     return 0;  
  81.   
  82. }  


 

 

首先,需要包含头文件#include <GL/glut.h>,这是GLUT的头文件。
本来OpenGL程序一般还要包含<GL/gl.h>和<GL/glu.h>,但GLUT的头文件中已经自动将这两个文件包含了,不必再次包含。


然后看main函数。
int main(int argc, char *argv[]),这个是带命令行参数的main函数,各位应该见过吧?没见过的同志们请多翻翻书,等弄明白了再往下看。
注意main函数中的各语句,除了最后的return之外,其余全部以glut开头。这种以glut开头的函数都是GLUT工具包所提供的函数,下面对用到的几个函数进行介绍。
1、glutInit,对GLUT进行初始化,这个函数必须在其它的GLUT使用之前调用一次。其格式比较死板,一般照抄这句glutInit(&argc, argv)就可以了。
2、 glutInitDisplayMode,设置显示方式,其中GLUT_RGB表示使用RGB颜色,与之对应的还有GLUT_INDEX(表示使用索引颜色)。GLUT_SINGLE表示使用单缓冲,与之对应的还有GLUT_DOUBLE(使用双缓冲)。更多信息,请自己Google。当然以后的教程也会有一些讲解。
3、glutInitWindowPosition,这个简单,设置窗口在屏幕中的位置。
4、glutInitWindowSize,这个也简单,设置窗口的大小。
5、glutCreateWindow,根据前面设置的信息创建窗口。参数将被作为窗口的标题。注意:窗口被创建后,并不立即显示到屏幕上。需要调用glutMainLoop才能看到窗口。
6. glutDisplayFunc, set a function, when drawing is required, this function will be called. (This statement is not accurate enough, but the accurate statement may not be easy for beginners to understand, so let's put it this way for the time being).
7. glutMainLoop, a message loop. (Beginners may not understand this. Now we only need to know that this function can display the window and wait for the window to be closed before returning. This is enough.)

In the glutDisplayFunc function, we set "When drawing is required, please Call myDisplay function". So the myDisplay function is used to draw pictures. Observe the three function calls in myDisplay and find that they all start with gl. The functions starting with gl are all standard functions of OpenGL, and the functions used are introduced below.
1. glClear, clear. GL_COLOR_BUFFER_BIT means to clear the color, and the glClear function can also clear other things, but it will not be introduced here.
2. glRectf, draw a rectangle. The four parameters represent the abscissa and ordinate of the two points on the diagonal respectively.
3. glFlush, to ensure that the preceding OpenGL commands are executed immediately (rather than having them wait in the buffer). Its function is similar to fflush(stdout).

 

 

If you still report an error in this way, you should pay attention to the following points:
Sometimes the cpp file added when building the console application changes the suffix sentence to .c.
Some programs require the glaux toolkit, which can be added according to the above steps same)

Guess you like

Origin blog.csdn.net/laiyinping/article/details/43054163