Game Development Reference
In-Depth Information
Switching scenes
Having set up the game or demo to use several scenes, we need to
consider the steps necessary to switch a scene. First, we must delete any
resources that are unique to the current scene. These include texture
objects and fonts. Then we create any new textures. In the source code
from Toon3D the user is offered three options for texture quality. At the
highest level the full texture size is used. If frame rates are suffering the
user can choose to show textures at half or quarter size. The bitmap that
supplies the texture to OpenGL is resized before being passed. Another
memory saving option is not to use MipMaps. You will know from the
OpenGL chapters that MipMaps are multiple sizes of bitmap texture that
can be created with better filtering at creation time and then used at
runtime to avoid the sparkling inherent in using the nearest pixel method
for filtering a scaled bitmap. For full details, refer to Chapter 4. OpenGL
uses a texture ID to reference a texture. We need to ensure that our
surfaces refer to the correct texture ID that is only determined at runtime.
For this reason, we iterate through all the surfaces and set the appropriate
texture ID by matching the texture name and the GL texture name. Scene
switching is finalized by the creation of any GL fonts that may be used and
the transformation of all objects in the scene by setting a starting frame.
Remember that GL fonts use display lists which, once created, are the
responsibility of the calling program to delete.
BOOL CToon3DDoc::SetScene(CToon3DScene *scn)
//Return if the choosen scene is already selected as active
if (scn==selScene) return FALSE;
//Deselect any object, surface, image etc;
//Clear existing GL textures
if (selScene && selScene->texTotal){
for (int i=0;i<selScene->texTotal;i++){
//Clear existing fonts
if (selScene) selScene->textList.ClearGLFonts();
glClearColor(scn->bgCol[0], scn->bgCol[1], scn->bgCol[2], 1.0f );
Search Nedrilad ::

Custom Search