Hi,
I am trying without success to draw TTF text onto a DirectX 9 texture.
I am using the DirectX 9 "DrawTextA()" function.
Please look at the below code and tell me what is wrong with it.
(focus on the source at the bottom)
Thanks in advance.
JeZ+Lee
bool Visuals::LoadSpritesIntoMemoryAndInitialize(void)
{
HRESULT result;
char filePath[256];
strcpy_s(filePath, "~\0");
for (int index = 0; index < NumberOfSprites; index++)
{
switch(index)
{
case 0:
strcpy_s(filePath, "Data/Visuals/Screen-Fade-Black-Box.png");
break;
case 5:
strcpy_s(filePath, "Data/Visuals/16BitSoft-Logo.png");
break;
case 6:
strcpy_s(filePath, "Data/Visuals/Title-BG.png");
break;
case 7:
strcpy_s(filePath, "Data/Visuals/TC5-Logo.png");
break;
case 1001:
strcpy_s(filePath, "Data/Visuals/Button.png");
break;
case 1002:
strcpy_s(filePath, "Data/Visuals/Button.png");
break;
case 1003:
strcpy_s(filePath, "Data/Visuals/Button.png");
break;
case 1004:
strcpy_s(filePath, "Data/Visuals/Button.png");
break;
case 1005:
strcpy_s(filePath, "Data/Visuals/Button.png");
break;
case 1006:
strcpy_s(filePath, "Data/Visuals/Button.png");
break;
case 1007:
strcpy_s(filePath, "Data/Visuals/Button.png");
break;
default:
strcpy_s(filePath, "~");
break;
}
strcat_s(filePath, "\0");
if (filePath[0] != '~')
{
D3DXIMAGE_INFO imageInfo;
result = D3DXGetImageInfoFromFileA(filePath, &imageInfo);
// if FAILED (hResult){
// return false;
// }
D3DXCreateTextureFromFileExA(DXDevice, filePath, imageInfo.Width, imageInfo.Height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &Sprites[index].Texture);
result = D3DXCreateSprite(DXDevice, &Sprites[index].DXSprite);
Sprites[index].ScreenX = 400.0f;
Sprites[index].ScreenY = 240.0f;
Sprites[index].ScaleX = 1.0f;
Sprites[index].ScaleY = 1.0f;
Sprites[index].RotationDegree = 0.0f;
Sprites[index].RedHue = 255;
Sprites[index].GreenHue = 255;
Sprites[index].BlueHue = 255;
Sprites[index].Transparency = 255;
Sprites[index].Smooth = true;
Sprites[index].FlipX = false;
Sprites[index].FlipY = false;
Sprites[index].OriginalWidth = imageInfo.Width;
Sprites[index].OriginalHeight = imageInfo.Height;
D3DSURFACE_DESC textureInfo;
Sprites[index].Texture->GetLevelDesc(0, &textureInfo);
Sprites[index].TextureWidth = textureInfo.Width;
Sprites[index].TextureHeight = textureInfo.Height;
Sprites[index].AnimationTimer = -1.0f;
if (index > 1000 && index < 1008)
{
LPDIRECT3DSURFACE9 pRenderSurface = NULL;
Sprites[index].Texture->GetSurfaceLevel(0, &pRenderSurface);
DXDevice->SetRenderTarget(0, pRenderSurface);
DXDevice->BeginScene();
DXDevice->SetTexture(0, Sprites[index].Texture);
RECT rect, textSize;
int posX, posY;
Font[0]->DrawTextA( NULL, "START!", -1, &textSize, DT_CALCRECT, D3DCOLOR_RGBA(255, 255, 255, 255) );
posX = (Sprites[index].TextureWidth / 2) - (textSize.right / 2) - 3;
posY = Sprites[index].TextureHeight / 2;
for (int screenY = -2; screenY < 3; screenY++)
{
for (int screenX = -2; screenX < 3; screenX++)
{
SetRect( &rect, posX+screenX, posY+screenY, 0, 0 );
if (screenY != 0 && screenX != 0)
Font[0]->DrawTextA(NULL, "START!", -1, &rect, DT_NOCLIP, D3DCOLOR_RGBA(100, 100, 100, 255) );
}
}
SetRect( &rect, posX, posY, 0, 0 );
Font[0]->DrawTextA( NULL, "START!", -1, &rect, DT_NOCLIP, D3DCOLOR_RGBA(255, 255, 255, 255) );
DXDevice->EndScene();
}
}
}
return(true);
}