Textures

Most objects in Shattered World are textured.

files/lowpolysoup.jpg

Texturing involves applying a 2D image to the surface of a shape like a bowl of soup. In most glscene objects a texture is applied directly to the outside of the object such as a cube. Other objects like freeform's and actor's can have different parts of a texture mapped to different parts of model such as an arm texture being mapped to the left arm and the same part of the texture mapped to the right arm.

files/actortexturemapping.jpg

In freeform's and actor's the textures used can be defined in the model itself. In other glscene objects they are specified in the 'texture' attribute of an object. Thus for a cube object you can apply a cloud texture as follows:

<CUBE cubeheight="0.2" cubewidth="0.3" cubedepth="0.1" texture="textures\clouds.jpg"/>

where the clouds.jpg file will be in c:\program files\mudclient\client\textures

The cloud texture will be applied using default texture settings specified in texturesettings eg texture scale is 1. To change the texture settings of a texture you can specify the texture in the textures element. For example if you wanted to scale the texture so it was scaled to be 6 times smaller and set the TEXTURE element to:

<TEXTURE texture="textures\clouds.jpg" scale="6" texturewrap="both" />

textures can be shared eg a cube and freeform can shared the same texture thus saving memory.

It is possible to use images when texturing. For example it is possible to draw a red cube:

<CUBE cubeheight="0.2" cubewidth="0.3" cubedepth="0.1" texture="@red"/>

The corresponding texture in texturelist would be:

<TEXTURE texture="@red" frontpropertiesemission="FF0000" />

The '@' symbol represents a texture that has no image.

Making Textures
One way to make a texture is to take a photograph and crop the part you like in gimp. For example when making a wood texture you might crop a part of a wooden cabinet. If the texture is repeating eg wood you can use 'make seemless' in the 'filters' menu of gimp so that it repeats seemlessly.

files/soup.jpg

OpenGL scales textures to the power of 2 in memory thus a 129x 128 pixel texture will be stored in memory as 256x 128 pixels thus it is wise to scale textures yourself to the power of 2 eg to 128x128 to save video card memory.

Transparent textures
Textures can be transparent. For example in Shattered World windows are drawn by using transparent textures:

files/texturetransparent.jpg

using the texture:

files/texturetransparent2.jpg

This reduces the number of polygons required to draw a town so increases frame rate.

It also useful in displaying vegetation. A transparent texture on a sprite can display plant for example:

files/sprites.jpg

Transparency in a texture can be specified in an alpha channel in files with the '.tga' format. Jpegs have no alpha channel therefore cannot store transparency. An example of a transparent texture in Shattered World is:

c:\program files\mudclient\client\textures\clock.tga

In GIMP you can click on the 'erase' button to erase more parts around the clock. To view the clock in a plane you would use:

<PLANE name="clock" texture="textures\clock.tga" height="0.4" width="0.2"/>

and in texturelist set 'imagealpha' to default:

<TEXTURE name="textures\clock.tga" imagealpha="default"/>

If you do not use an image with an alpha channel you can also specify transparency with superblacktransparency. Superblack transparency means that everything in the image that is black will be made transparent. This article gives more information about superblack transparency:

http://glscene.sourceforge.net/wikka/UsingSuperBlackTransparency

Instead of imagealpha="default" you'd use imagealpha="superblacktransparency"

If you want to make a texture transparent in its entirety you dont need an alpha channel or superblack transparency. You can just set the 'alpha' attribute of a TEXTURE so that it less than 1. For example if you want to make a transparent red cube you can define the following cube:

<CUBE cubeheight="0.2" cubewidth="0.3" cubedepth="0.1" texture="@red"/>

The corresponding texture in texturelist would be:

<TEXTURE texture="@red" frontpropertiesemission="FF0000" alpha="0.5" />

Moving Textures
In Shattered World you might have noticed the Gargoyles have a moving texture such as:

This is achieved by setting the 'addscaledvectorx' and/or 'addscaledvectory' attributes in the TEXTURE element in texturelist. For example:

<TEXTURE texture="models\gargoyle.jpg" addscaledvectorx="0.1"/>

will scroll the texture in the x texture direction repeating every 10 seconds.

Secondary Textures
Secondary textures are where you apply one texture to an object then a second texture over the top:

files/texturesecondary.jpg

This is useful if for example you have a low detail 256x256 terrain texture that you map directly onto the terrain. To add detail to the ground you might apply a repeating secondary texture such as stones to give the appearance of detail.

To use secondary textures in the mud client you set the 'texture2name' attribute in the TEXTURE element to the name of the secondary texture. This 'texture2name' will then reference another texture in the texturelist. Unfortunately secondary textures can greatly reduce frame rate therefore are not used in Shattered World.

Texture Management in the mud client
When an actor for instance leaves the room the actor model is destroyed but the texture remains in memory in case other actors are using it and if the actor were to come back into the room the texture is still in memory. This stops textures being unloaded and reloaded unnecessarily. But if a texture stays in memory too long without being used it can waste video memory so every 60 seconds the mud client will go through every texture in memory and test if it is being used. If it isnt it is deleted.

Cubemap Reflection
The above video in moving textures shows a moving texture. On top of that it has uses cubemap reflection to give the appearance of shininess. Cubemap reflection can be switched on by setting the attribute 'mappingmode' to cubemapreflection. For example:

<TEXTURE texture="models\gargoyle.jpg" mappingmode="cubemapreflection" addscaledvectorx="0.1"/>

Texture Settings based upon extensions
The mud client allows texture settings to be specified based upon the OpenGL extensions a persons PC has. This allows different default texture settings to be set based upon how good a persons PC's. For example a low grade PC that doesnt accept the extension GL_ARB_texture_env_combine might have the maximum sized texture limited to 512 pixels wide or high. The following example has the maximum texture size set to 512 if the PC doesnt have the GL_ARB_texture_env_combine extension while it is 1024 if it does have it. Likewise the default texture can be set based upon the extensions:

<TEXTURESETTINGS>

<TEXTURESETTING maxtexturesize="512" withoutextensions="GL_ARB_texture_env_combine" defaulttexture="@lindos"/>
<TEXTURESETTING maxtexturesize="1024" withextensions="GL_ARB_texture_env_combine" defaulttexture="@lindos"/>

</TEXTURESETTINGS>