Using the Window3D class

From Solid Graphics Wiki

Jump to: navigation, search

This article discuss various scenarios of using the Window3D class.


Using the Window3D class in MFC applications

Use C3DView class or C3DWindow class to use Window3D class features in MFC applications. These classes are derived from the Window3D class and implemented in SklMFC.h and SklMFC.cpp. Include the SklMFC.h and SklMFC.cpp files into the MFC application's project and compile them with the rest of the project source code files.

You can use the CreateProject tool included with the SolidKit Library to create initial version of your MFC project using MFC_MDI_Template or MFC_SDI_Template project (included in the SolidKit Library sample projects) as template.

Using the Window3D class with a window not created by any of the SolidKit library functions

If the window is created by some other framework and you want to use the Window3D class features in such window then you need to pass handling of the window's WM_CREATE, WM_DESTROY, WM_SIZE, WM_ERASEBKGND, WM_SETFOCUS, WM_KILLFOCUS, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MOUSEMOVE, WM_MOUSEWHEEL messages to the corresponding Window3D::OnWindow3D* message handlers. The WM_PAINT message must call Window3D::RenderBegin and Window3D::RenderEnd functions and the scene should be rendered between these two function calls. An example of such implementation are actually the C3DView and C3DWindow classes implemented in the SklMFC.h and SklMFC.cpp files

Using the Window3D class to create 3D view navigation window

If the application uses the Window::Create method to create a window for 3D scene navigation, then writing such application involves these steps:

  • derive a class from the Window3D class and override the DrawScene virtual function. You can also override the InitializeRenderingContextState function to provide custom rendering context state (such as lighting, texture modes etc) initialization.
  • implement your scene rendering into the overrided DrawScene function.
  • call Window::Create method on the derived class object's to create the 3D view navigation window, or if the derived class instance is supposed to be main application window then provide the instance as mainWindow parameter to the WindowsApplication::Run method (this also involves overriding the Window::ProcessWindowMessage function to implement main-window-specific handling of the window messages).

See SKL_3DGUI_Template SolidKit Library's project for example of such application.

Using the Window3D class for off-screen rendering

Call Window3D::CreateOffScreenWindow to create off-screen rendering context. Such context is most often used in programs which do no have graphics interface such as console applications or services.

Example of creating off-screen window, rendering a cube into it and saving rendered image into JPEG file
SKL3D::Window3D      view;
SKL3D::Shape         shape;
SKL3D::VectorList    shapeNormals;
SKL3D::ObjectPosInfo objectPosInfo
                       SKL3D::cOrigin,                           // shape's position
                       SKL3D::Vector( 30.0f, -20.0f, -10.0f )    // shape's rotation

// create (Box) shape and calculate it's normals
shape.CreateBox( 2.0f, 2.0f, 2.0f ); shape.CalculateNormals( shapeNormals, SKL3D::Flat );

// create 800x600 pixels sized off-screen (memory based) window
view.CreateOffScreenWindow( 800, 600 );
view.SetEyePoint( SKL3D::Point( 0.0f, 0.0f, 5.0f ), true );


SKL3D::DepthTestOn  depthTestOn;
SKL3D::LightingOn   lightingOn;
SKL3D::LightOn      lightOn;


// render scene
objectPosInfo.ObjectToWorldOGL();	// set object's position
SKL3D::DrawFlatShadedShape( shape, shapeNormals );


// save result to Screenshot.jpg file
view.SaveScreenShot( "Screenshot.jpg", true );

The above code is similar to code in the Console_Template sample application.

See Also

Personal tools