Click here to Skip to main content
11,805,266 members (52,091 online)
Click here to Skip to main content

CGLEnabledView - An MDI view class supporting OpenGL

, 30 Nov 1999 180.2K 8K 51
Rate this:
Please Sign up or sign in to vote.
A plug-in view class that provides OpenGL support
  • Download demo project - 82 Kb
  • Download source files - 15 Kb
  • Sample Image - glenabledview.gif

    <!-- Article Starts -->

    What is it

    CGEnabledView is a view class designed to wrap all OpenGL stuff (initialization, managing of Rendering Contexts and palettes, destruction, etc.) allowing the creation of multiple views in a MDI application.

    CGEnabledView also offers these basic services:

    • a function to get various information about the OpenGL implementation which is currently being used (separate information for the OPENGL and GLU libraries).
    • manages internally the creation of display lists and offers a primitive interface for display lists execution.
    • defines mouse cursor to be used inside the views.
    • offers an object oriented encapsulation of quadric objects for drawing of spheres, cylinders and disks.
    • offers an object oriented encapsulation of glu tessellator routines for translating non simple polygons (concave, self-intersecting and with holes) in groups of simple ones (triangle strips and fans).
    • presents a simple interface to draw text strings as 2D bitmaps or complete 3D glyphs.


    This article uses the trackball code introduced in the companion article A virtual trackball rotation controller .

    To start experimenting OpenGL drawing you just need to follow these steps:

    1. Use AppWizard to geneate an MDI project.
    2. Substitute CView with CGLEnabledView in [YourProject]View.cpp and [YourProject]View.h.
    3. Use ClassWizard to remove the OnDraw and PreCreateWindow functions (delete the bodies too).
    4. Override the VideoMode function if you need to ask for a particular combination of color-buffer depth,depth-buffer depth and double-buffering mode.
    5. Override the OnCreateGL if you need to perform some initializations
    6. Override the OnDrawGL function and issue some GL calls.
    7. Remember to link OpenGL libraries (look at the top of GLEnabledView.cpp for explanations) before building your project.

    Since it's not adviseable to mix Windows GDI and OpenGL drawing commands some WM handlers have been made private, use the overridable virtual functions instead.
    Other details are in the demo code (wich should be well commented) which can be used as a good starting point.

    The Demo

    In the sample project you can open multiple views each presenting a sample scene and rotate them interactively with the mouse. You can get some information about OpenGL implementation via the Help/View OGL Info menu item. Look at the about dialog box for some shortcut-keys.
    This demo project shows the use of a virtual trackball controller which permits to rotate the scene as if you are manipulating a virtual sphere superimposed on the application child window.


    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

    Alessandro Falappa
    Software Developer (Senior)
    Italy Italy
    Living in Rome, Italy
    Computer addict since 12 years old (first computer: Commodore 64).
    Master degree in Computer Science.
    Very interested in computer generated graphics both real time (mainly OpenGL) and photorealistic rendering.

    You may also be interested in...

    Comments and Discussions

    Question2Tb Virtual Disk Pin
    nhchmg27-Jun-11 20:22
    membernhchmg27-Jun-11 20:22 
    Generalpainting flaw Pin
    jldavis2-Oct-08 12:17
    memberjldavis2-Oct-08 12:17 
    Generalrotation not around 0,0,0 Pin
    mimosa26-Sep-08 23:44
    membermimosa26-Sep-08 23:44 
    Questionc# Pin
    Tonnek9-Oct-07 11:45
    memberTonnek9-Oct-07 11:45 
    GeneralHi,dear Alessandro,I have some question about your artics Pin
    aqing1-Jul-04 7:20
    memberaqing1-Jul-04 7:20 
    GeneralHi,dear Alessandro,I have some question about your artics Pin
    aqing1-Jul-04 7:20
    memberaqing1-Jul-04 7:20 
    QuestionExcellence! How did you make the text output in the scene? Pin
    aqing27-Jun-04 5:59
    memberaqing27-Jun-04 5:59 
    QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox? Pin
    werter13-May-04 21:09
    memberwerter13-May-04 21:09 
    GeneralRedrawing without re-rendering Pin
    Phil Atkin29-Aug-03 2:11
    memberPhil Atkin29-Aug-03 2:11 
    GeneralRe: Redrawing without re-rendering Pin
    Alessandro Falappa31-Aug-03 23:58
    memberAlessandro Falappa31-Aug-03 23:58 
    Generalan excellent pointer Pin
    xhay23-May-03 0:19
    sussxhay23-May-03 0:19 
    GeneralHelp me Pin
    rockers13-Apr-03 6:54
    memberrockers13-Apr-03 6:54 
    How to draw lines3D or circle3D by mouse
    GeneralMDI & OpenGL Pin
    uNsignedINT22-Mar-03 12:06
    memberuNsignedINT22-Mar-03 12:06 
    QuestionCan't run debugger with the code??? Pin
    Anonymous27-Oct-02 0:39
    sussAnonymous27-Oct-02 0:39 
    GeneralVery Impressive Pin
    Assajac15-Oct-02 0:23
    sussAssajac15-Oct-02 0:23 
    GeneralTextures Pin
    ste26-Aug-02 3:34
    memberste26-Aug-02 3:34 
    Generalsave the OpenGL view Pin
    bluntagain8-May-02 9:07
    memberbluntagain8-May-02 9:07 
    GeneralRe: save the OpenGL view Pin
    kooktroop11-Oct-03 22:32
    memberkooktroop11-Oct-03 22:32 
    Generaltitle bar Pin
    redspy4-Apr-02 3:00
    memberredspy4-Apr-02 3:00 
    GeneralRe: title bar Pin
    dineshkumarkataria7-Oct-08 3:22
    memberdineshkumarkataria7-Oct-08 3:22 
    GeneralVery helpful Pin
    Anonymous18-Feb-02 2:53
    memberAnonymous18-Feb-02 2:53 
    GeneralHelp!!! in Fill Contour Pin
    Anonymous15-Oct-01 5:23
    memberAnonymous15-Oct-01 5:23 
    GeneralBeware: PrepareCharset2D() Pin
    Kristian Nilssen30-Aug-01 5:29
    memberKristian Nilssen30-Aug-01 5:29 
    GeneralMemory overflow when opening lots of documents Pin
    Jonathan de Halleux8-Jun-01 7:53
    memberJonathan de Halleux8-Jun-01 7:53 
    GeneralWon't Run on Win2k Pin
    Randy Mardak21-May-01 19:53
    memberRandy Mardak21-May-01 19:53 

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

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

    | Advertise | Privacy | Terms of Use | Mobile
    Web04 | 2.8.151002.1 | Last Updated 1 Dec 1999
    Article Copyright 1999 by Alessandro Falappa
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid