爱情的奇迹第二部.:大侠们! open gl在vc++里面的详细流程??? 最好举个例子

来源:百度文库 编辑:高校问答 时间:2024/05/11 02:50:34
还有请推荐MFC 实例教程 谢谢!!!

在MFC称序里调用openGL与调用别的主要区别是:
(1)要加头文件 #include <gl\gl.h>
(2)用的DC不同。通常要有:
BOOL CxxView::SetWindowPixelFormat(HDC hDC)
{
PIXELFORMATDESCRIPTOR pixelDesc;

pixelDesc.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pixelDesc.nVersion = 1;

pixelDesc.dwFlags = PFD_DRAW_TO_WINDOW |
// PFD_DRAW_TO_BITMAP |
// PFD_SUPPORT_GDI |
PFD_DOUBLEBUFFER |
PFD_SUPPORT_OPENGL |
PFD_STEREO_DONTCARE;
pixelDesc.iPixelType = PFD_TYPE_RGBA;
pixelDesc.cColorBits = 32;
pixelDesc.cRedBits = 8;
pixelDesc.cRedShift = 16;
pixelDesc.cGreenBits = 8;
pixelDesc.cGreenShift = 8;
pixelDesc.cBlueBits = 8;
pixelDesc.cBlueShift = 0;
pixelDesc.cAlphaBits = 0;
pixelDesc.cAlphaShift = 0;
pixelDesc.cAccumBits = 64;
pixelDesc.cAccumRedBits = 16;
pixelDesc.cAccumGreenBits = 16;
pixelDesc.cAccumBlueBits = 16;
pixelDesc.cAccumAlphaBits = 0;
pixelDesc.cDepthBits = 32;
pixelDesc.cStencilBits = 8;
pixelDesc.cAuxBuffers = 0;
pixelDesc.iLayerType = PFD_MAIN_PLANE;
pixelDesc.bReserved = 0;
pixelDesc.dwLayerMask = 0;
pixelDesc.dwVisibleMask = 0;
pixelDesc.dwDamageMask = 0;
// find system pixel format
m_GLPixelIndex = ChoosePixelFormat( hDC, &pixelDesc);
if (m_GLPixelIndex==0) // Let's choose a default index.
{
m_GLPixelIndex = 1;
if (DescribePixelFormat(hDC, m_GLPixelIndex, sizeof(PIXELFORMATDESCRIPTOR), &pixelDesc)==0)
{
return FALSE;
}
}
if (SetPixelFormat( hDC, m_GLPixelIndex, &pixelDesc)==FALSE)
{
return FALSE;
}
return TRUE;
}
(3) 绘图不在OnDraw(),而在
void CxxView::OnPaint() 中
(4)绘图颜色用材料色,配光源色。基本绘图库程序是画空间直线,空间三角形,空间多边形。

例子:http://www.codeguru.com/cpp/g-m/opengl/
有许多实用程序(源程序)可下载,都是编译通过过的程序。