GLBasic forum

Main forum => GLBasic - en => Topic started by: Moru on 2011-Mar-15

Title: MEM2SPRITE and transparency
Post by: Moru on 2011-Mar-15
How do I use the transparency correctly when making sprites with mem2sprite? I try with 0x00 and 0x0f and I only get 1 bit transparency. 0-14 makes 100% transparent, 15-255 makes 100% non-transparent. I thought it would be 8 bit? What am I missing?

Code (glbasic) Select

GLOBAL sprite%[]
GLOBAL abgr%, r, g, b, a
GLOBAL mx, my, b1, b2
ALPHAMODE 0.9
DIM sprite[100*100]

FOR n = 0 TO 16
DRAWRECT RND(800), RND(600), RND(800), RND(600), RGB(RND(255), RND(255), RND(255))
NEXT
USEASBMP

WHILE TRUE
FOR y = 0 TO 99
FOR x = 0 TO 99
abgr = bOR(ASL(x, 24), 0xffffff)
sprite[x + y * 100] = abgr
NEXT
NEXT
MEM2SPRITE(sprite[], 1, 100, 100)
MOUSESTATE mx, my, b1, b2

DRAWSPRITE 1, mx, my

SHOWSCREEN
WEND

Title: Re: MEM2SPRITE and transparency
Post by: Kitty Hello on 2011-Mar-15
You need to enable alpha blending when you draw it:
   ALPHAMODE -1
   DRAWSPRITE 1, mx, my
Title: Re: MEM2SPRITE and transparency
Post by: Moru on 2011-Mar-15
ALPHAMODE is in there already but in the start. I noticed now that SHOWSCREEN resets alphamode, did it do that earlier too? Never had this problem before, but it works if I put it just before the drawsprite.
Title: Re: MEM2SPRITE and transparency
Post by: MrTAToad on 2011-Mar-15
I believe ALPHAMODE was reset with each SHOWSCREEN
Title: Re: MEM2SPRITE and transparency
Post by: Kitty Hello on 2011-Mar-16
SHOWSCREEN resets pretty much everything.