Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Textures on meshes

Textures on meshes

Textures on meshes


I want render a texture on a mesh. The texture is loaded from a file. The mesh is created by the primitive mesh methode (e.g. Mesh.Box)
I'd read, that this meshes don't have meshcoordinates. So I cloned the mesh to a mesh with texturecoordinates.
But the texture isn't drawn.
Can anyone help me please? A source example would be helpful, because all examples I found load the mesh from a file, where the textures are defined, too.
Here is the source-code which I use.


Appearance appearance=(Appearance)m_appearance;
ImageTexture appTexture=(ImageTexture)appearance.Texture;
if (appTexture!=null){
     Texture texture = TextureLoader.FromFile

Microsoft.DirectX.Direct3D.Mesh tempboxMesh=null;
Mesh boxMesh=tempboxMesh.Clone(tempboxMesh.Options.Value, tempboxMesh.VertexFormat | VertexFormats.Normal | VertexFormats.Texture0,directXDevice);



RE: Textures on meshes

I have never used anything beyond the very basics of D3D with C# (I'm an unmanaged C++ kind of guy), but I'll try to help.  You gave it texture coordinates, but you never specified the values of the coordinates.  You would have to specify which vertices of the box coorespond to what texture coordinate - there is no way that D3D could know what corners get what texture coords.  I would recommend just creating your own index and vertex buffer to render the box yourself rather than using the Mesh class.  It wouldn't be too much work at all considering this is just a box.

By the way, PLEASE tell me that you just pasted code from different methods and you aren't creating and releasing a mesh and texture every frame.  That's the best way to get fewer frames per second than Doom 3 at 1600x1200 on a TNT2.

RE: Textures on meshes


the box is only an example. The program should render other primitives e.g. a sphere or cylinder, too. So to build a index and vertex buffer is right complex.
I don't know, how to get the vertices of the mesh. Are there any methods in C++? Perhaps I would find them in C#, too :)

cu Kostarsus

P.S. I'd pasted the code from different methods.

RE: Textures on meshes

Mesh has a VertexBuffer property which will allow you to get to the VB.  Just lock it and set the texture coordinates.  In C++ there is a class D3DXMesh that is similar to Mesh, but I have never used it for anything other than loading them from files.  I always just create the VBs and IBs myself when doing otherwise.  It helps keep my math skills sharp :).

RE: Textures on meshes

I' changed the code to this:


bool urlFound=false;
int i=0;
Mesh boxMesh=Mesh.Box(directXDevice,this.m_size.X,m_size.Y,m_size.Z);    
Appearance objectAppearance=(Appearance)m_appearance;
if (objectAppearance.Texture!=null)
    Texture texture=null;
    ImageTexture imageTexture=(ImageTexture)objectAppearance.Texture;
    Mesh clonedMesh=boxMesh.Clone(boxMesh.Options.Value,boxMesh.VertexFormat | VertexFormats.Normal | VertexFormats.Texture0, directXDevice);
    while (i<imageTexture.Url.Count && urlFound==false)
        texture = TextureLoader.FromFile(directXDevice,imageTexture.Url.GetElementAt(i));        }
    for (i=0;i<clonedMesh.NumberVertices;i++)        
    {                    directXDevice.SetTexture(0,texture);            clonedMesh.DrawSubset(i);

But the texture isn't diplayed. Where is now the error?
Can anyone send an example, please. no matter if it is in managed or unmanaged code.
I'll try to translate unmanaged code to managed code than.

cu Kostarsus

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close