December 04, 2020, 03:23:11 am

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Alpha Blending

Started by Zen, June 27, 2006, 03:41:11 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zen

Ok so i get how i can make a sprite semi transparent but how can i make a say a black filled rectangle then make it so its semi-transparent? I've looked through the 2D include file and i cant see anything within any of the classes.

Any pointers ;) anyone!

Lewis

Ionic Wind Support Team

Create a sprite, draw a rectangle to it, and use it's alpha blending render mode.  The breakout example should help...specifically see the SetupPaddle funciton.

You could use PutAlphaPixel from C2DSurface but it would be a bit slow for a large rectangle.

Ionic Wind Support Team

Zen

Ok how do i draw a rectangle to a sprite? I know how to draw to a surface because there is a DrawRect method on the surface class. Couldnt see anything like that in the Sprice class though.

Lewis

Ionic Wind Support Team

See the example/funciton I specified ;)

m_Tile is a member of C2DSprite and m_Tile is derived from C2DSurface. 

sprite->m_Tile->DrawFilledRect(...


Ionic Wind Support Team

Zen

Ahhh, seems a long way around but its good enough for me.

Thanks a lot Paul

Lewis

Zen

Hi.

I still seem to be having a problem with Alpha blending. Although i am not trying to do it on a large scale now, Some things (small sprites) still need to be semi transparent. I cant seem to do it. Anyone give me an example?

Lewis

Protected

Actual sprites or black rectangles?

Zen

Actual Sprites. I have drawn some graphics and i want them to be semi transparent, not like how the SHADOW render mode does it, but so it is still visible but the background shows through.

Lewis

Protected

I think it should work if you used:

      SetRenderMode(RENDER_TRANSALPHA);
      SetAlpha(25);

But I'm getting weird results ~_~ It looks like it's showing whatever crap was in the buffer (it's ignoring the fact that the background is set to black) :-S

Zen

Yeah thats what i thought it was but all i have been getting is that crap too. Glad its not just me then :D

Lewis

Ionic Wind Support Team

I'll look but it did work the last time I tried it ;)

Rendering order is important and if your using RENDER_TRANSALPHA then the mask color has to be correct to.
Ionic Wind Support Team

Ionic Wind Support Team

July 04, 2006, 09:54:23 am #11 Last Edit: July 04, 2006, 09:56:53 am by Paul Turley
Well it looks like a bug crept in during one of the updates.

I'll fix it after the holiday.

EDIT:  Bug is only with 32 bit modes.  Works with 16 bit fullscreen.
Ionic Wind Support Team

Zen

Ohh good, i thought it was me. Thanks a lot Paul. At least i know it will work after.

Also another quick question. What if i want to use RENDER_TRANSSTRETCHED and RENDER_TRANSALPHA can i | them or will it not work?

Lewis

Ionic Wind Support Team

No there aren't combined modes currently. 
Ionic Wind Support Team

Zen

Ohh no! lol. I assume by currently, that you mean there will be eventually. Its just i have a few sprites that are 1x10px and is sized at runtime but also needs to be transparent.

Lewis

Ionic Wind Support Team

It's not an easy thing to accomplish but can be done.  Which is why I said eventually.

The alpha blending is done through software since DX7 never supported it through hardware.  The TRANSSTRETCHED is done with a hardware blit.  So a temporary buffer would need to be set up to apply the alpha first.

The alpha problem is fixed for Rev 6 BTW.   A simple matter of a signed/unsigned oversight on my part.
Ionic Wind Support Team

Zen

Ohh so when we use TRANSSTRETCHED it is actually telling the hardware to do something i guess through directX's com interface rather than something you have done like the alpha problem.

There is no rush as the project is quite large and it can be added later.

Yeah its always the simple little things that cause the problems in life.

Thanks
Lewis

Barney

Once 3D is added it's best to use what's called "2D in 3D" i.e. use 3D quads as sprites. That way one can still program 2D games but with all the bells and whistles available with modern 3D hardware. Blitz3D combined with Sprite Candy is an excellent example of such system.

Barney

Zen

Thanks barney, i will take note of your wise words. For now i will still carry on as its good practice about how graphical programming works. Its not a game im making though, its my GUI controls project i am working on.

Thanks
Lewis