Skip to main content
Email Password   helpLost your password?

Sample Image - ogltools.jpg

Introduction

This article presents a set of helper classes that encapsulates OpenGL handling and really makes the programmer's life easier (and happier).

This piece of code was originally been written by W.Weyna 'Voytec'. All I did was to publish it to CodeProject.

Here are the main features of the package:

The main class: CWGL

CWGL is a Windows OpenGL rendering interface class. This header defines also a few interfacing wgl_ inlines.

The idea behind the CWGL is to make use of OpenGL in Microsoft Windows as simple as possible.

Under Windows only one OpenGL rendering context may be active in a single thread. CWGL helps you write a single threaded Windows application which need more than one OpenGL rendering context.

Usage:

Examples:

  1. In MFC view, render to window's backbuffer and swap buffers.
    //  CView.h
    
    
    CWGL m_wgl;
    //  CView.cpp
    
    CView::OnDraw(pDC)
    {
        m_wgl.Begin(pDC);
        glClearColor(1.0, 1.0, 1.0, 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
        m_wgl.End();
    }
  2. Render on DIB section GDI object and copy it to clipboard.
    CRGBSurface tmpSurf;    // CRGBSurface encapsulates a DIB section GDI object
    
    tmpSurf.Create(10, 10);
    
    CWGL wgl;
    wgl.Begin(tmpSurf.GetDC());
    glClearColor(1.0, 1.0, 1.0, 0.0)
        glClear(GL_COLOR_BUFFER_BIT);
    wgl.End();
    
    tmpSurf.CopyToClipboard();
  3. Rendering contexts may be 'nested' if different CWGL objects are used, but remember that only one RC can be created for one window.
    wgl1.Begin(&windowDC);
    {
        CWGL wgl2;
        wgl2.Begin(&bitmapDC);
        wgl2.End();
        // here wgl2 destructor delete's wgl2 RC and makes
    
        // wgl1 RC current again.
    
    }
    // here all the display lists and textures of wgl1 RC
    
    // remain valid
    
    wgl1.End(); 
  4. If you need an RC for a window for which you no longer have a device context available, you may call wgl.Begin() with no DC to make last used RC of this window current again.
    wgl.Begin(&windowDC);
    wgl.End(); 
    ...
    
    // some time in the future...
    
    wgl.Begin();
    wgl.End();
  5. After a call to CWGL::End() you may ask what the rendering time was with GetRenderingTime().

Notes:

When rendering on different DIB sections or bitmaps, a new RC with PFD_DRAW_TO_BITMAP pixelformat is always created for that bitmap.

WindowsNT: CWGL synchronizes GDI and OpenGL access to rendering surface automatically.

When switching RC's of different pixelformats with CWGL, all textures and display lists must be recreated in a new RC. Display list sharing is possible when RCs are of the same pixelformat (this means also that you cannot share between window and bitmap RC).

Please also note that under Windows, only one RC may be created for a given window and this RC cannot be used for another window.

Working with textures:

CGLTexture is a simple wrapper to OpenGL texture object. It enables easy changing of texture images, reusing existing texture object when possible.

More examples and Doc

A documentation of the classes has been generated and is available with the source code distribution.

Using the library in your app

  1. Include the OGLTools header in your StdAfx.h:
    #include "OGLT.h"
  2. Make sure the .h and .lib are available, if not add the corresponding directories to the project settings.
  3. That's it, the lib's will be automatically inserted.
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Generalusing OpenGL to read, save,.. file .bmp Pin
1vs1
20:55 8 Apr '05  
GeneralProblem encountered with CGLImage Pin
Allem77
22:46 9 Sep '04  
GeneralRe: Problem encountered with CGLImage Pin
Ian Miller
5:12 7 Jul '05  
GeneralRe: Problem encountered with CGLImage Pin
MasterGohan
11:58 9 May '06  
GeneralHow to run 2 different(or same) OpenGL objects in one DialogBox? Pin
werter1
22:53 5 Jun '04  
GeneralAbout FullScreen Pin
int
4:53 29 Nov '03  
GeneralUsing OGTL with dialog items Pin
Zeruel
8:26 10 Jan '03  
GeneralRe: Using OGTL with dialog items Pin
Jonathan de Halleux
22:32 13 Jan '03  
GeneralHelp Pin
Ali Khanlarkhani
2:47 19 Dec '02  
GeneralRe: Help Pin
Jonathan de Halleux
2:56 19 Dec '02  
GeneralRe: Help Pin
Ali Khanlarkhani
1:33 21 Dec '02  


Last Updated 15 Jul 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009