Solved

sphere mesh texture map using MDX

Posted on 2006-07-09
8
2,081 Views
Last Modified: 2013-12-08
hello,

how can i wrap a given texture to my sphere mesh in direct x? i tried
using the code in the 'Applying Textures part 3 (ZMan)' article (
http://msdn.microsoft.com/coding4fun/zman/zmantextures3/default.aspx )
but it didnt work.

can you please show me some code and make it as brief and simple as
possible?

when i use the following code:

device.SetTexture(0, TextureLoader.FromFile(device,
System.Windows.Forms.Application.StartupPath + @"\woodcrate.bmp" ));

it makes the sphere black in color. i dont see the texture clearly on
the mesh. i just see a black sphere. do i need to set texture
coordinates?

thanks for your time,

Zahid
0
Comment
Question by:zahidayar
  • 5
  • 2
8 Comments
 
LVL 4

Expert Comment

by:joachimc
ID: 17081305
I am guessing you haven't set any lights pointing at the sphere.

You could try making the texture self iluminating to test if that is the problem. It's one of the material settings I just can't remeber at the moment. Could be the emissive property.

But of course you need to set the ambient lighting and some kind of directional light to get it right.
0
 
LVL 3

Accepted Solution

by:
OutsideTheBox earned 500 total points
ID: 17108390
Zahid,

Could you please post your code, there could be a number of things that could cause this problem. It would help us to eliminate possibilities.

Are you sure you have woodcrate.bmp in the correct folder?

Most of the time you create a mesh with textures in a program like 3ds max or maya and these programs set texture coords and you do not have to set them manually because they import with the mesh. It doesn't look like that is your case but I would think in your case they just defaulted to 0,0 at vertex #1 of your sphere and you would have seen 'something' anyways. So I don't think that not setting them is your problem.

You said that you can't see the texture clearly. Can you see it at all? Is it there but somehow incorrect? or is the sphere simply just black with the texture missing?

I have found when following tutorials, that when they do not work, I've made a small, simple mistake in the coding somewhere that just takes a while to find, then I thump my forhead and wonder why I missed it. It rarely is the tutorial.

Steve
0
 

Author Comment

by:zahidayar
ID: 17111107
thanks for the replies....
lighting is set up...the sphere mesh just looks completely black....i didnt notice anything of the texture...i also asked this question on another forum (gamedev.net) and they suggested that i should setup the VertexFormat (and the texture coordinates) of the mesh properly...i will work on that soon hopefully...im working on other things right now...thanks again for the replies...

Zahid
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:zahidayar
ID: 17111110
by the way, i meant black with light shining off of it.. :)
0
 

Author Comment

by:zahidayar
ID: 17204470
hello,

this is my code:

            protected void SetupMaterial()
            {
                  this.iconMaterial = new Material();      
                  this.iconMaterial.Diffuse = Color.Blue;
                  this.iconMaterial.Specular = Color.LightGray;
                  this.iconMaterial.SpecularSharpness = 15.0F;
                  this.iconDrawingDevice.Material = this.iconMaterial;
                  this.iconDrawingDevice.RenderState.SpecularEnable = true;
                   this.iconDrawingDevice.SamplerState[0].AddressU = TextureAddress.Wrap;
                          this.iconDrawingDevice.SamplerState[0].AddressV = TextureAddress.Wrap;
           
if ( (addNelementIconMesh.VertexFormat & VertexFormats.Texture1) == 0 )
{
    // create a cloned mesh with texture coordinates attached to it
    Mesh tempMesh = addNelementIconMesh.Clone ( this.addNelementIconMesh.Options.Value , this.addNelementIconMesh.VertexFormat | VertexFormats.Texture1 , this.iconDrawingDevice );
    // get rid of the old mesh
    this.addNelementIconMesh.Dispose();
    // assign the new one
    this.addNelementIconMesh = tempMesh;
    // calculate them
   // CalculateSphereTextureCoordinates();

}

            this.iconDrawingDevice.SetTexture(0, TextureLoader.FromFile(this.iconDrawingDevice, System.Windows.Forms.Application.StartupPath + @"\woodcrate.bmp" ));
            }

as u can see the CalculateSphereTextureCoordinates() method is commented... i got some parts of the code from a member at gamedev.net....i would be happy if someone would provide a possible implementation of the CalculateSphereTextureCoordinates() method...

thanks for your time,

Zahid
0
 

Author Comment

by:zahidayar
ID: 17204473
yeah...woodcrate.bmp is in the correct folder...they are both in the same folder
0
 

Author Comment

by:zahidayar
ID: 17302905
hello,

yeah Steve, i set the texture coordinates and the texture mapping worked. :)

i used the following code:

            private void CalculateTextureCoordinatesForThisSphereMesh ( Mesh sphereMesh )
            {
                  using ( VertexBuffer vb = sphereMesh.VertexBuffer )
                      {
                          CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])vb.Lock(0, typeof(CustomVertex.PositionNormalTextured), LockFlags.None, sphereMesh.NumberVertices);                          
                             try
                              {
                                  for (int i = 0; i < verts.Length; i++)
                                  {
                                            verts[i].Tu =  Convert.ToSingle ( Math.Asin( verts[i].Nx ) / Math.PI + 0.5 );
                                            verts[i].Tv = -1 * Convert.ToSingle ( Math.Asin( verts[i].Ny ) / Math.PI + 0.5 );                  
                                  }
                              }
                              finally
                              {
                                  vb.Unlock();
                              }
                    }
            }

thanks for the help everyone..

Zahid
0
 
LVL 3

Expert Comment

by:OutsideTheBox
ID: 17317811
Glad you figured it out.

Thanks,
Steve
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java3D Add Line to existing scene 1 208
Java Chess - Any practical complete GIF zips for a chess app? 4 89
PDF: Display my cards game? 8 124
Fibonacci challenge 11 132
What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question