Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Cutting Edge Direct 3D Programming
(Publisher: The Coriolis Group)
Author(s): Stan Trujillo
ISBN: 1576100502
Publication Date: 11/01/96

Bookmark It

Search this book:
 
Previous Table of Contents Next


The RMWin::OnSize() Function

The OnSize() function is called whenever the window is resized. This is important because Direct3D devices cannot be resized. This means that the OnSize() function must destroy and rebuild the device whenever the window is resized. Since viewports are attached to devices, the viewports must also be destroyed and rebuilt. The OnSize() function for the MultiView demo looks like this:

void RMWin::OnSize(UINT type, int cx, int cy)
{
    CFrameWnd::OnSize( type, cx, cy );

    if (!device)
        return;

    int newwidth = cx;
    int newheight = cy;

    if (newwidth && newheight)
    {
        int old_dither = device->GetDither();
        D3DRMRENDERQUALITY old_quality = device->GetQuality();
        int old_shades = device->GetShades();
        viewport1->Release();
        viewport2->Release();
        viewport3->Release();
        device->Release();
        d3drm->CreateDeviceFromClipper( clipper, GetGUID(),
                newwidth, newheight, &device );

        device->SetDither( old_dither );
        device->SetQuality( old_quality );
        device->SetShades( old_shades );

        CreateViewports();
    }
}

The function first stores the current device settings. These settings are used to configure the new device once it has been created. The Direct3DRMDevice GetDither(), GetQuality(), and GetShades() functions are used to retrieve the device settings.

Next, all three viewports and the device are released. A new device is then created using the Direct3DRM CreateDeviceFromClipper() function. The new device is configured with the previously saved settings.

Notice that it isn’t necessary to destroy and create the three camera frames. The CreateViewports() function (the last function call in the OnSize() function) will use the existing camera frames to createand position the new viewports.

The RMWin Viewport Functions

The MultiView demo provides menu options that allow each viewport to be configured. One menu is provided for each of the three viewports. We’ll discuss the message-handling functions for the first viewport here. The code for the remaining two viewports is virtually identical to these functions.

void RMWin::OnViewport1Disabled()
{
    view1setting=VIEWPORT_DISABLED;
    viewport1->Clear();
}

void RMWin::OnViewport1Front()
{
    view1setting=VIEWPORT_FRONT;
    ConfigViewport( camera1, view1setting );
}

void RMWin::OnViewport1Left()
{
    view1setting=VIEWPORT_LEFT;
    ConfigViewport( camera1, view1setting );
}

void RMWin::OnViewport1Right()
{
    view1setting=VIEWPORT_RIGHT;
    ConfigViewport( camera1, view1setting );
}

void RMWin::OnViewport1Top()
{
    view1setting=VIEWPORT_TOP;
    ConfigViewport( camera1, view1setting );
}

Each of the functions assigns a different value to the view1setting data member. The OnViewportDisabled() function uses the Direct3DRMViewport Clear() function to reset the viewport. The remaining functions use the ConfigViewport() function to configure the viewport according to the new setting.

Conclusion

It is entirely possible that the applications that you are going to write with Direct3D will use viewports solely for viewing scenes. If, however, you need to implement viewport operations such as zooming or picking, this chapter will give you a strong start.

In the next chapter, we’ll talk about using DirectDraw and Direct3D together, to create applications that push Windows out of the way and take over the whole screen.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.