COpenGLView class

Use the COpenGLView class when you are building MFC applications with using ClassGL library.

The COpenGLView class is inherited from the MFC’s CView class. It provides the same functionality as the base CView class. The COpenGLView class extends the base class with OpenGL rendering capable window by creating OpenGL rendering context in the CView object window. Plus, the COpenGLView class provides handling of user interface commands for view navigation, rendering context settings, antialiasing and printing.

Using the COpenGLView class

Creating new ClassGL project

The recommended way of creating application with using the OpenGLView class is to create the application using one of the ClassGL sample projects (for example the OglSample project) as an template. Use the CreateProjectFiles tool, which is located in the ClassGL\Tools directory to create your project. Please, note that all OpenGL rendering should be implemented in the DrawScene method in your View class, not by using the OnDraw method. For drawing GDI part of the scene override the COpenGLView:DrawGDIScene method and place the GDI calls there.

If you don’t want some functionality inherited from the ClassGL sample project, delete the code related to it.

Moving OpenGL code from existing project to ClassGL project

1.Create your project with ClassGL\Tools\CreateProjectFiles tool using the EmptyProject ClassGL sample project as template. For the project use the same name as your existing project.
2.Replace created ClassGL project’s Document and View files by the files from your existing project.
3.In the header file (.H) of your View class, change all occurrences of the CView string with COpenGLView string. Do the same in the implementation (.CPP) file of your View class.
4.Put all implementation and header files for the classes and functions used in the existing project’s Document and View classes to the newly created ClassGL project. Copy the relevant project settings (such as include files, libraries, preprocessor definitions settings) from your existing project to the created ClassGL project.

After these steps, the ClassGL project should be ready. However, in some cases the pattern showed in this paragraph have to be modified or extended in order to conform specifics of your existing project.

Creating new ClassGL project using MSVC Application Wizard, or using existing MFC project’s framework

If you want to create your project using the Application Wizard, or if you want to use an existing project’s framework, follow these steps:

1.Create your project using MFC Application Wizard (omit this step if you project is already created)
2.Follow instructions described in the Setting up a project for using the ClassGL library
3.Add the MfcClasGL.cpp to the Source Files folder of your project files, MfcClassGL.h file to the Header Files folder of your project files. The MfcCalssGL.cpp and MfcClassGL.h files are delivered with the OglSample sample application in the source code form, you can copy these files from there.
4.In the header file (.H) of your View class, change all occurrences of the CView string with COpenGLView string. Do the same in the implementation (.CPP) file of your View class.

On the beginning of the header file (.H) of your View class, insert following line:

#include “MfcClassGL.h”

6.Delete the OnDraw, OnBeginPrinting, OnEndPrinting, OnPreparePrinting, OnPrint (if any) methods from your View class using MSVC Class Wizard.
7.Place User Interface entries (such as menu items and toolbar buttons) in your application’s resource file using following identifiers for the COpenGLView class handled messages. Note that after adding these entries, you most probably have to rebuild all project in order to make them work due to incorrect (in some cases) detecting of dependencies in MSVC.
ID_FIT_ALLFit all scene into view
ID_FIT_SELECTEDFit selected object into view
ID_SELECT_OBJECTSelecting objects
ID_ZOOM_WINDOWZoom by specifying the zoom window.
ID_ROTATERotating the view and document objects
ID_PANPanning the view and document objects
ID_ORTHOTo switch between Orthographic and Perspective projections
ID_KEEP_SCALETo switch between Keep Picture and Keep Scale modes
ID_LIGHTINGTo switch on/off lighting
ID_LOCAL_VIEWERTo switch on/off the “local viewer” lighting mode
ID_ANTIALIASINGTo Turn antialiasing on or off.
You don’t have to support all these interface entries, you can use how many you want from them, however be sure to use identifiers above.
8.You might want to use toolbars from the ClassGL sample applications, such as toolbar for Zoom In/Out etc. Please, copy the appropriate resource file from some ClassGL sample application to your project directory and include it to your project using the resource editor.
9.Override the COpenGLView::DrawScene method in your View class. Implement all OpenGL rendering code into the DrawScene method. (for existing projects, move all previous OpenGL rendering code from the OnDraw method there). Please, see the ClassGL example projects, such as the OglSample project, for example of implementation of the DrawScene method.
10.In this point, you might want to update Class Wizard information. In MSVC Version 5.0, you can delete the .CLW file of your project and regenerate the .CLW file using existing project files by opening the Class Wizard. For higher versions of the MSVC please, follow your MSVC documentation, however this step will be most probably the same as with MSVC 5.0.

To add the View Angle Control Dialog, please use following names for the identifiers:

CG_IDD_VIEWCONTROLfor dialog resource ID
ID_VIEW_ANGLE_CONTROLfor Slider dialog control controlling the view angle
ID_VIEW_ANGLEfor edit text dialog control displaying current view angle

Note:For converting existing project for using the ClassGL library, use workflows described in this section just as coarse guidelines, in many cases they need to be modified to conform specifics of your project.