Jump to content
  • Advertisement
Sign in to follow this  
Headkaze

Applying a texture to a Mesh.Sphere

This topic is 4079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying to draw a sphere with a texture on it using Mesh.Sphere but I can't seem to get the texture to show. I checked out the Mesh.VertexFormat and it is "Texture0, PositionNormal" so the vertex data does not expect a texture. Now to my question, how can I apply a texture to this sphere?

Share this post


Link to post
Share on other sites
Advertisement
I havent done it this way myself, but I think you have to lock it and change the texture coordinates yourself; they are not auto-generated. There is a popular page somewhere that shows you how to generate these coordinates if you don't remember your 3D math; somebody here might remember the URL.

I preferred to generate my own sphere instead of doing this, but you still need the formulas to calculate the coordinates...

Share this post


Link to post
Share on other sites
The D3DX-generated shapes don't have texture coordinates, so you're on your own for generating these. Remember that you'll have to clone the generated mesh to one that has space for the TC information.

Mapping a 2D texture to a sphere isn't as simple as you might think - try wrapping a piece of paper around a tennis ball for example; you'll find you have to scrunch bits up or cut parts out to get a nice tight fit...

A quick search will yield numerous algorithms.

hth
Jack

Share this post


Link to post
Share on other sites
Thanks guys.

I found this great article on the web by the famous ZMan and he clones the Sphere mesh then or's in the texture vertext format.

private static D3D.Mesh cloneAddTexture(D3D.Mesh mesh)
{
return mesh.Clone(mesh.Options.Value, mesh.VertexFormat | D3D.VertexFormats.Texture1, mesh.Device);
}


Then the texture coordinates are calculated using spherical texture mapping.

Very interesting article.

http://blogs.msdn.com/coding4fun/archive/2006/10/31/912562.aspx

Now I have my sphere with a texture which looks fine but I want to place my camera inside it and use it like a skybox. But it's completely dark when I make the sphere large enough to be in the centre of it. I've tried putting a light right in the centre but it's still dark. I've tried turning on cullmode still nothing. I thought culling made textures show on both sides of polys. I remember reading somewhere about "reversing normals" to make the texture show on the inside instead of the outside. Perhaps I'm not putting the light in the right place.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!