bool CMesh::CreateSphere(float radius, int LOD, char* texturename)
{
LPD3DXMESH pMeshTemp;
D3DXCreateSphere(pD3DDevice, radius, LOD, LOD, &pMeshTemp, &pAdjacency);
//Generate textures, materials, and normals
NumMaterials = 1;
//Create two arrays. One to hold the materials and only to hold the textures
pMeshMaterials = new D3DMATERIAL9[NumMaterials];
pMeshTextures = new LPDIRECT3DTEXTURE9[NumMaterials];
for(DWORD i = 0; i < NumMaterials; i++)
{
//Create basic material
pMeshMaterials.Diffuse.r = 1.0f;
pMeshMaterials.Diffuse.g = 1.0f;
pMeshMaterials.Diffuse.b = 1.0f;
pMeshMaterials.Diffuse.a = 0.0f;
pMeshMaterials.Ambient.r = 0.0f;
pMeshMaterials.Ambient.g = 0.0f;
pMeshMaterials.Ambient.b = 0.0f;
pMeshMaterials.Ambient.a = 0.0f;
pMeshMaterials.Specular.r = 0.0f;
pMeshMaterials.Specular.g = 0.0f;
pMeshMaterials.Specular.b = 0.0f;
pMeshMaterials.Specular.a = 0.0f;
pMeshMaterials.Emissive.r = 0.0f;
pMeshMaterials.Emissive.g = 0.0f;
pMeshMaterials.Emissive.b = 0.0f;
pMeshMaterials.Emissive.a = 0.0f;
// Create the texture
if(FAILED(D3DXCreateTextureFromFile(pD3DDevice, texturename, &pMeshTextures)))
{
pMeshTextures = NULL;
}
}
//Make sure that the normals are setup for our mesh
pMeshTemp->CloneMeshFVF(D3DXMESH_MANAGED, MESH_D3DFVF_CUSTOMVERTEX, pD3DDevice, &pMesh);
D3DXComputeNormals(pMesh, NULL);
return true;
}
bool CMesh::Render()
{
for(int i = 0; i < NumMaterials; i++)
{
pD3DDevice->SetMaterial(&pMeshMaterials);
pD3DDevice->SetTexture(0, pMeshTextures);
if(FAILED(pMesh->DrawSubset(i)))
{
Log->LogError("Failed to draw mesh");
return false;
}
}
return true;
}
D3DXCreateSphere Help
I'm trying to create a sphere for my program from D3DXCreateSphere. It creates the sphere and renders in correctly. However, I would like to texture the sphere. The way I am currently doing it does not work at all (my guess is the texture coordinates are all messed up because it renders as a solid color depending on the textures' background). How should I go about texturing this sphere? (NOTE: The textures do load in correctly it is the texturing the sphere that is messing up)
Here is my current code:
The problem is that meshes created with that function don't have texture coordinates, so you have to clone the FVF with the function... mesh.cloneFVF or something of the sort.
I honestly don't know how to do it, but that's your problem. I'll search the forums to see if I can find the answer...
EDIT: Checked my SDK (I only have the VB6 one... sorry!) but the prototype looks like this:
Basically, you have to clone the mesh you created a new one, but be sure to include D3DFVF_TEX1 which will give it texture coordinates. And uh, don't forget all your other vertex formats (just use the FVF you're using for everything else).
I hope that works (to any degree)!
I honestly don't know how to do it, but that's your problem. I'll search the forums to see if I can find the answer...
EDIT: Checked my SDK (I only have the VB6 one... sorry!) but the prototype looks like this:
object.CloneMeshFVF( _ Options As Long, _ FVF As Long, _ Device As Direct3DDevice8) As D3DXMesh
Basically, you have to clone the mesh you created a new one, but be sure to include D3DFVF_TEX1 which will give it texture coordinates. And uh, don't forget all your other vertex formats (just use the FVF you're using for everything else).
I hope that works (to any degree)!
No, its still not working, when I cloned the mesh to get the normals I included D3DFVF_TEX1 already... Any other ideas?
Well, in the worst case scenario you can always just make a sphere in an X file and import that. It's probably not the best way to do it and I know how you probably feel. I was trying to do the same thing you are but never had much success and it wasn't vital to what I needed to do (just for debugging anyway) so I just decided to forgo it. I'm interested to see useful replies to this however.
Quote:Original post by Squirell
No, its still not working, when I cloned the mesh to get the normals I included D3DFVF_TEX1 already... Any other ideas?
Cloning won't magically compute your texture coordinates [smile], you have to do it yourself. Check Robert Dunlop's X-Zone for a tutorial on spherical mapping.
yeah check out Robert Dunlops site, I got a lot of help from his site. but other than that if you use the fvf of your cloned mesh and use a buffer pointer couldn't you lock it and just change the tex or tu-tv values?
Quote:Original post by Anonymous Poster
yeah check out Robert Dunlops site, I got a lot of help from his site. but other than that if you use the fvf of your cloned mesh and use a buffer pointer couldn't you lock it and just change the tex or tu-tv values?
That's exactly what he should do [smile]. He just needs to make sure he calculates his tu/tv offset into the vertex structure correctly based on the FVF.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement