# Very fun Direct3D.Font problem

## Recommended Posts

This is the overload of Direct3D.Font.DrawText I am using:
public int DrawText(
Sprite sprite,
string text,
Point pos,
Color color
);
You are allowed to pass null for sprite, which means Direct3D will pick one for you. If I do this, DrawText works exactly how I would expect. However, I have my own sprite that I want to use. When I specify it (within sprite.Begin()/End()) all I get is rectangles of the specified color the size of each letter. EDIT: The function is not failing. What gives? [Edited by - Daniel Miller on June 29, 2005 2:27:45 PM]

##### Share on other sites
turnpast    1011
You must specify SpriteFlags.AlphaBlend when drawing fonts.

##### Share on other sites
Thanks! [smile] That got the text working, but now my other textures disappeared...

##### Share on other sites
That's probably because I am using Color.Transparent for the color. Is there a a way to specify a "neutral" color?

##### Share on other sites
turnpast    1011
The docs say that a color value of 16777215 (0xFFFFFF) using the form of draw that takes an int will preserve the texture's color and alpha data.

##### Share on other sites
Thanks, but that is the same as Color.Transparent. If I specify, for example, Color.Red, my sprite appears red. If I use Color.Transparent, it dissapears. Is this because my sprite doesn't have an alpha channel (it was made in Paint)?

By the way, it only dissapears if I use the SpriteFlags.AlphaBlend flag. Should I have two sets of Sprite.Begin/End?

##### Share on other sites
turnpast    1011
1. Using two begin/end blocks should work but may incur a minor performance penalty depending on the volume of rendering you are doing.

2. Try using 0xFFFFFFFF instead of 0xFFFFFF, put it in an unchecked block or the compiler will complain.

3. Make sure you are using a texture format that does not have an alpha channel or that you are filling it correctly. If I recall correctly you can also specify a mask color when you are loading a texture.

##### Share on other sites
I was using a png, but I did not specify any alpha, and I don't think that MSPaint can. I will try it with a BMP.

##### Share on other sites
It is still invisible when I'm using a BMP. I don't understand why, because the docs say this:

Quote:
 The Color.Transparent value maintains the original source color and alpha data.

##### Share on other sites
turnpast    1011
How are you loading your texture? Are you using TextureLoader.FromFile? If you use one of the longer forms you can specify the format and a colorKey for transparancy. Using this you will at least know what dx is doing internally with your texture. You may have to fool around to find a format your card supports, (most the cards I have used support R5G6B5 and X8R8G8B8 as non-alpha formats). Also make sure you specify 0 as the color key.

Did you mess around with any of the texture states before entering your sprite block? Usually sprite sets this all up correctly for you, but it may only adjust the states it is directly intrested in.

Also -- this is probably not the problem, but if you left the zbuffer on, you may want to turn it off. You may also want to use the SortDepthBackToFront sprite flag if you are drawing sprites with alpha.

##### Share on other sites
Syranide    375
Wait a minute, what is the actual problem, DrawText or your custom font?
As you said, it works when specifying NULL, are you sure you aren't doing something wrong with your font, invalid size, bad character placement och forgetting some data that DrawText requires (I would guess it needs some kind of CHAR->RECT mapping).

##### Share on other sites
GroZZleR    820
Color.White will preserve your texture's colours. Color.Transparent seems like it would make them all transparent, but that's just what my gut is telling me.

##### Share on other sites
Quote:
 Original post by GroZZleRColor.White will preserve your texture's colours. Color.Transparent seems like it would make them all transparent, but that's just what my gut is telling me.

Yes, Color.White did it. But I am not making that up, look here!

MSDN...

Look in the parameter section. Thanks a lot! [smile]

edit: I sent feedback on that topic to Microsoft.