PDA

View Full Version : ID3DXFont Problem?



Arius Myst
26-09-2003, 03:38 PM
Ok, I had fonts working before. But now it doesn't seem to want to work.

Heres my code:


unit AerInit;

interface

uses Direct3d9, D3DX9, windows, sysutils, Dialogs, Graphics;

Function Start(Windowed: Boolean; Width, Height, Depth: Integer; Diag: Boolean; Name: HWND): HRESULT; // Initialises Aeris And A Basic Font(DiagFnt).
Procedure TextIt(X, Y: Integer; Text: String); // Draws A String Of Text To The Screen At The Given Co-Ord's.
Procedure Err(Err: String); // Displays An Error Message Then Terminates The Engine.
Procedure Flip(); // Brings The BackBuffer To The Front And Renders The Scene.
Procedure Clean(); // Cleans Up.

Var
GfxDevice : IDirect3DDevice9 = nil; // The Device. Uses The Systems Defauly Display Adapter.
D3DObj : IDirect3d9 = nil; // A Direct3d Object. Will Be Used To Initialise The Device.
Canvas : Hwnd ; // The Drawing Canvas. Defined In The "Start" Function.
Diag : Boolean ; // Should The Engine Be Running In Diagnostics Mode?.
DiagFont : ID3DXFont ; // Direct3D Font Object.
DiagFontObj : TFont ; // Delphi Font Object - Used For Direct3D Font Objects Properties.
TxtRect: TRect;

implementation

//-----------------------------------------------
// NAME: Start
// DESC: Initialises The Device And Default Font.
//-----------------------------------------------



Function Start(Windowed: Boolean; Width, Height, Depth: Integer; Diag: Boolean; Name: HWND): HRESULT;
Var
Present: TD3DPresentParameters;
Begin
FillChar(Present, SizeOf(Present), 0);


//-----------------
// Type Of Display

If Windowed = True Then
Begin
Present.Windowed := True;
End;

If Windowed = False Then
Begin
Present.Windowed := False;
End;

//---------------------
// Main Initialisation

D3DObj := Direct3dCreate9( D3D_SDK_VERSION );
If (D3DObj = Nil) Then Err('Engine Failure: Direct3D Object Failed During Creation.');

Present.SwapEffect := D3DSwapEffect_Discard;
Present.BackBufferFormat := D3DFMT_UNKNOWN;
Present.BackBufferWidth := Width;
Present.BackBufferHeight := Height;

Result := D3DObj.CreateDevice( D3DAdapter_Default, D3DDevType_HAL, Name, D3DCreate_Software_VertexProcessing, @Present, GfxDevice);

Canvas := Name;

DiagFontObj := TFont.Create;
With DiagFontObj Do
Begin
Name := 'Tahoma';
Size := 8;
End;

D3DXCreateFont(GfxDevice, DiagFontObj.Handle, DiagFont);


If Failed( Result ) then
Begin
Result := E_FAIL;
Err('Device Failed To Initialise.');
End;

End;

//-----------------------------------------------
// NAME: Err
// DESC: Displays Errors.
//-----------------------------------------------

Procedure Err(Err: String);
Begin
ShowMessage(Err);
End;

//-----------------------------------------------
// NAME: TextIt
// DESC: Prints Text To The Screen.
//-----------------------------------------------

Procedure TextIt(X, Y: Integer; Text: String);
//Var

Begin
TxtRect.Left := X;
TxtRect.Top := Y;
TxtRect.Right := Length(Text)+4;
TxtRect.Bottom := 20;
DiagFont._Begin;
DiagFont.DrawTextA(Text, -1, TxtRect, DT_LEFT, D3DColor_XRGB( 147, 203, 255 ));
DiagFont._End;
End;

//-----------------------------------------------
// NAME: Flip
// DESC: Flips The Back To The Front.
//-----------------------------------------------

Procedure Flip();
Begin
GfxDevice.Clear(0, nil, D3DClear_Target, D3DColor_XRGB( 46, 66, 90 ), 1.0, 0);
GfxDevice.BeginScene;
//Diag();
DiagFont._Begin;
DiagFont.DrawTextA('lalalalalalala', -1, TxtRect, DT_LEFT, D3DColor_XRGB( 147, 203, 255 ));
DiagFont._End;
GfxDevice.EndScene;
GfxDevice.Present(Nil, Nil, 0, Nil);
End;

When i add that unit to my uses clause everything works fine. Except it doesn't display any text. I've even added it in the flip procedure to make sure its not because its not encased in the GfxDevice.Begin and End statements. Still no luck, can anybody shed some light on this?



Edit:

I figured out why. The code above is from the source i was working on. An older version of the source was being used for the app trying to use the "TextIt" procedure. To cut a long story short i'm the dumbass who forgot to update the copy of the source in the lib folder ;)