A WTL class for developping OpenGL programs using WTL






4.85/5 (9 votes)
Oct 2, 2001
2 min read

106101

3347
A class to develop OpenGL programs which can be easily plugged into your WTL programs
Overview
Recently, I studied up on how to write OpenGL programs. I have tried GLUT, a window system independent toolkit for writing OpenGL programs. But I don't like it since it is C-style and need an additional glut32.dll. I have played with WTL for a while, I really like this great framework for developing Win32 program, so I decided to write OpenGL programs using WTL.
Actually, WTL DOES provide OpenGL support in atlgdi.h
. If you didn't define _ATL_NO_OPENGL
,
you should be able to use ChoosePixelFormat
, wglCreateContext
, etc. However, you have
to do a lot of work every time to write an OpenGL program. For simplification, I developed a class COpenGL
which can be easily plugged into your WTL programs.
Using COpenGL
COpenGL
is a template class which implements most necessary work for OpenGL. It is defined in
atlopengl.h
. For using it in your program, you have to do the following steps: (assume your main program
is Cube.cpp
, your OpenGL window is CMainFrame
.)
- copy
atlopengl.h
toWTL\include
. - add
#include <atlopengl.h>
inCube.cpp
file. - derive your OpenGL window
CMainFrame
fromCOpenGL<CMainFrame>
. - chain message map to
COpenGL
by addingCHAIN_MSG_MAP(COpenGL<CMainFrame>)
inCMainFrame
's message map. - if you have implemented
OnCreate
function inCMainFrame
, setbHandled = FALSE;
beforereturn 0;
- implement three functions in
CMainFrame
:OnInit(), OnRender(), OnResize()
- (optional) if you want to do animation, derive
CMainFrame
fromCIdleHandler
and implementOnIdle
. In additional, changeCMessageLoop
toCGLMessageLoop
inCube.cpp
. (you have to do this, otherwise, you cannot get animation).
atlopengl.h
and the demo project for more details.
Conclusion
atlopengl.h
is still very simple, but it is a good start for writing OpenGL programs using WTL.
Comment
Partial codes in demo project generated by "OpenGL AppWizard" developed by Ulf Öhlén. See here for details.