PDA

View Full Version : Need help with DrawAlpha



Speeeder
31-03-2006, 05:50 PM
Hi everybody!

I'm developing a shoot 'em up style game with UnDelphiX v6 (The one on turbo.gamedev.net, top of the list). If I turn the 3D acceleration on, then the alpha blended pictures that I draw loose their single-colour transparency at some places. I've tried it on more PCs, and I've tried in Fullscreen 16 and 32bit mode and Windowed 24bit mode as well. The result is that same.

Does anyone have any idea how to fix this? Or any new UnDelphiX version coming maybe?

It's crapped here:
http://img443.imageshack.us/img443/4949/pic15sx.jpg

It's working well here:
http://img304.imageshack.us/img304/7337/pic27ox.jpg

The only difference between the way the two shield objects are used above (At least that I've noticed), is that the lower ship's shield is firstly loaded to a TBitmap, flipped there then loaded to the Surface with .LoadFromGraphic. Although I've tried loading the above ships' shield with a TBitmap and .LoadFromGraphic, but the bug was still present.

User137
31-03-2006, 06:43 PM
It's not so much about version but how you use it. Have you enabled acceleration? That means do3D, doHardware and doDirectx7Mode enabled.

Speeeder
31-03-2006, 07:02 PM
Well, my question almost started with "If I turn the 3D acceleration on"...

WILL
01-04-2006, 02:19 AM
Hi Speeeder, welcome to PGD and nice screenies! :)

I recommend checking out the turbo site (http://turbo.gamedev.net/) for the lastest version of UnDelphiX by Jaro as it has been updated to include hardware acceleration on top of the other updates that allow the use of DirectX 8.1 and I think DirectX 9 aswell.

It will help up the performance of your game if you are having speed issues using the alpha effects.

Robert Kosek
01-04-2006, 02:30 AM
Will:
I'm developing a shoot 'em up style game with UnDelphiX v6 (The one on turbo.gamedev.net, top of the list). If I turn the 3D acceleration on

Speeder, you might want to be sure it's the same as this one, which was recently released: http://www.pascalgamedevelopment.com/forums/viewtopic.php?t=3092

WILL
01-04-2006, 03:34 AM
oopsie sped past that one. ;)

Speeeder
01-04-2006, 01:49 PM
Weeell... I'm quite sure it's the latest UnDelphiX... I've taken it from Turbo some time ago, it wrote UnDelphiX v6, so I would guess it's the one on the forums as well... Also there is some blahblah, about that hardware acceleration in the readme, so yeeeaah... Hardware accel is also on, as I've seen speed increase when I tested some bigger rotation + alpha thing... Whatever. Point is that it's doing what the above pictures show. I'm using TDirectDrawSurfaces and I draw with DXDraw.Surface.blahhh. The shield images are using the exact same image, and as I said I only flip the one below. erm, I'm drawing them on a little different places of the program, but as far as I can remember, there are only simple .Draw methods between the two places. And, well, this is a tiny bit annoying, cuz I wanted to make alpha blended warp holes too etc, so it kinda sucks in software :) Oh, yea! And both pictures were taken in hardware accelerated mode.

Will: thanks for the welcome, and those screenies are crap, the game is very much prettyer with a proper background and some objects flying around :) Hehe, test map ^^

P.S. Yes, it works perfectly in software. And yes, I've noticed the forum post that says that the single colour tranparency can be crap on some display but damnit, it's working on the below one :D

Speeeder
01-04-2006, 02:45 PM
Mkay, I take the upper back... I've used UnDelphiX 1.05, don't ask how I managed not to know, I don't know myself... Anyway, thing is that I've installed 1.06, it works just as well in software mode, and if I turn on hardware mode (well, do3D at least...) the screen gets like this:

http://img217.imageshack.us/img217/962/pic33es1.jpg

Guess this version can't really cut out a part of the source image to draw (even tho those warp holes ARE cut... Strange...). And can't draw system-memory stored things... Orwhat... So I guess it's back to 1.05 :) However point is that it seems to actually work well, at some place, while it doesn't at some other, so I'd mainly like so ideas about what could cause the program to ignore the trasparency here and not there...

Robert Kosek
01-04-2006, 05:35 PM
Now that's goofy! :think:

It could be your drivers, video card ... otherwise we need Ijcro to take a peek at this. I've never used DelphiX. :D I Use Asphyre (http://www.afterwarp.net/).

Speeeder
01-04-2006, 05:42 PM
I have an ATi Radeon 9700 card with the Omega Drivers based on the latest ATi Catalyst drivers. I would think it's perfectly alright ;)

Ijcro, where are yoooouuuu? :)

Robert Kosek
01-04-2006, 08:41 PM
He's in Czechia. :P

Anyhow, try PMing/Emailing him (http://www.pascalgamedevelopment.com/forums/profile.php?mode=viewprofile&u=439).

Speeeder
01-04-2006, 11:22 PM
I would prefer not to pester ppl, if he's around and he has time he'll prolly look at this post othervise, I'm outta luck... It still works in software after all :)

AthenaOfDelphi
02-04-2006, 07:17 AM
Hi Speeder,

You say you're having problems with alpha blending destroying the transparency information in some situations.

What colour are you using for the transparency?

When I was experimenting with UnDelphiX for this years competition, I had some similar problems, so I went hunting on google and I came across some information that suggested the best transparency colour to use was pure black.

Certainly I was having all sorts of problems using magenta and lime... when I switched transparency colour to black, the problems went away. Of course, once you've switched to using black, if you want black to appear on your sprites etc you have to use a very very dark gray (I use $101010). Any darker and I was finding the hardware matched it to black and parts that weren't supposed to be transparent became transparent.

Just a thought :-)

Huehnerschaender
02-04-2006, 07:28 AM
As you can see in his first post, he seems to use magenta for transparency. I also guess that this is the problem, because when hardware is set to dither images the color information may be corrupted a bit.

And Speeder, you don't pester ppl here. It's a forum! And people are supposed to ask questions and post their problems here :wink:

AthenaOfDelphi
02-04-2006, 08:41 AM
I should read more, I know, but its Sunday morning, it was early when I read the thread and I'd been up since 4am watching the Australian GP so I was being lazy :D

Huehnerschaender
02-04-2006, 09:48 AM
Don't try to find excuses! *lol*

Just kidding... :)

Speeeder
02-04-2006, 09:54 AM
Magenta... duhhh... Well, I have uhhm, let's seeeee...
7+20+4+1+4+7+20+3+8+27 Pictures / Animations / Framed pictures as of yet... hhmm... Well, then it'll be software mode for some more time :lol: Thanks for the help tho! (Why on EARTH does it dither 256 colour bitmaps on a 32bit surface?)

Speeeder
02-04-2006, 10:02 AM
Well, I would think finnishing the bosses and writeing the AI and a proper scoring algo WOULD be more important for the game than hardware acceleration to a game that takes at most 10% CPU on my 2GHz Athlon... (And that's the system memory stored background and streaming HE-AAC format music, not my stupidness :P)

Traveler
02-04-2006, 10:10 AM
In case you own PhotoShop, its quite easy to change the color of all your images into black using actions.
Record the steps for one image and run them automatically for all other images in a directory.

Speeeder
02-04-2006, 10:22 AM
I'm using Paint Shop Pro, I know using scripts, buuuut... Think this would be a bigger work right now that I would wanna spend on it :) Future patch maybe! :P

AthenaOfDelphi
02-04-2006, 10:42 AM
The thing to do, is try one image that you know causes the problem... the shield for example. As I said in my post, this COULD be the problem, it might not be, but for one image, its worth a try... at least then you know either way and if it is, you can schedule it in down the line.

Speeeder
02-04-2006, 11:07 AM
Gave it a try, no winwin :(

User137
02-04-2006, 11:14 AM
I could point out that DelphiX source is right there :) If you know how, you can experiment things like removing that dithering. If it works please tell all the details so it ends up in next version of UnDelphiX. It's just DirectX when it comes to core of it :wink:

ps. DXDraws.pas is the unit that renders all and handles the textures.

Edit: And 1 more thing, try what happens when using different image sizes. For example 3D cards are most optimal for square textures with size power of 2 (mostly 64x64, 128x128, 256x256).

Speeeder
02-04-2006, 12:05 PM
Yea, I guess, but I'm only a starter at programing yet :) I don't have much knowledge, only what I picked up learning DelphiX...

ijcro
03-04-2006, 06:39 AM
Hello!

I can say few words only.

Version 1.06 has fixed transparent color, previous version had wrong color key order, it was hard problem, I think that its out now.

Problems in SW mode occurred when display set to 32 bit (no work blend etc.) I don't know where is error, but Hori's functions in DXRender I don't rewite, it's original DelphiX-unDelphiX still.

I have to many functions (spot generator, font generator, map editor, particle sprite etc.) get out, because no work properly in SW mode.

You take note that some functions and units was integrated into DXClass and DXDraws (some mathemathics functions, texture unit, font unit, fast pixels etc.), not all is done.

Very thanks for User137 and Mr. Takanori Kawasaki for their great idea. Thanks.

Speeeder
03-04-2006, 08:11 AM
hhmm... Okay, thanks for the reply I will try 1.06 Un with 16bit, hardware then...

Oh, one more question... Is it normal that Delphi 7 pops up a couple of warnings and hints when I compile UDX .6? Mainly in DIB and DXDraws, some in DXWave, DXSprite, TurboPixels.

Speeeder
03-04-2006, 08:29 AM
Well... to say it lightly it looks crapped as hell :P
The pictures I store in system memory eighter don't show, or show at a totally bad place and size. There are only a very few things that display well, but in fact the transparency on the upper ships' shields is stil crapped XD

ijcro
03-04-2006, 08:55 AM
OK, many warnings is normal (DelphiX was founded in Delphi3, so Delphi2? I don't know it), you have to turn off warnings in IDE, but it's no problem with running.
You have to set "Assignable typed constant" options only (it is overwritten in history.rtf file).

When you find bad functionality in this version 1.06, and you can isolate and separete problem into simple application, please send me result, I can fix it or I can quick use your solution. Thank you for your oppinion.
:oops:
Regards

Speeeder
03-04-2006, 09:04 AM
hhmm... The proggy's pretty big... Well, I think I'll just finnish it, and after it's done I'll show it to you... (That should be some close to 1 monthish more I guess... I'm fairly lazy :P) Thanks for offer to help!

ijcro
03-04-2006, 12:46 PM
OK.

Note, on Turbo site is still old version of HW unDelphiX 1.05 (signed there as 06 too).

When I sent in November 2005 to Turbo support info mail about changes in DXSpriteEngine, no answered me :?

But Mr. Willson send me clear E-mail about Turbo site situacion. :cry:

Last versions and new home of unDelphiX is there http://www.micrel.cz/Dx now. :P

Bye

Speeeder
03-04-2006, 01:15 PM
Yeah, yeah, tried that one, but it somehow totally mussed up all the system memory stored pictures in hardware mode and did pretty strange things for me othervise as well... Strange thing is that .05 CAN actually display the transparency in hardware as seen on my second picture, but not on every place as seen on my first picture :P
That's why I still think that that one is somewhat closer to the yay ^^
Oh, what visual greatness would be some lens flares... :P

Speeeder
05-04-2006, 11:13 AM
OH FOR ****'S SAKE! I got it!!! In hardware mode .05 ignores the transparent colour setting and simply uses the upper-left corner pixel's colur as transparent!!! AAAHHHHH

ijcro
06-04-2006, 06:11 AM
This feature is in version 1.05 and 1.06 too but in 1.06 is corrected it for explicit set color key. image_pixel[0,0] is used for surfaces only, because there isn't set up color but boolean switch transparent only. there http://turbo.gamedev.net/ is old version still. Regards

Speeeder
06-04-2006, 11:02 AM
Yeah, but point is that I've figured this out, and .05 works well for me now... .06 is very... *VERY* ****ed up somehow... Don't ask me tho, I have no idea what's on with it... As said, you'll see a final-ish version of the game + source...

ijcro
06-04-2006, 01:59 PM
Do you use 05 version as well? Hmm.
It si depend by picture or algorithm? Send me, please, snippet of your code how you it use please! Thank you!

Speeeder
06-04-2006, 02:23 PM
Example objects:



TShipType = class
private
public
ShipName: String;
Picture: TDirectDrawSurface;
PictureFile: String;
MaxHP, MaxShield, MaxSpeed: Double;
HitSoundIndex: Integer;
HitBoxes: Array of TRect;
Turrets: Array of TPoint;
end;

TShip = class
private
ShieldAnimIndex: Integer;
ShieldHits: Integer;
Procedure Shoot;
Procedure HitCheck;
Procedure Explode;
Function AI: ShortInt;
public
ShipType: ^TShipType;
Position: TPoint;
HP, Shield, Speed: Double;
NoShield, Invulnerable: Boolean;
LaserType: ^TLaserType;
Lasers: Array of TPoint;
LaserCoolDown: Word;
IsWarping, IsExploding: Boolean;
WarpCounter, ExplosionCounter: Word;
Procedure WarpIn;
Procedure Update;
Procedure Draw;
Procedure DrawLasers;
end;


Picture loader for the ship's pictures:


...
If Length(ShipTypes) > 0 Then
For I := 0 To Length(ShipTypes) - 1 Do
Try
ShipTypes[I].Picture := TDirectDrawSurface.Create(Window.DXDraw.DDraw);
ShipTypes[I].Picture.LoadFromFile(Misc.GetAppDir + ShipTypes[I].PictureFile);
ShipTypes[I].Picture.TransparentColor := $FF00FF;
Except
Misc.Error('Cannot load the picture: ' + ShipTypes[I].PictureFile + ' of ship: ' + ShipTypes[I].ShipName);
end;
...


Picture loader for the shield picture:


If ShieldType.PictureFile <> '' Then
begin
ShieldType.Picture &#58;= TDirectDrawSurface.Create&#40;Window.DXDraw.DDraw&#41;;
ShieldType.Picture.LoadFromFile&#40;Misc.GetAppDir + ShieldType.PictureFile&#41;;
ShieldType.Picture.TransparentColor &#58;= $FF00FF;
end;


Drawing code:


Procedure TShip.Draw;
var ShipRect&#58; TRect;
// Function to get the shield effect's alpha
Function RetShieldAlpha&#58; Integer;
var I&#58; Integer;
begin
Result &#58;= 100;
For I &#58;= 1 To ShieldHits Do
Result &#58;= Result + 15;
If Result > 200 Then Result &#58;= 200;
If ShieldAnimIndex < 15 Then Result &#58;= Result + Round&#40;&#40;ShieldAnimIndex - 15&#41; * 6.7&#41;
end;

begin
If NOT&#40;IsWarping AND &#40;WarpCounter <= 30&#41;&#41; Then
begin
ShipRect &#58;= PicRect&#40;Speed, ShipType.MaxSpeed, ShipType.Picture.Width, ShipType.Picture.Height&#41;;
// If Warping&#58; &#40;30-110. warpframe&#41;
If IsWarping AND &#40;WarpCounter > 30&#41; AND &#40;WarpCounter < 110&#41; Then
ShipRect.Top &#58;= Round&#40;ShipRect.Bottom - &#40;&#40;WarpCounter - 30&#41; / &#40;80 / ShipRect.Bottom&#41;&#41;&#41;;
// Draw
Window.DXDraw.Surface.Draw&#40;Position.X, Position.Y, ShipRect, ShipType.Picture, True&#41;;
// Shield
If ShieldAnimIndex > 0 Then Window.DXDraw.Surface.DrawAlpha&#40;Bounds&#40;Position.X, Position.Y + ShipType.Picture.Height + 5 - ShipRect.Top - ShieldType.Picture.Height, ShipType.Picture.Width DIV 5, ShieldType.Picture.Height&#41;, ShieldType.Picture.ClientRect, ShieldType.Picture, True, RetShieldAlpha&#41;;
// Spark
If &#40;&#40;HP < ShipType.MaxHP / 6&#41; AND &#40;Random&#40;64&#41; = 0&#41;&#41; OR &#40;&#40;HP < ShipType.MaxHP / 3&#41; AND &#40;Random&#40;64&#41; = 0&#41;&#41; Then
begin
Misc.Sounds.Play&#40;SparkSounds&#91;Random&#40;2&#41;&#93;, Round&#40;&#40;Position.X / &#40;800 - ShipType.Picture.Width DIV 5&#41; * 200&#41; - 100&#41;&#41;;
With Window.DXDraw.Surface.Canvas Do
begin
Pen.Width &#58;= 1;
Pen.Color &#58;= clAqua;
MoveTo&#40;Random&#40;ShipType.Picture.Width DIV 10&#41; + Position.X + ShipType.Picture.Width DIV 20, Random&#40;ShipType.Picture.Height&#41; + Position.Y&#41;;
LineTo&#40;Random&#40;ShipType.Picture.Width DIV 10&#41; + Position.X + ShipType.Picture.Width DIV 20, Random&#40;ShipType.Picture.Height&#41; + Position.Y&#41;;
Release;
end;
end;
end;
end;


P.S.: I know my code is shit at places and that spark thing is very lame, but I'm a lazy person, so don't tell me about these... :P

User137
06-04-2006, 02:46 PM
Well that's new approach alright :o Never seen images held as surfaces in that scale before...propably 1 reason for problems. TDXImageList was made for the purpose of holding all game graphics. To manually fill it from files, there is much discussion around internet so i'm not going into details now... no Delphi open and all :P

Traveler
06-04-2006, 04:05 PM
Well that's new approach alright

Not at all. It's also how I have been doing things when I used DelphiX. Its also one of the ways in the demos provided. It works quite well IMO.

note: I've always used the last version of DelphiX by Hori and not any of the newer (undelphix and newer) made by other developers.

ijcro
06-04-2006, 06:39 PM
note: I've always used the last version of DelphiX by Hori and not any of the newer (undelphix and newer) made by other developers.

It's well, I want collect all changes from developers around the world and put it into last version unDelphiX. :D

Many developers no work in DelphiX now, their links no lives on Internet and others developer waiting only complete and fully functional version. Anybody not want spend their time to learn basics, at first clamp they run off. Because unDelphi is perfect not yet , they rather vote C++ and pure DX or any OpenGL version without Delphi (and when you can use Delphi from now on? Try Asphyre instead! Or anything other!). Framework unDelphiX is trifle now only... it is sad reality. And position DelphiX in Japan, where DelphiX was born, is the same or worse.

:idea:

Speeeder
07-04-2006, 09:52 AM
Well, I just like DelphiX's approach, but this is my first real thing in fact, so that's about why I used it... I wanna learn C++ and pure DirectX too and try to go for being a real game programmer... But first I should finnish this as a good prog for my finals at school :P

Speeeder
17-04-2006, 12:09 AM
Well, I was messing - again - with 1.06 DelphiX, and I've got why it is ****ed up at me:
If I comment this line:
{$Define DrawHWAcc}
then it works perfectly... Wonder what does this enable that messes up drawing THIS much...

Speeeder
17-04-2006, 12:17 AM
hmm, I also see that this for the TDirectDrawSurface part is only present for TDirectDrawSurface.Draw... Which would also tell why were SOME things okay more or less while this was on... question: what the heck could be wrong with D2D.D2DRenderDrawDDS? :( Someone please help, cuz this might as well fix my slowdown prob...

Edit: Okay, umm, some lil more exact description... I'm storing the images in TDirectDrawSurface-s... There's one surface with the background picture, that's mostly megs of memory... Well, it completely doesn't display that. Then there are some menu pictures that I store in the system memory... Now those are switched up, sometimes drawn to a bad place, things like that... Then there are images that store multiple frames of an animation... Those aren't cut out from the main picture when drawn... aaand... As I've looked, StretchDraw() uses the perfectly same way as Draw(), and StretchDraw doesn't even have this IFDEF, so guess I've always used that... It worked and works... aaaaand, it's quite late and I'm a little crappy with numbers prolly, but "D2D.D2DRenderDrawDDS(Source, Bounds(X, Y, SrcRect.Right - SrcRect.Left, SrcRect.Bottom - SrcRect.Top), Transparent, 0);" seems to be totally right to me, and that's the only difference that I've seen between Draw() and StretchDraw... Oh, and of course if I take the IFDEF out, the unaccelerated Draw works PERFECTLY... So I don't think it'd be some error with my calling the Draw...

Edit2: Yet another question could be: why do the menu pictures crap up when I draw them from an imagelist? I still have DrawHWAcc disabled and I'm commenting and uncommenting the IFDEFs, so, no, I'm not THAT much of an idiot that I've enabled the wrong thing on the ImageLists' Draw method...

Edit3: Correction, TDirectDrawSurface has 2 StretchDraws overloaded and only the one without sourcerect parameter has acceleration... So I guess I haven't used that one after all, so the baddy should be the D2D.D2DRenderDrawDDS...

Edit4: Okay, guess it wasn't intended to work for the Draw that had a source rect in it at all, so I removed it... The latest and final question of mine would be... could anyone come up with a smart idea for drawing sub-images of one bigger image? I don't know DirectX good enough to do that :)