目的:由于在写OpenGL程序的时候这些东西每次都要写一遍,而且特别繁琐!为了刚步入OpenGL人提供一个界面控件,让他们较早的看到自己写的OpenGL程序的效果!让他们觉得OpenGL的神奇!
作者:王卫星(wangweixing2000)
1, 新建一个ATL空项目(项目名OpenGL_ATL)
2, 添加一个ATL对象(MyControl)(VC6下为Full Control,VC7下为ATL控件)必须选中Su ort Co ection Points为了添加事件。
3, 在对象的.H头文件中添加:
#include <gl/gl.h>
#include <gl/glu.h>
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
4, 在接口实现类添加一个OpenGL 的RC(rendering context)成员变量:
HGLRC m_hRC
5, 添加一个设置OpenGL像素格式(接口实现类的)成员函数:
// Set OpenGL pixel format for given DC
BOOL MyControl::Setu ixelFormat(HDC hdc)
{
tatic PIXELFORMATDESCRIPTOR pfd =
{
izeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
FD_DRAW_TO_WINDOW | // su ort window
FD_SU ORT_OPENGL | // su ort OpenGL
FD_DOUBLEBUFFER, // double buffered
FD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
FD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int pixelformat;
if ((pixelformat = ChoosePixelFormat(hdc, &am fd)) == 0)
{
ATLA ERT(FALSE);
return FALSE;
}
if (SetPixelFormat(hdc, pixelformat, &am fd) == FALSE)
{
ATLA ERT(FALSE);
return FALSE;
}
return TRUE;
}
[1] [2] 下一页


