ATL opengl
2015-10-08 09:55
344 查看
#include <atlbase.h> #include <atlwin.h> #include <gl/glew.h> #include <gl/GL.h> #pragma comment(lib, "opengl32.lib") extern CComModule _Module; CComModule _Module; class MyWindow : public CWindowImpl<MyWindow, CWindow, CFrameWinTraits> { public: MyWindow() : m_hDC(0) , m_hGLRC(0) { Create(NULL, rcDefault); } public: DECLARE_WND_CLASS(_T("MyWindow")); BEGIN_MSG_MAP(MyWindow) MESSAGE_HANDLER(WM_CREATE, OnCreate) MESSAGE_HANDLER(WM_SIZE, OnSize) MESSAGE_HANDLER(WM_PAINT, OnPaint) MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd) MESSAGE_HANDLER(WM_DESTROY, OnDestroy) END_MSG_MAP() public: LRESULT OnCreate(UINT msg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { m_hDC = GetDC(); PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), /* size */ 1, /* version */ PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER, /* support double-buffering */ PFD_TYPE_RGBA, /* color type */ 16, /* prefered color depth */ 0, 0, 0, 0, 0, 0, /* color bits (ignored) */ 0, /* no alpha buffer */ 0, /* alpha bits (ignored) */ 0, /* no accumulation buffer */ 0, 0, 0, 0, /* accum bits (ignored) */ 16, /* depth buffer */ 0, /* no stencil buffer */ 0, /* no auxiliary buffers */ PFD_MAIN_PLANE, /* main layer */ 0, /* reserved */ 0, 0, 0, /* no layer, visible, damage masks */ }; int pixelFormat = ChoosePixelFormat(m_hDC, &pfd); SetPixelFormat(m_hDC, pixelFormat, &pfd); m_hGLRC = wglCreateContext(m_hDC); if (!m_hGLRC) { PostQuitMessage(0); } wglMakeCurrent(m_hDC, m_hGLRC); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); return true; } LRESULT OnSize(UINT msg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { return true; } LRESULT OnPaint(UINT msg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { if (m_hGLRC) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } if (m_hDC) SwapBuffers(m_hDC); return true; } LRESULT OnEraseBkgnd(UINT msg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { return false; } LRESULT OnDestroy(UINT msg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { wglMakeCurrent(NULL, NULL); if (m_hGLRC) wglDeleteContext(m_hGLRC); if (m_hDC) ReleaseDC(m_hDC); m_hDC = 0; m_hGLRC = 0; PostQuitMessage(0); return true; } public: void Show() { ShowWindow(SW_SHOW); UpdateWindow(); } private: HDC m_hDC; HGLRC m_hGLRC; }; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { _Module.Init(NULL, hInstance); MyWindow win; win.Show(); MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } _Module.Term(); return 0; }
相关文章推荐
- Apache Camel添加动态路由
- linux常用命令笔记
- linux内存机制简记
- linux常用工具系列----ctags
- Hadoop的多目录输出
- 深入解析Linux系统下的高端内存
- linux之cut用法
- OpenWrt的luci web管理器添加新菜单(二)
- linux 网卡配置详解 ifcfg-eth0
- 如何恢复Windows引导
- linux CentOS 下设置 tomcat开机自启动
- 从零自学Hadoop(08):第一个MapReduce
- linux常用小命令
- centos安装g++
- tomcat conf
- SRM 667 DIV2 OrderOfOperationsDiv2 500-point
- java程序执行Linux命令
- 一步步安装nginx搭建流媒体服务器
- Linux系统目录
- Ubuntu必备软件