CAnimSprite Class with Alpha-Blending(Transparency)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

CAnimSprite Class with Alpha-Blending(Transparency)

Post by DaChief »

I was wondering how to do Alpha-Blending with the CAnimSprite Class posted in the Wiki

i heard somethin about setVertexColorAlpha(person->getMesh(0),200); somewhere in the Forums but i have no idea how to use it in the Sprite-Class.
i've also tried to set the Alpha at the SColor of the S3DVertex to 0 for example, but nothing happends... after a few other tries i gave it up.

I thought of a function called setAlpha(int alpha) or something like this for setting the transparency of the Sprite.

I hope someone can help me out of this

by the way: How can i set the Alpha at 2D-Images(using draw2dimage) ?
i've been searching a while but i didn't find anything...
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

see the setBlend function of TMovieMesh class,it is what you are looking
for and apply it to CAnimSprite.

here is the link of TMovieMesh class

http://www.irrforge.org/index.php/Playi ... in_texture
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post by DaChief »

THX for your help. It looks like what i need...

but could it be, that this function simply sets the first s32-Value of the SColor Object ?
I'm not sure, but i tried that befor i posted my request in here and it didn't work very well. Ok it didn't work at all because simply nothing happend.

Maybe my problem is somewhere else:
if you set the Alpha of a Sprite, is it half-transparent if you put a 2d-Image behind ? Or do you have to but a Sprite in the Background as well ?

i think thats the problem, because i've tried to mix 2D-Images with Sprites(SceneNodes)

i'll try the setBlend() method tomorrow, maybe it works anyway and all my problems are gone ^^
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post by DaChief »

i've tried this method from the TMovieMesh to set the transparency of the Sprites:

Code: Select all

     
virtual void setBlend(s32 al)
      {
              Vertices[0].Color.setAlpha(al);
              Vertices[1].Color.setAlpha(al);
              Vertices[2].Color.setAlpha(al);
              Vertices[3].Color.setAlpha(al); 
      }
I've been trying for at least one hour to figure out why it doesn't work right.
I can put a 2D-Image or another Sprite in the Background but whatever i do, it is not transparent at all. The alpha-Value i use doesn't have any effect.

But if i chance some other Values of the Color, for example the Green part, it works. it is not transparent, but there i see that the values of the color can be changed. But if i change the alpha value simply nothin happends...

i'm sorry if it is a noob-error or something but i really have no idea why this shouldn't work.

hopefully someone can help me out of this. thx in adcance
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

you can only make it transparrent using vertex alpha if you use vertex alpha mode to draw it, but you also need transparren by colour key or all your sprites will have square borders.
You might need to combine the source code of the two render modes you need to make your own, but first i'd try some of the existing ones to see if any of them work like you need.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post by DaChief »

so it isn't possible to draw a 2D-Image or Sprite with Alpha if you use the Alpha-Channel of the Texture(like in PNG-Images) ?

i don't ike the Color-Keying very much, because you cant make some pixel half-transparent(like pre-rendered Anti-Aliasing, if you know what i mean)

Thx for trying the stuff out for me, at the moment i'm not pretty sure if i understand what you mean with "vertex alpha mode".
hope you can explain that for me i'm not as experienced as it maybe looks like ^^
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

what drive are you using,OpenGl or Dx?

to be honest, i have moved form using DX to use OpenGL for many
reasons,it is more easy ,and allows you to make some work could not be
done or hard to do with DX.

any way i will take a look and if it is ok,i will let you know.

Edited:
you could do that with OpenGL but not with DX if you are using OpenGL
Driver and want to know how to do it , let me know.
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post by DaChief »

sounds interesting.
i used a ComboBox in the MainMenu to choose the DriverType that will be used.. so if it is only possible in OpenGL i have to remove it, but in General it is no problem.

How does it work in OpenGL ? :wink:
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

DaChief wrote: How does it work in OpenGL ? :wink:
in your render function of CAnimSprite Class put those after
seting the material

Code: Select all

glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        glDisable(GL_ALPHA_TEST);
        glColor4ub(255,255,255,MyALpha);

where 
    
       MyALpha = ranged from 0 to 255
hope that help you.
Guest

Post by Guest »

@DaChief: I hear ya!. Antialiased edged sprites (using a true alpha channel) are essential for a modern look / feel to 2D graphics these days. Colour keying leaves jagged edges in many cases and is not adequate.
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post by DaChief »

@Guest
Jup.. :wink:

@Emil_halim
i've got some problems with your solution. Do i have to compile it with the engine to do that ?
i've been using the class as a header-file of a test-project because i made some little changes to it and for testing it was a lot more comfortable.
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

No you do not have to change the engine.

what kind of problems you got?
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post by DaChief »

well.. simple:
{
glEnable()
GL_BLEND
glBlendFunc()
GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA
glDisable()
GL_ALPHA_TEST
glColor4ub
} -> not identified...

could it be, that these functions come from the device or the driver ?
all my IrrLicht Stuff is in a namespace called "KXD::irrEngine"
Maybe i have to use them by -> using namespace KXD; using namespace irrEngine;

and maybe i should test someting like this before i cry around that it doesn't work ^^
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

it is so simple. you got those errors becouse you did not include OpenGL
Include file and did not telling your compiler the library that has those
functions.

firest you have to download OpenGl Includes&Libs stuff ,i have upload
them with Mixing_OpenGL_stuff_with_Irrlicht tutorial in wiki if you want
here is the link
http://www.irrforge.org/index.php/Mixin ... h_Irrlicht
then you must include the OpenGL headers in your program and tell the
compiler about the Libs for linking stuff.
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post by DaChief »

ok, i'll try it as soon as i can...

but to go back to my other question:
why can't i do Alpha-Blending by changing the Alpha-Value of SColor at the Sprites or 2DImages ?
is it a bug in the Engine ?
or for what can you use this Alpha-Value instead ?

and how does the Vertex-Alpha Mode works?

Only interested. Maybe i'll need it in another project...
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
Post Reply