- Windows提供opengl支持和实现
- Windows 64-bit location: C:\Winodws\SysWOW64\opengl32.dll
- Windows 32-bit location: C:\Windows\System32\opengl32.dll
- 尽管win64的System32下面仍然有opengl32.dll,但是win64会默认查找SysWOW64目录
- 那么在windows下要开发opengl应用,至少还需要opengl32.lib和opengl相关头文件才行。
- 如果你使用visual studio,那么已经包含他们了(替换你自己的安装目录)
D:\environment\visual studio 2005\VC\PlatformSDK\Lib
- 如果你使用visual studio,那么已经包含他们了(替换你自己的安装目录)
D:\environment\visualstudio 2005\VC\PlatformSDK\Include
- 如果你不是用visual studio,那么windows SDK 包含他们,你可以去这里下载
http://msdn.microsoft.com/en-us/windows/bb980924.aspx
- 因为opengl设计目标就是作为一种流线型的、独立于硬件的接口,在许多不同的硬件平台上实现。因此,有下面两个问题产生。
Issue | solution | comment |
OpenGL并没有包含用于执行窗口任务或者获取用户输入之类的函数。而是需要通过具体的窗口系统来控制OpenGL应用程序所使用的特定硬件 | OpenGL不提供,那么所有的窗口系统都提供了函数库,扩展窗口系统的功能来支持OpenGL渲染。 Windows: WGL库函数提供了Windows和OpenGL之间的接口,所有WGL函数都使用前缀wgl。这个实际上是需要window api来提供窗口的。 AUX库,前缀aux X window: 使用GLX库提供接口,函数使用前缀glX。 Mac OS: 可以使用三种库,AGL(前缀为agl),CGL(cgl)和Cocoa(NSOpenGL类) 跨平台解决方案: GLUT (OpenGL Utility Toolkit),前缀glut | 这里面,只有GLUT是需要单独下载的包 |
OpenGL库本身并没有提供描述三维物体模型的高级函数,而程序员必须根据一些为数不多的几何图元(点、直线和多边形)来创建所需要的模型 | OpenGL内置一个GLU工具函数库来实现一些高级特性的封装操作,GLU库函数使用前缀glu |
|
- 使用Windows SDK AUX库
#include <windows.h>
#include <GL/gl.h>
#include <GL/glaux.h>
voidtest1()
{
auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
auxInitPosition(0,0, 500,500);
auxInitWindow(L"simple");
glClearColor(0.0,0.0, 0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0, 0.0);
glRectf(-0.5, -0.5,0.5, 0.5);
glFlush();
_sleep(5000);
}
voidCALLBACKmyReshape(GLsizei w, GLsizei h)
{
glViewport(0,0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
voidCALLBACK display(void)
{
glColor3f(1.0,1.0, 0.0);
auxSolidSphere(1.0);
glFlush();
}
voidtest2()
{
auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
auxInitPosition(0,0, 500,500);
auxInitWindow(L"aux sample");
glClearColor(0.0,0.0, 0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
auxReshapeFunc(myReshape);
auxMainLoop(display);
}
intmain()
{
//test1();
//test2();
return0;
}
- 使用GLUT学习OpenGL
因为GLUT使用简单,而且平台无关,所以用来学习opengl很好,具体使用如下:
- http://www.opengl.org/resources/libraries/glut/下载glut windows zip
<<glut-3.7.6-bin.zip>>
- 包内文件如上图,
- 将glut32.dll放入C:\Winodws\SysWOW64\ (32 bit放 C:\Windows\System32),
- 将glut32.lib放入D:\environment\visual studio 2005\VC\PlatformSDK\Lib
- 将glut.h放入D:\environment\visual studio 2005\VC\PlatformSDK\Include\gl
- 然后就可以使用GLUT编写测试程序了,一个简单的程序。
#include <GL/glut.h>
voidinit(void)
{
glClearColor(0.0,0.0, 0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
}
voiddisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25,0.25,0.0);
glVertex3f(0.75,0.25,0.0);
glVertex3f(0.75,0.75,0.0);
glVertex3f(0.25,0.75,0.0);
glEnd();
glFlush();
}
intmain(int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,100);
glutCreateWindow("helloglut");
init();
glutDisplayFunc(display);
glutMainLoop();
return0;
};
参考文献:
OpenGL编程指南(第七版)
Creatingan OpenGL Context (WGL)
Pastedfrom <http://www.opengl.org/wiki/Creating_an_OpenGL_Context_(WGL)>