View Full Version : Slow alpha blending with DelphiX

05-01-2006, 10:23 PM
Hi all,

Quick question... I'm working on my first attempt at a real game engine. One of the things I want to do is to provide a field of visibility that blends out items that appear higher than the player layer as they move closer.

I've created an array that has alpha values 255, 170, 85 down to 0 in the area around the player.

If I don't use alpha blending and instead I simply don't draw the 9 around and above the character, it doesn't slow down. As soon as I start using the drawAlpha function of TDXImageList.items, my frame rate drops to 11. Normally I time it down to 25fps from around 66-72fps (we don't need lots of speed since its supposed to have a retro feel).

Although this isn't a necessary, it does look nice, so Is there any other way of achieving this type of blending, without the slow down? Am I simply using the wrong software configuration options (Surface is 640x480x24)?

Just in case the rest of how it works is relevant... it goes something like this...


Calculate map pos from player pos and xLoop,yLoop

Draw map tile using TDXImageList.items.draw(dxd.surface,xCoord,yCoord, 0);

Obtain alpha value from alpha map

Draw overlapping tile using TDXImageList.items.drawAlpha(dxd.surface,xCoord,yC oord,0,alpha);

End xLoop
End yLoop

// Draw player sprite

// Movement processing

// Draw console command results/debugging text/console


Robert Kosek
05-01-2006, 10:31 PM
Depending on what version you're using this may be fast or slow, there is now a hardware accelerated version of DelphiX known as "unDelphiX (http://www.micrel.cz/Dx/)". You might want to check it out, if it's not what you're using. There is a semi-new version of it at the homepage I linked to. (As of November last year, bottom item)

Well, one way to smoothly vary the alpha is just a simple percentage calculation. Just round the result of 255*Percent and you'll have it without the array.

05-01-2006, 11:06 PM
Try searching around the forum, this problem was brought up many times before

05-01-2006, 11:36 PM
Basically what Robert said. :)

The guy who made the updates to the continuation of the DirectX project called UnDelphiX is a guy named Jaro. He added hardware acceleration to the existing UnDelphi code(code that was already updated from theDelphiX version and made to work with Delphi 7, optimized, etc --it's just better! ;))

If you are looking for the semi-official site for UnDelphiX, go to Turbo and look for the UnDelphiX link. That's (what I think) the best place to go for the latest packaged copy of it.

06-01-2006, 12:04 AM
Hi Robert,

I've just downloaded the unDelphiX demo program... the difference is amazing. Its funny, because I looked at unDelphiX before DelphiX, but decided not to download it for some reason.

Calculating the alpha value itself is the easy part. I opted to use the array method to save clock cycles for more important stuff. It was just the alpha blend functions that were slowing things down, so hopefully unDelphiX will fix that.

* WOW * - I just installed unDelphiX... what else can I say... DelphiX to unDelphiX and hardware acceleration on... 11fps to around 70fps.

Thanks :-D

Robert Kosek
06-01-2006, 12:13 AM
No problem. I might not be a great programmer myself, but I read around. ;)

Planning on supporting weaker PCs or effects that use a lot of clock cycles? :)

06-01-2006, 09:43 AM
Planning on supporting weaker PCs or effects that use a lot of clock cycles? :)

What are you saying about my PC??? :wink:

Basically, I'm trying to leave as many clock cycles free as possible so I can use scripting to provide the game logic rather than hard coding stuff, but obviously flexibility has its price and that price is clock cycles. That and the fact my PC is an Athlon 800 with a 32MB GeForce 2 GTS... it needs all the help it can get :-D

Many thanks guys.

06-01-2006, 10:05 PM
Perhaps my advice would be obvious for You, but have You tried to
turn of the doWaitVBlank option in DXDraw?
And another thing, You may be interested in this topic:

and this link http://www.micrel.cz/Dx/ for further DelphiX speed up ;)



I didn't know that Jaro=ijcro so You probably visited those links :wink:

07-01-2006, 01:06 AM
Also check out this thread.

It talks about using multiple surfaces to speed up drawing in DelphiX. (should still work for unDelphiX)

I know FPS isn't your main worry, but just something to keep in mind. :wink:

Robert Kosek
07-01-2006, 01:16 AM
What are you saying about my PC??? :wink: Well... twasn't meant in reference to your PC, but, ok? Don't tell, but my last PC was a pI 233mhz, with 32mb geforce 4(I think) PCI... Delphi 6 took ~8 minutes to boot.

So you're planning on a highly intelligent game, then? Good. I hope it's something akin to an RTS ... I've not had fun with one since AOK! Going for glitz lately. :roll: If not, bah, sounds neat anyway.

Guys, it's kinda hard to squeeze more FPS out of a system that old, she's doing a fabulous job as is. :wink:

07-01-2006, 02:58 PM
Thanks for all the additional pointers.

I'll have to have a read of all this before I write the real renderer. At the moment, all I have is a bunch of code thats serving as a test bed, will need to try out some of the suggestions and see which ones fit with what we are aiming to achieve.

07-01-2006, 08:53 PM
If you start thinking about 3D, but I doubt you will at this stage, you'll want to move onto something else than UnDelphiX. It's good for 'simple' 2D even with alpha now because of the hardware acceleration, but don't even think about 3D. :)

It can do it, but you'll be disappointed.