My problems with the sphere continue.
Well, last time the code was rather incomplete. Here's the complete thing.
I have added Normals for the calculation of the texture cordinates, as
suggested. I am using a 256 x 256 .bmp file as my input file in
CreateTextureFromFile (.....), but all I get in the end is a skeleton of
a sphere, no texture, nothing.
Here's the InitGeometry() function
Code:
void CMainframe::InitGeometry()
{
if (FAILED (D3DXCreateTextureFromFile (g_pd3dDevice,"BANANA.BMP",&g_pTex)))
throw "Could not load Texture, Fatal failure";
if (FAILED (g_pd3dDevice->CreateVertexBuffer (2*15*31*sizeof (CUSTOMVERTEX),
0,D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED,
&g_pVB)))
throw "Failed to CreateVertexBuffer()";
CUSTOMVERTEX* p_Vertices;
if (FAILED (g_pVB->Lock (0,0,(BYTE**)&p_Vertices,0)))
throw "Failed to Lock()";
float fDeltaRingAngle = D3DX_PI / 15.0f;
float fDeltaSegAngle = 2.0f * D3DX_PI / 30.0f;
for (DWORD ring=0; ring<=15;ring++)
{
float r = 3 * sinf (ring * fDeltaRingAngle );
float y = 3.05 * cosf (ring * fDeltaRingAngle);
float r1 = sinf ((ring + 1) * fDeltaRingAngle);
float y1 = cosf ((ring+1) * fDeltaRingAngle);
for (DWORD seg=0;seg <= 30 ; seg++)
{
float z = r * cosf (seg * fDeltaSegAngle);
float x = r * sinf (seg * fDeltaSegAngle);
float z1 = r1 * cosf (seg * fDeltaSegAngle);
float x1 = r1 * sinf (seg * fDeltaSegAngle);
(*p_Vertices).position = D3DXVECTOR3 (x,y,z);
(*p_Vertices).color = D3DCOLOR_ARGB (100,100,1,1);
(*p_Vertices).normal=D3DXVECTOR3 (x,y,z);
//Calculate the texture Co-ordinates
(*p_Vertices).tu = asinf(x)/D3DX_PI + 0.5f;
(*p_Vertices).tv = asinf(y)/D3DX_PI + 0.5f;
p_Vertices++;
}
}
g_pVB -> Unlock();
}
Ok, that was long, and heres the Render()
Code:
void CMainframe::Render()
{
// Clear the backbuffer and the zbuffer
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
D3DCOLOR_RGBA (0,0,255,0), 1.0f, 0 );
// Begin the scene
g_pd3dDevice->BeginScene();
// Setup the world, view, and projection matrices
SetUpMatrices();
// Setup the Textures
g_pd3dDevice->SetTexture( 0, g_pTex );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
// Render the vertex buffer contents
g_pd3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 500 );
// End the scene
g_pd3dDevice->EndScene();
// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
So whats wrong really ? I am using the right (!!!) method to map them,
am I not ?
And yes, another interesting thing, although I am running this program on
a P4 2.4GHz machine, the sphere seems to rotate *painfully* slow. Parts
of it even seem to be disappearing at times. I find that rather funny
because I have played Unreal2 on this system, and that was running fine.
My Sphere couldn't possibly be demanding more resources or processing
than Unreal2. So why is this so slow ???
Thanks...
CJ