Click here to Skip to main content
14,981,532 members
Articles / Desktop Programming / WTL
Posted 1 Oct 2001


32 bookmarked

A WTL class for developping OpenGL programs using WTL

Rate me:
Please Sign up or sign in to vote.
4.85/5 (10 votes)
1 Oct 20012 min read
A class to develop OpenGL programs which can be easily plugged into your WTL programs

Sample Image


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 to WTL\include.
  • add #include <atlopengl.h> in Cube.cpp file.
  • derive your OpenGL window CMainFrame from COpenGL<CMainFrame>.
  • chain message map to COpenGL by adding CHAIN_MSG_MAP(COpenGL<CMainFrame>) in CMainFrame's message map.
  • if you have implemented OnCreate function in CMainFrame, set bHandled = FALSE; before return 0;
  • implement three functions in CMainFrame: OnInit(), OnRender(), OnResize()
  • (optional) if you want to do animation, derive CMainFrame from CIdleHandler and implement OnIdle. In additional, change CMessageLoop to CGLMessageLoop in Cube.cpp. (you have to do this, otherwise, you cannot get animation).
Similarly you can use it in your view windows. Read atlopengl.h and the demo project for more details.


atlopengl.h is still very simple, but it is a good start for writing OpenGL programs using WTL.


Partial codes in demo project generated by "OpenGL AppWizard" developed by Ulf Öhlén. See here for details.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
No Biography provided

Comments and Discussions

Praisethe code is eternal - thanks! Pin
phoenicyan28-Nov-16 16:34
Memberphoenicyan28-Nov-16 16:34 
Generala small correction of COpenGL::OnSize(..) Pin
Hunt Chang5-Oct-09 18:42
MemberHunt Chang5-Oct-09 18:42 
GeneralRe: a small correction of COpenGL::OnSize(..) Pin
bible~9-Aug-11 18:28
Memberbible~9-Aug-11 18:28 
Questionwhat is the function of CGLMessageLoop? [modified] Pin
Hunt Chang29-Sep-09 18:40
MemberHunt Chang29-Sep-09 18:40 
Generalatlres.h Pin
peterdrozd20-Dec-05 8:16
Memberpeterdrozd20-Dec-05 8:16 
GeneralOpengl error Pin
Anonymous24-Apr-05 10:10
MemberAnonymous24-Apr-05 10:10 
GeneralRe: Opengl error Pin
tdziki11-Jan-07 10:25
Membertdziki11-Jan-07 10:25 
GeneralI use my view derived from COpenGL&lt;&gt;, and it works well Pin
gu mingqiu13-Sep-04 2:50
Membergu mingqiu13-Sep-04 2:50 
QuestionFullscreen/Windowed switch? Pin
_leech_25-May-04 20:01
Member_leech_25-May-04 20:01 
QuestionHow to draw openGl in dialog box use WTL Pin
Anonymous7-May-04 21:22
MemberAnonymous7-May-04 21:22 
GeneralSome problems on Win2K Pin
cdr8-Oct-01 17:18
Membercdr8-Oct-01 17:18 
GeneralRe: Some problems on Win2K Pin
Zilin10-Oct-01 6:26
MemberZilin10-Oct-01 6:26 
GeneralRe: Some problems on Win2K Pin
cdr11-Oct-01 19:17
Membercdr11-Oct-01 19:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.