Sign in to follow this  
Thr3ad

Texturing a mesh

Recommended Posts

Thr3ad    122
Is there a simple way to load a texture from a file and then attach it to a mesh? I want to create a sphere and then add a texture to it so i am setting up like this:
LPD3DXMESH  EarthMesh = NULL;
D3DXCreateSphere( pD3DDevice, 1.0f, 20, 20, &EarthMesh, NULL);
I am not sure where to go from here, do i need to make a custom vertex buffer or not? Thanks for looking.

Share this post


Link to post
Share on other sites
jollyjeffers    1570
There isn't an easy way for your example...

You can use D3DXCreateTextureFromFile() to load up a texture - thats easy enough.

What's difficult is the geometry returned from D3DXCreateSphere() (and the similar functions) DON'T include texture coordinates.

You'll have to go into the vertex data and develop some sort of algorithm (many exist if you want to try it) to define texture coordinates. It can get a little involved [wink]

The alternative is to use a 3D modelling program and create the mesh (with texture) and export it to a .X file.

hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this