Very fun Direct3D.Font problem

Started by
11 comments, last by Daniel Miller 18 years, 9 months ago
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]
Advertisement
You must specify SpriteFlags.AlphaBlend when drawing fonts.
Thanks! [smile] That got the text working, but now my other textures disappeared...
That's probably because I am using Color.Transparent for the color. Is there a a way to specify a "neutral" color?
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.
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?
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.
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.
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.
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.

This topic is closed to new replies.

Advertisement