Jump to content
  • Advertisement
Sign in to follow this  
byrdJR

Manually texturing a sphere

This topic is 5165 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

Hi. I'm trying to texture a mesh created by the D3DX (DX9)createSphere function and here's my FVF:
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
and here's how I cloned my mesh:
	 LPDIRECT3DVERTEXBUFFER9 pTempVertexBuffer;

    pTempMesh->CloneMeshFVF( 0, D3DFVF_CUSTOMVERTEX, g_pd3dDevice, &g_pMesh );

    if( SUCCEEDED( g_pMesh->GetVertexBuffer( &pTempVertexBuffer ) ) )
    {
        int nNumVerts = g_pMesh->GetNumVertices();
        CUSTOMVERTEX *pVertices = NULL;

        pTempVertexBuffer->Lock( 0, 0, (void**)&pVertices, 0 );
        {
            for( int i = 0; i < nNumVerts; i++ )
			{
				
                                pVertices[i+0].tu  = ((FLOAT)i)/(nNumVerts-1);
				pVertices[i+0].tv  = 0.0f;
				pVertices[i+1].tu  = ((FLOAT)i)/(nNumVerts-1);
				pVertices[i+1].tv  = 1.0f;
				
				
			}
			pTempVertexBuffer->Unlock();

			pTempVertexBuffer->Release();
		}
	}
Now all I get as output is a wireframe sphere. I think my problem is my algorithm for maping the tex coords to the sphere is all wrong and I would like to know how I should manually calculate texturing a sphere. I have a basic understanding of how to texture a mesh and I know that u and v are between 0 and 1 and I can texture simpler polys, but I don't have a clear idea of how to manually texture a sphere. I mean I think I have to calulate the four points that make a square on the sphere for each vert on the sphere, but I don't know how to put that into an array. I really need a clear explaination of how to manually texture simple meshes like spheres or cubes and an explaination of the logic behind the process. I have tried using a 3d program and I loaded x files before, but I spent so much time trying to learn those programs that I'm not completing any of my projects, so I'd rather get the basics of D3D down before I spend any more time on a 3d program. Anyway, if you or anyone here can point me in the right direction I would greatly appreciate it.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
http://www.mvps.org/directx/articles/spheremap.htm

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!