ATL opengl

 #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()
, m_hGLRC()
{
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 */
, /* version */
PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER, /* support double-buffering */
PFD_TYPE_RGBA, /* color type */
, /* prefered color depth */
, , , , , , /* color bits (ignored) */
, /* no alpha buffer */
, /* alpha bits (ignored) */
, /* no accumulation buffer */
, , , , /* accum bits (ignored) */
, /* depth buffer */
, /* no stencil buffer */
, /* no auxiliary buffers */
PFD_MAIN_PLANE, /* main layer */
, /* reserved */
, , , /* 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();
}
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 = ;
m_hGLRC = ;
PostQuitMessage();
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, , ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
_Module.Term();
return ;
}
上一篇:MySQL 如何修改字符集 utf8 改为 utf8mb4


下一篇:mysql查看修改参数