![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
Direct3DRMTexture: The Texture InterfaceIn Direct3D, textures can be applied to faces and meshes or added directly to a scene as a background image or decal. Textures can be loaded from BMP files, PPM files, from a programs resources, or from memory. Textures are represented with the Direct3DRMTexture interface. Creating TexturesThe easiest way to create a texture is to use the Direct3DRM LoadTexture() function: LPDIRECT3DRM texture; d3drm->LoadTexture("texture.bmp", &texture ); LoadTexture() takes the name of a BMP or PPM file as an argument and uses the bitmap file to create a texture. Textures can also be created and loaded from a programs resources by using the LoadTextureFromResource() member function as shown below: LPDIRECT3DRMTEXTURE texture; HRSRC id = FindResource( NULL, MAKEINTRESOURCE(IDR_SAMPLETEXTURE), "TEXTURE" ); d3drm->LoadTextureFromResource( id, texture ); The Direct3DRM LoadTextureFromResource() function takes a resource ID as a parameter and creates a texture from the resource indicated by the id variable. Internally, Direct3D uses DirectDraw surfaces to represent textures. The LoadTextureFromSurface() member function allows existing DirectDraw surfaces to be used as textures. Texture ColorsOnce an instance of the Direct3DRMTexture interface has been created, the GetColors() and SetColors() member functions can be used to control how many colors Direct3D uses to represent the texture. Together with the GetShades() and SetShades() member functions, you have precise control over how a texture is rendered. The number of colors in a texture (the setting controlled by GetColors() and SetColors() functions) determines the number of distinct colors present in the texture itself. The GetShades() and SetShades() member functions control how many shades are used to represent each color in the texture. For example, if a texture has only two colors, the GetColors() member function will return the value 2, and the GetShades() member function will return the value 16 (because 16 is the default number of shades). In this example, each of the two colors in the texture will be represented by 16 variations of the color. Reducing either the number of colors or shades that a texture uses will reduce the clarity of the final output but allow specific textures to be favored over others. For example, if a texture uses many colors but is used in such a way that its clarity isnt important, its colors and shades can be reduced, reserving more colors and shades for a texture whose appearance is of more importance. DecalsA decal is a texture that is added to a scene without being applied to a face or a mesh. Decals are rendered into a scene with respect to their location, so they grow and shrink depending on their distance from the viewer. Decals also obey hidden surface rules. If a decal appears behind an object, it will be occluded by the object. Decals have one major drawback: they always appear facing the viewer, so they cannot be viewed from different angles. This limits their usefulness considerably. If they could be oriented away from the camera, they could be used, for example, to represent paintings in a museum scene or monitors on the deck of a spaceship. Nevertheless, decals are great for rendering two-dimensional images into scenes. Effects that are computationally expensive to implement with meshes and faces can often be simulated efficiently with decals (explosions, for example). The Direct3DRMTexture interface offers a number of decal manipulation member functions.
Most of the decal member functions are used only with decals. The transparency member functions, however, are used to control transparency for decals as well as textures that are applied to meshes and faces.
|
![]() |
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. |