Editing Images


Over the course of this book, you have seen images used for a wide variety of purposes including textures for objects, terrain height maps, splash screen backgrounds, and buttons . In order to create and manipulate these images, you will need one or more image editing tools.

Editing Images in General

Every copy of Microsoft Windows comes with the Paint program. This program provides simple editing capability. Although Paint does provide the ability to edit an image, it is limited in the file formats it supports ” numerous types of Windows bitmap (.BMP and .DIB) files as well as JPEG, GIF, TIFF, and PNG format files ”and the tools it supplies . One of the major features that it lacks is the ability to manipulate transparency information in an image.

Note

If you choose to use the Windows bitmap formats, be sure to use the 24-bit color version. The other two color formats use either 4 or 8 bits per pixel and require palette management. The 24-bit style contains all of the color information for each pixel within the image data. When you add the transparency data, you move up to 32 bits with the 8 bits of alpha information.

To get serious about image editing requires a more powerful tool. The tool of choice is Adobe Photoshop (http://www.adobe.com). This package is not cheap at a list price of $609, but it provides any image editing feature you could think of. This includes a wide range of filtering options as well as the ability to work with each color channel and the alpha transparency channel individually.

Creating Textures

The creation of textures for models and billboards is the most common use for the image editing tool. If you do have Photoshop, you have everything that you need. You can create any transparent areas needed within a texture.

Note

Remember to create your textures with dimensions that are a power of two. Video cards can manage the textures much more efficiently if both dimensions of the texture meet this requirement.

If you do not have Photoshop, you are not out of luck. You can still create textures with Microsoft Paint and add the alpha channel using the texture tool provided by Microsoft with the DirectX SDK ( DxTex.exe ). The texture tool can work with any of the texture formats that Paint can create with the exception of the GIF format. It also has its own format (DirectDraw Surface, or DDS) that it can read and write. The DDS format is a 32 bit per pixel format that includes the alpha transparency information.

To create a texture with transparency requires that you create two images with Paint. The first image is the normal view of the image with the color information. The second image is a gray-scale image the same size of the first. You load the first image into the texture tool. You then open the second image in the alpha channel within the tool. Any pixels that are white in the second image will be opaque in the composite image. Any pixels that are black in the second image will be completely transparent. Gray values will be partially transparent based on the intensity of gray. The composite image may then be saved into a DDS file for use by the game.

Creating Height Maps

Remember in Chapter 4 that we used a height map image to control the shape of the terrain. The height map is a gray-scale image. The intensity of each pixel in the image represents the elevation of the corresponding point in the terrain. This height map can be generated either manually or programmatically. Any image editing tool will work for this. A tool like Photoshop will provide a smoother looking terrain since it has the ability to apply color gradients to an image. It also includes a blurring filter to smooth transitions between manually applied colors.

There are several automated approaches to creating a height map. The Microsoft DirectX 9 SDK includes a C++ sample called Fractal. This sample uses fractal mathematics to create a height map and then render it to the screen as terrain. This sample could easily be ported to C# and coupled with the screenshot code used in the sample game to save the generated height map images.

An excellent freeware height map generator is also available at SourceForge (http://hme. sourceforge .net). Since this is an open source project, it comes with the source code so that you may modify and expand it to meet your needs.




Introduction to 3D Game Engine Design Using DirectX 9 and C#
Introduction to 3D Game Engine Design Using DirectX 9 and C#
ISBN: 1590590813
EAN: 2147483647
Year: 2005
Pages: 98

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net