I am trying to add a tiled texture to the floor. The texture does not show up, instead all the vertices are showing, and the ball now has a floor that follows it's bounce. Any help would be appreciated.
pGrid->CreateDirectXMesh(pd3dDevice);
D3DXCreateSphere(pd3dDevice, 2, 20, 20, &pBallMesh, NULL);
MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
createCamera(0.1f, 1000.0f);
moveCamera(camPos);
pointCamera(camLook);
float speed, maxSpeed = 0.5;
long volume;
BallVel.y -= .01f;
if (Abs(D3DXVec3Length(&BallVel)) > maxSpeed) {
D3DXVec3Normalize(&BallVel, &BallVel);
D3DXVec3Scale(&BallVel, &BallVel, maxSpeed);
}
BallPos = BallPos + BallVel;
pGrid->GetGridPoint(&gridPt, BallPos.x, BallPos.z);
if (BallPos.y < gridPt.y) {
speed = D3DXVec3Length(&BallVel);
volume = long(0.25 * DSBVOLUME_MIN * (1 - (speed/maxSpeed)));
if (speed < maxSpeed * 0.1f) {
volume = DSBVOLUME_MIN;
}
hr = DSBuffer->SetVolume(volume);
if( FAILED( hr ) )
DXTRACE_ERR( TEXT("Volume error "), hr );
playSound(DSBuffer);
BallVel.y *= -.8f;
BallPos.y = gridPt.y + .01f;
}
D3DXMatrixTranslation(&translate, BallPos.x, BallPos.y, BallPos.z);
D3DXMatrixIdentity(&id);
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(5, 5, 5), 1.0, 0 );
pd3dDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(5, 5, 5), 1.0, 0 );
hr = D3DXCreateTextureFromFile( pd3dDevice, "patchy.jpg", &g_pTexture);
if FAILED(hr)
return false;
pd3dDevice->BeginScene();
pd3dDevice->SetTransform(D3DTS_WORLD, &id);
pGrid->DrawDirectXMesh(pd3dDevice);
pd3dDevice->SetTransform(D3DTS_WORLD, &translate);
pBallMesh->DrawSubset(0);
pd3dDevice->SetTexture(0, g_pTexture);
pGrid->DrawDirectXMesh(pd3dDevice);
pd3dDevice->EndScene();
pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
}
shutdownDirect3D();
if (DSBuffer)
{
DSBuffer->Release();
DSBuffer = NULL;
}
shutdownDirectSound();
return (int) msg.wParam;
}