参考自PicZoom: A Photo Viewer Created in OpenGL
1. 新建MFC对话框工程,Use Unicode Libraries。该图片浏览器共分为4部分:背景、图像区域、关闭按键、底层按键栏。先来实现背景的绘制
2. 背景,首先来实现两个基类GLSetup和GLWindowBase,GLSetup是设置OpenGL绘制环境,GLWindowBase则是所有OpenGL窗口的基类
有几点注意:本程序没有使用glew库,添加lib文件opengl32.lib glu32.lib,GLSetup::InitGL()中不仅创建了绘制环境,也根据当前应用程序窗口设置了投影矩阵
如何使用GLSetup
// PicZoomDlg.h
class GLSetup;
class CPicZoomDlg : public CDialog{
private:
GLSetup* m_pGLSetup;
void Draw();
//.....
};
/// 1.构造函数中初始化
m_pGLSetup = 0;
/// 2.OnInitDialog()中
m_pGLSetup = new GLSetup();
/// 3.Initialize Drawing Context.
if( !m_pGLSetup->InitGL( m_hWnd )){
AfxMessageBox( L"OpenGL Initialisation failed" );
}
else{
int nError = glGetError();
if( GL_NO_ERROR != nError ){
AfxMessageBox( L"Opengl initilisation fai