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
- CSharp .Net Tutorial: Move a Borderless FormLearn how to give the user the ability to move a borderless form in your CSharp .Net Applications.
- CSharp .Net Tutorial: Read / Write RegistryLearn how to manipulate the system registry using CSharp .Net.
- CSharp .Net Tutorial: Sending EmailLearn how to send emails using CSharp .Net.
- CSharp .Net Tutorial: PingingLearn how to ping an IP Address using CSharp .Net in this easy to understand tutorial.
- CSharp .Net Tutorial: How to Skin Your FormsA free way to skin your Windows Form application in CSharp .Net.
- Csharp.Net Tutorial: Drawing Sprites with Truevision 3D
- Csharp.net Tutorial: Drawing Particles with Truevision 3D
- CSharp .Net Tutorial: Picture Box Load Icon
- Csharp .Net Tutorial: Catching Errors
- CSharp .Net Tutorial: Directory Manipulation
- CSharp .Net Tutorial: Reading and Writing INI
- Csharp.Net Tutorial: Playing Audio with DirectX



