DrawText(HDC) overwrites alpha values of my texture

Started by
5 comments, last by HaywireGuy 20 years, 6 months ago
So I''ve heard that doin'' text thing in Direct3D can be very slow. OK, then I came up with this idea to do text in Direct3D in a hope to get text without killin'' my framerate (it''s not an original idea). 1. Create/load my 32bits ARGB texture. 2. Use Win32 and HDC stuff to DrawText on the bitmap. 3. Use this texture for text display. OK, I tried this, and later bump into one problem. DrawText function modifies the alpha values of the area it has drawn to. So the text region will have alpha value of 0, and became totally transparent (you can see through the text if it''s on a bitmap image). So how should I overcome this problem? Is there ways to prevent DrawText() from overwritin'' my alpha values? Now I backup the alpha before DrawText(), but that''s additional work. Thanks for any help
Advertisement
Hi... may be too green about DX and graphic programming in general but I''m still almost sure that you''d have to try to set your Render states and so on (ie textures states etc.) properly. I dont have any clue as what exactly you gotta do but I think you should check this.
Hope it helps some. ;-)

Prog, Hex & Rock''n''Roll :
I don''t like the Prog but the Prog likes me.
Some nice poetry to sweeten your spirit and relax a bit before programming
Prog, Games & Rock'n'Roll :I don't like the Prog but the Prog likes me.
Thanks Kurt for the suggestion, but I''m sure there''s nothin'' to
do with the RenderStates... I''m currently DrawText() onto my
own HBITMAP, and copy the content (bitmap raw data) to the
texture.. Even before I copy the content over to the Direct3D
texture I locked, the alpha values are already reset to zero..

Only the alpha values in the area covered by the text are
reset, the rest remains untouched. So looks as though the
bitmap has some holes on it.

Thanks anyway




GDI is not designed to handle transparency on DC level.
DirectX has a font interface, ID3DXFont, that is not only faster than gdi text, but also handles transparency correctly.

kind rgds,
-Nik

Niko Suni

Woooooo thanks Nik, I know that ID3DXFont takes care of the
transparency perfectly. But my only concern here with it is the
performance. I heard the ID3DXFont is slower than CD3DFont... I
can''t start implementin'' it before I know which approach is
faster. From what I have found out here in GameDev, it seems
that CD3DFont is faster than the ID3DXFont before the summer
update (DirectX 9b). Now it becomes an unknown again after that
summer update... Any advice?




"I
can''t start implementin'' it before I know which approach is
faster."

that''s the wrong way to go about coding. it''s never a good idea to let an implementation choice hold up your design and coding. just write your own interface and hide the implementation details behind that interface. then you can use whatever you want, ID3DXFont, CD3DFont, homegrown, whatever. and after performance testing later, if you need to you can change the implementation without having to change the interface or any code that makes use of that interface. and if you''re smart about it you can change the implementation so that it uses whichever method is faster depending upon the runtime conditions.
You have a point there, in fact I'm already headin' that way. I
have the whole class close to complete except the text drawin'
part, it's still an empty function right now. OK, I'll try out
different ways later. First, get it to work

Thanks for the advice!






[edited by - HaywireGuy on October 14, 2003 8:53:49 PM]

This topic is closed to new replies.

Advertisement