Archive: Rendering text in APE


18th February 2002 15:43 UTC

Rendering text in APE
Hi all,
I'm a newbie at VC++, and would appreciate some help from you pros. I am writing an APE that has to render text to the AVS/WVS window. I have rendered it into a memBitmap, but can't figure out how to copy
it to the AVS framebuffer. Since AVS doesn't expose a DC, I can't BitBlt it, and am clueless about writing directly to the framebuf. Any tips or example code would be appreciated.

Thanks.


19th February 2002 00:44 UTC

The AVS framebuffer uses the 32-bit color format RGB0 (or maybe BGR0, not sure). It's best to get rid of GDI DeviceContext for drawing because they'll always be slower: implement your own line-drawing algorithms and you'll be waaay faster. If you *really* need GDI, create 32-bit a DIB using CreateDIBSection as your bitmap. You'll receive a direct-pointer to the DIB-data when you create it, which you can use to copy the bitmap's contents in RGB0 straight into the AVS framebuffer.
For optimal speed, you'll need to use MMX operations in your code for operations such as blending or adding. They're very suited to RGB0 images. You can always use them, as the width of an AVS window is always a multiple of 4.


19th February 2002 14:48 UTC

cool...
Cool, that was easy! Thanks, UnConeD, you're a sweetheart!

It IS very slow though, nowhere near as fast as the built in text render. Did the author (lone, I think) use MMX? Can you point me to some MMX resources so I can get started?


19th February 2002 20:47 UTC

I haven't tried MMX myself yet, but I've read about it on the web. Can't do it now, because my old VC++ doesn't know MMX assembly instructions.

If it's really a lot slower, are you sure you're accessing the bits directly and not through GetDIBits()? I've made some APE's myself for my next preset pack (will release them at the same time) for a few effects such as larger fast brightness and special cases of color clip (all nonblack -> white and vice-versa), and they approach the built-in effects in terms of speed. I can even improve my fast brightness if I use MMX instructions, in which case it'll be just as fast for the same functions, and faster than 2 or more instances of the built-in effect.

Here are a few URLs on MMX instructions. There's quite a lot more tutorials on the web about using MMX instructions for 32-bit pixels. Look for code for fast alpha-blending, they should point you in the right direction.

- http://space.virgilio.it/insignis@ti...aTransfer.html
- http://7gods.sk/coding_mmx.html

I'm also going to clean up my APE's code and release them as open-source, so that other authors can improve theirs and code new ones based on mine.