GLBasic forum

Main forum => GLBasic - en => Topic started by: mentalthink on 2011-Dec-20

Title: Polyvetor and Alpha
Post by: mentalthink on 2011-Dec-20
Hi I don´t know if somelse comment this before, in this case excuseme....

Well I have a doubt, I want to make a simple polyvector, but in some corner I want it is totally transparent... (the sprite, can be have alpha channel or not, can be .JPG or .PNG or .BMP)

I think whit RGB can be done, but the Alpha channel , how I put a transparent value from the RGB command... and technical data... it´s internaly RGB-Alpha or Alpha-RGB, or nothing of both  :-[

Thanks in advance...
Title: Re: Polyvetor and Alpha
Post by: Wampus on 2011-Dec-20
Not sure if this will help. I'll try anyway.




I don't think you can set the alpha of a polyvector triangle point using RGB. If you could do it, it would be RGB+alpha. For instance something like...

POLYVECTOR sx, sy, px, py, RGB(255,255,255) + ASL(alpha,24)

...will make no difference. The original sprites alpha data and ALPHAMODE are the only ways as far as I know.

What you can do is change the alpha data of a sprite using SPRITE2MEM and MEM2SPRITE to change alpha data. That should work (afaik) even with BMP and JPG. Internally its RGB-Alpha.

I wrote some code to create special font sprite sheets for my Chaos R game. One part checks for black pixels with alpha 3 or less and makes them totally transparent:-

Code (glbasic) Select
abgr% = pimg%[arpart] // Read the colour as a whole

r = bAND(abgr, 0xff) // Read the individual colour values
g = bAND(ASR(abgr,8), 0xff)
b = bAND(ASR(abgr,16), 0xff)
a = bAND(ASR(abgr,24), 0xff)

IF r = 0 AND g = 0 AND b = 0 AND a < 4 // black with alpha of 3 or less

a = 0 // set alpha TO 0

pimg%[arpart] = bOR(RGB(r,g,b), ASL(a, 24) ) // insert back into array

ENDIF
Title: Re: Polyvetor and Alpha
Post by: mentalthink on 2011-Dec-20
HI Wampus, thanks a lot  :nw: :nw:

I will try your code, and comment...
Thanks in advance...
Title: Re: Polyvetor and Alpha
Post by: monono on 2011-Dec-20
Just put an ALPHAMODE before each POLYVECTOR to change the corners alpha. Every corner of the same polygon has to be above or under 0. Cant´t change ogl blendmodes in one call, I think. For example if the other corners have an alpha value of -0.999 and 0 in the one corner doesn´t make any differents, try -0.0001 instead.
Title: Re: Polyvetor and Alpha
Post by: mentalthink on 2011-Dec-20
Thanks Monono very interesting the solution...  :nw: :nw:

Thanks to both...

Kinds Regards,