CSharp .Net Tutorial: Loading Textures in Truevision 3D

James Cloud
Introduction

3D games use textures to make their otherwise plain 3d models into life like looking objects. A tree without a leaf and wood texture would look utterly boring and would have no place in any respectable game. Follow the simple steps given below to learn how to load texture files and apply these textures to your 3D objects using the Truevision 3D engine and CSharp .Net.

Please note that this tutorial was made using version 6.5 of Truevision 3D.

Step One - Creating the Texture Factory

In order to be able to load texture images into the game engine, the texture factory object must first be defined. In your project's declaration code place,

public TVTextureFactory textureFactory;

In your initialization code add,

textureFactory = new TVTextureFactory();

Now that the texture factory has been successfully added to the project, proceed to step two below.

Step Two - Loading Textures

It is a good idea to have a separate function set aside entirely for just loading textures. Call this function loadTextures() using the source code given here,

private void loadTextures()
{
// Load Textures
Textures.LoadTexture(TexPath + "Grass.jpg", "Grass");
Textures.LoadTexture(TexPath + "Dirt.jpg", "Dirt");
}

To load a texture, call the 'LoadTexture()' method inside the texture factory object. The first parameter is the path to the texture file, and the second parameter is an optional name for the newly created texture.

Make sure to call the 'loadTextures()' function after the engine initialization and before the game's main loop.

Conclusion

Here is an example on how to apply textures to a TVMesh object:

// Apply the Grass Texture to the Grass Object
objGrass.SetTexture(Globals.GetTex("Grass"));

You can also apply multiple textures to specific groups of a model. Use the 'SetTexure()' method's second overload to achieve this. For example,

// Apply the bark texture to the trunk of the tree model
Tree.SetTexture(Globals.GetTex("Bark"), Tree.GetGroupFromName("Trunk"));

Please make sure to read over the Truevision 3D manual and documentation on TVMeshes, texture functions and more.

Published by James Cloud

I like to program and do basically anything that has to do with technology and computers.  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.