PDA

View Full Version : DirectDraw.DrawText - Missing?



Gadget
10-01-2005, 06:29 PM
I am using DirectX 7 interfaces (from DX 8 headers), and I noticed that DrawText is missing? Is it supposed to be there? I thought it was a method of DX7 surfaces?

EDIT: Getting the DC and using TextOut is way too slow!

Crisp_N_Dry
10-01-2005, 08:15 PM
I didn't know there was a DrawText method. I coded the procedure below



procedure SpriteText(var Surface: IDirectDrawSurface4;Fontsheet: IDirectDrawSurface4;X,Y: Integer;Text: String);
var
C: Integer;
CharRect: TRect;
begin
For C:=1 To Length(Text) Do begin
CharRect:=Rect(-1+Ord(Text[C])*10,0,9+(-1+OrdC*10),20);
Surface.BltFast(X+(-1+C*10),Y,Fontsheet,CharRect,DDBltFast_SrcColorKey or DDBltFast_Wait);
end;
end;



This is assuming that the width of each letter is 10 pixels and the height is 20 pixels. Adjust as necessary. It seems fast enough.

Sly
10-01-2005, 09:46 PM
There was never a DrawText method in DirectDraw. You have two options:
:arrow: Get the DC and use the GDI TextOut. Yes, very slow.
:arrow: Draw your own bitmap font, similar to that described by Crisp_N_Dry. A lot faster, but more work for you initially.

Gadget
11-01-2005, 09:38 AM
There was never a DrawText method in DirectDraw. You have two options:
:arrow: Get the DC and use the GDI TextOut. Yes, very slow.
:arrow: Draw your own bitmap font, similar to that described by Crisp_N_Dry. A lot faster, but more work for you initially.

Cool, thanks for the replies guys =D

I only found out about DrawText on MSDN. It mentions it's a IDirectDrawSurface method, but they missed it out?

EDIT: The problem I have is that text is a major part of the game, as it's a MMORPG, and needs to support many languages including possibly japanese and chinese. So I think I need to stick with GDI for now. Maybe later I might experiment with dynamically populating the character surfaces by running through the entire character set. Whilst that's fine for english and latin characters, it's not for the 1,000s of japanese ones :P TrueType fonts are a bugger as well, different char sizes :P

TheLion
11-01-2005, 10:21 AM
It doesn't matter if the characters are of different size, there are many methods for dealing with that, the most common one is to mark the end of a character somehow either by using a single pixel in a certain colour marking the end of a character or by having a character index file showing the measurements of each character so you can easily calculate where the character you want is in the bitmap... however the even easier method is to use seperate bitmaps for each character! ;)

the good thing about bitmap characters is that they simply look better and (like sly already mentioned) they draw a lot faster than using the GDI functions (cause believe me your framerate will drop tremendously by using GDI).

When it comes to japanese languages... well if you know what the characters look like you can also draw them, all you need then are more bitmap files/characters and a larger index.

There are even freeware programs out there that convert true type fonts to a bitmap font for you, all you will have to do then is either write code so they can be read or use a paint program (maybe in conjunction with a tool you wrote yourself) to make them compatible with your own bitmap font type/storage... :)

However it's your choice what you use! ;) It's also easy done to change the TextOut stuff to your own bitmap font renderer later on so you it's never too late to change your mind! ;)

Sly
11-01-2005, 10:56 AM
I know the problems with dealing with foreign languages. I write console games a for a living and making sure the games work in eight different languages with the possibility of having to support Japanese (katakana and hirakana I think they're called) is a huge task.

http://www.users.on.net/~sly/images/bfauto3.jpg (http://www.users.on.net/~sly/images/bfauto3.jpg)
Click the image above for the full screenshot of my dogfight competition entry so far (I'm working on the menus at the moment). All the text in that screenshot is drawn using bitmap fonts created from Truetype fonts. I am using Direct3D, so I draw the text as a series of quads. This is how every 3D game out there does it.

Here is a tool that will create a bitmap font for you from a Truetype font. It's the one I used for the fonts in that screenshot.
http://www.angelcode.com/products/bmfont/