# D3DXCreate... No Tex Coords

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

## Recommended Posts

Hi, I'm currently experimenting with some new shaders and would like to use the D3DXCreateBox, Sphere, Teapot etc functions for quick use. But they arn't provided with texture coords. I know how to change them into the my own Pos,Norm,Tex Declaration but how to I generate texture coordinates for them? I can make do with defining tex coords for the box, but the others are kinda difficult.

##### Share on other sites
Don't know if this is the best/easiest thing to do, but take a look here.

##### Share on other sites
Also cylinder should be easy, but you're right, for sphere and even teapot, it is a problem ;)
There are more ways how to map textures (that means how to generate texcoords) on such complicated surfaces. Man understands this problem better after messing around with some 3D modelling SW (3ds max, Maya etc.).
The link Gage64 gave you shows one method for a sphere, which seems to be the simplest one. Which of course brings some drawbacks, for instance a nasty looking "North and South Poles".

##### Share on other sites
Thanks fo the link, very nice start off.

This is what I've got so far:
LPD3DXMESH d3d::CreateMappedSphere(float radius, unsigned int slices, unsigned int stacks, IDirect3DDevice9* device){	LPD3DXMESH outMesh = 0;	D3DXCreateSphere(device, radius, slices, stacks, &outMesh, 0);	D3DVERTEXELEMENT9 elements[MAXD3DDECLLENGTH];	unsigned int numElements = 0;	VertPosNormTex::Decl->GetDeclaration(elements, &numElements);	LPD3DXMESH temp = 0;	outMesh->CloneMesh(D3DXMESH_SYSTEMMEM, elements, device, &temp);	SAFE_RELEASE(outMesh);	VertPosNormTex* verts = 0;	temp->LockVertexBuffer(0, (void**)&verts);	for (DWORD i = 0; i < temp->GetNumVertices(); ++i)	{		float u = asinf(verts.n.x) / PI + 0.5f;		float v = asinf(verts.n.y) / PI + 0.5f;		verts.t0.x = u;		verts.t0.y = v;	}	temp->UnlockVertexBuffer();	temp->CloneMesh(D3DXMESH_MANAGED | D3DXMESH_WRITEONLY, elements, device, &outMesh);	SAFE_RELEASE(temp);	return outMesh;}

which shows this: http://img167.imageshack.us/img167/6832/sphericaltexkr1.jpg

I've also found another version in a book (Intro to Direct3D game programming, Frank D. Luna)
for (DWORD i = 0; i < temp->GetNumVertices(); ++i){	D3DXVECTOR3 p = verts.p;	float a = atan2f( p.z, p.x );	float b = acosf( p.y / sqrtf(p.x*p.x + p.y*p.y + p.z*p.z) );	float u = a / (2.0f*PI)	;	float v = b / PI;	verts.t0.x = u;	verts.t0.y = v;}

which shows this: http://img167.imageshack.us/img167/1817/sphericaltex1ng8.jpg

fortunately that squashed part only happens on that side. Does anyone have any more resources, particular for the teapot