webdancer's Blog
opengl配置
SC写了使用mingw时的opengl配置。由于我是使用VS,记录一下Windows7 下VS2010的opengl配置。由于图形学刚开始学,了解的不多。
1.安装Glut。GLUT是OpenGL应用工具包的缩写,英文全称为OpenGL Utility Toolkit,是一个和窗口系统无关的软件包,可以给我们的学习带来方便。当然,也可以选择不安装。
下载:http://www.opengl.org/resources/libraries/glut/glut37.zip
文件介绍:
glut.h -你需要在你的源代码中包含这个文件. 通常情况下, 这个文件应该放在你系统的包含目录下的 GL 文件夹中。
glut32.lib (微软版本) 和glut.lib (SGI windows版本) - 这个文件必须被连接到你的程序中, 确保它放在 LIB 目录中。
glut32.dll (Windows) 和 glut.dll (SGI Windows版本) - 根据你所使用的OpenGL选择一个, 如果你正在使用微软公司的版本, 那么你必须选择 glut32.dll. 你应该把DLL放置在你的系统文件夹中。
在我的机子里,具体为:
glut.h ---> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl
glut.dll,glut32.dll ---> C:\Windows\SysWOW64 (windows7 64位操作系统)
---> C:\Windows\System32 (windows7 32位操作系统)
glut.lib,glut32.lib ---> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib
2.建立project。
注意:项目选择Win32控制台项目,文件的后缀为c。
试一下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <gl\glut.h> #include <math.h> void dda( int x1, int y1, int x2, int y2){ int k,i; float x,y,dx,dy; k= abs (x2-x1); if ( abs (y2-y1)>k) k= abs (y2-y1); dx=( float )(x2-x1)/k; dy=( float )(y2-y1)/k; x=( float )(x1); y=( float )(y1); for (i=0;i<k;i++){ //gl_point(int(x+0.5),int(y+0.5)); glBegin(GL_POINTS); glVertex2i(( int )(x+0.5),( int )(y+0.5)); glEnd(); x+=dx; y+=dy; } } void printline( void ){ glClearColor (1.0,1.0,1.0,0.0); glMatrixMode (GL_PROJECTION); gluOrtho2D (0.0,200.0,0.0,150.0); dda(15,15,300,300); glFlush(); } int main( int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(100, 100); glutInitWindowSize(400, 400); glutCreateWindow( "第一个OpenGL程序" ); glutDisplayFunc(printline); glutMainLoop(); return 0; } |
对于mingw感兴趣的,可以参考:http://scturtle.is-programmer.com/posts/24996.html