今天写了个基于mfc对话框的opengl类:copengl,可以在对话框程序中使用opengl了,并且提供了全屏与非全屏转换的两个函数,很容易使用,速度快. 可以到这里下载demo project.有什么意见或问题,请大家给我留言.:) 使用方法:在对话框上加一个static控件(或者其他的也可以),在oninitdialog()中加人下面这段代码(假设控件id为idc_opengl,m_opengl是类copengl的对象): codedivstart() crect rect; getdlgitem(idc_opengl)->getwindowrect(rect); screentoclient(rect); m_opengl.create(rect, this); codedivend() 然后在适当的地方调用m_opengl.renderglscene()就可以了. 以下是类代码(opengl.h与opengl.cpp): codedivstart() #if !defined(afx_opengl_h__38b5d1c8_2dff_4a7d_9a99_3ac401c19d72__included_)#define afx_opengl_h__38b5d1c8_2dff_4a7d_9a99_3ac401c19d72__included_
/////////////////////////////////////////////////////////////////////////////// copengl window 【程序编程相关:Implement the 3D vie】
#if _msc_ver > 1000#pragma once#endif // _msc_ver > 1000// opengl.h : header file// 【推荐阅读:利用DirectShow开发自己的Fil】
// attributespublic: 【扩展信息:[C++]监控特定文件夹的事件:三种解决】
class copengl : public cwnd{// constructionpublic: copengl();
// operationspublic:
// overrides // classwizard generated virtual function overrides //{{afx_virtual(copengl) //}}afx_virtual
// implementationpublic: bool setnormscreen(); bool setfullscreen(int width, int height, int depth); virtual void renderglscene(); void create(crect rect, cwnd *parent); virtual ~copengl();
// generated message map functionsprotected: crect m_rect; cwnd* m_parent; bool m_bfullscreen; devmode m_dmsaved; bool m_binit; int initgl(); void killglwindow(); hdc m_hdc; hglrc m_hrc; //{{afx_msg(copengl) afx_msg int oncreate(lpcreatestruct lpcreatestruct); afx_msg void onpaint(); afx_msg void onsize(uint ntype, int cx, int cy); //}}afx_msg declare_message_map()};
/////////////////////////////////////////////////////////////////////////////
//{{afx_insert_location}}// microsoft visual c++ will insert additional declarations immediately before the previous line.
#endif // !defined(afx_opengl_h__38b5d1c8_2dff_4a7d_9a99_3ac401c19d72__included_) codedivend() codedivstart() // opengl.cpp : implementation file//
#include "stdafx.h"#include "dialogopengl.h"#include "opengl.h"#include <gl/gl.h>#include <gl/glu.h>
#ifdef _debug#define new debug_new#undef this_filestatic char this_file[] = __file__;#endif
/////////////////////////////////////////////////////////////////////////////// copengl
copengl::copengl():m_binit(false),m_bfullscreen(false), m_hdc(null),m_hrc(null),m_parent(null){}
copengl::~copengl(){ killglwindow(); // shutdown}
... 下一页