博客日历
2025年07月 | ||||||
一 | 二 | 三 | 四 | 五 | 六 | 七 |
30 | 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 | 1 | 2 | 3 |
存档
2025年03月 2024年
03月 04月 05月 2021年
01月 02月 11月 12月 2020年
02月 03月 04月 05月 06月 07月
09月 2018年
09月 2017年
01月 02月 07月 2016年
01月 04月 07月 08月 11月 12月
2015年
01月 02月 03月 05月 09月 10月
11月 2014年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2013年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2012年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2011年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2010年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2009年
03月 04月 05月 06月 07月 08月
09月 10月 11月 12月
OpenGL.5 Win32下的OpenGL基本框架之更简单的封装
头文件OpenGL.h:
/*
使用方法:
1.在需要显示OpenGL的窗体中的OnCreate或InitDialog之类函数中执行EnableOpenGL()
2.在OnDestroy之类函数中执行DisableOpenGL()
3.在自己需要的地方如OnPaint中执行任意OpenGL函数,如果与显示有关,则在最后执行SwapBuffers()
*/
#pragma once
#include <Windows.h>
#include <GL/gl.h>
#pragma comment(lib,"opengl32.lib")
#include <GL/glu.h>
#pragma comment( lib, "glu32.lib")
#include <GL/glaux.h>
#pragma comment( lib, "glaux.lib")
class COpenGL
{
private:
HDC _m_hDC;
HGLRC _m_hGLRC;
HWND _m_hWnd;
public:
//返回值等于0,表示启用OpenGL成功
int EnableOpenGL(IN HWND hWnd);
//结束OpenGL的使用
void DisableOpenGL();
//交换缓冲区
void SwapBuffers();
};
源文件OpenGL.cpp:
#include "StdAfx.h"
#include "OpenGL.h"
int COpenGL::EnableOpenGL(IN HWND hWnd)
{
ASSERT(hWnd!=NULL && IsWindow(hWnd));
_m_hWnd=hWnd;
_m_hDC=::GetDC(_m_hWnd);
PIXELFORMATDESCRIPTOR pfd ;
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1 ;
pfd.dwFlags = PFD_SUPPORT_OPENGL|PFD_DRAW_TO_WINDOW|PFD_DOUBLEBUFFER;
pfd.cColorBits = 24 ;
pfd.cDepthBits = 32 ;
pfd.iLayerType = PFD_MAIN_PLANE ;
int nPixelFormat=ChoosePixelFormat(_m_hDC, &pfd);
if (!SetPixelFormat(_m_hDC,nPixelFormat,&pfd)){
return -1;
}
_m_hGLRC = wglCreateContext(_m_hDC);
if (_m_hGLRC==NULL){
return -2;
}
if (!wglMakeCurrent(_m_hDC, _m_hGLRC)){
return -3;
}
return 0;
}
void COpenGL::DisableOpenGL()
{
wglMakeCurrent(_m_hDC, NULL);
wglDeleteContext(_m_hGLRC);
::ReleaseDC(_m_hWnd,_m_hDC);
};
void COpenGL::SwapBuffers()
{
::SwapBuffers(_m_hDC);
}
上一篇: OpenGL.4 Win32下的OpenGL基本框架:对OpenGL简单的封装,使用wgl
下一篇: 用DPInst.exe/devcon.exe从命令行自动安装驱动程序
分类:Win32/C++ 查看次数:6547 发布时间:2009/12/9 17:30:40