Mask for background animations and transparencies

Previous topic - Next topic

erico

#30
Damn it can´t do.

Revising the code, I could only do it with alphamode 1 (bad for caanoo) and as it is, the outer sides had to be white instead of black.
Really complicated stuff! How can it be?

The following code was supposed to work on my mind.
I can draw the pink color on the virtual screen, but when I come back to use it on the primary screen, there is no way it will read the pink as transparent.

What do you guys think?

EDIT: click mouse to add an extra ball

Code (glbasic) Select
// --------------------------------- //
// Project: LIGHTMASK
// Start: Thursday, February 07, 2013
// IDE Version: 10.283

// BKG image by Stefan Bogdanovic http://www.pixeljoint.com/p/7846.htm



SETCURRENTDIR("Media") // go to media files

//--------------------------------------------------------------- VARIABLES
GLOBAL mx,my,b1,b2,x,y,vx,vy
vx=1
vy=1

//--------------------------------------------------------------- SCREENS

SETSCREEN 320,240,0
CREATESCREEN 2,1,320,240
SMOOTHSHADING FALSE

//--------------------------------------------------------------- LOAD ASSETS
LOADBMP "BKG.png"
LOADSPRITE "LH.png",0

//--------------------------------------------------------------- LOOP START
WHILE TRUE

USESCREEN 2

DRAWRECT 0,0,320,240,RGB(0,0,0)
MOUSESTATE mx,my,b1,b2

SETTRANSPARENCY RGB(255,255,255)

IF b1 THEN DRAWSPRITE 0,mx-38,my-38
DRAWSPRITE 0,x-38,y-38

x=x+vx
y=y+vy
IF x>320 THEN vx=-1
IF x<0 THEN vx=1
IF y>240 THEN vy=-1
IF y<0 THEN vy=1

USESCREEN -1

SETTRANSPARENCY RGB(255,0,128)
DRAWSPRITE 1,0,0

SHOWSCREEN
WEND
//--------------------------------------------------------------- LOOP END


imgs attached too

[attachment deleted by admin]

Ian Price

Yep, that's exactly what  came up with too.

There just seems to be no easy way of doing it that works well on the Caanoo.

It doesn't make any logical sense that an effect like this is so hard to do in GLB. I've done it in Blitz, BlitzMax and other languages over the years. As I've shown it can be done, but with no easy route.
I came. I saw. I played.

erico

Could it not be done if the set transparency command ´worked´ before drawing on the final screen?
I set it back to pink, but it won´t affect the sprite at all.

Would it be too hard for Gernot to mess with this?

On the topic you raised, you said it not to be that much important, but this the only ´easy´ route I thought of doing such.

I have seen threads asking about creating these kinds of lightsources, I always thought that such route would be a logical way of doing, now that I tried myself, it almost fried my mind yesterday.

Ian Price

Quotenow that I tried myself, it almost fried my mind yesterday.
And I've been trying to find an alternative method since September last year!!!" :S  :giveup:
I came. I saw. I played.

erico

It sure would be nice if we could draw transparencies, as a color.

graffix989

could you make an array from said image and setpixel from that ? just ignore something you introduce to the array as "transparent"... i dont have a caanoo so dont know what your restrictions are? may be more taxing on your FPS but i dunno :) just a thought
not at my computer at the moment but code should roll on something like this:
assuming RGB(255,0,0) is your "transparent"

LOADSPRITE "blah.png",0
GETSPRITESIZE 0,sx,sy
SPRITE2MEM(image[],0)
for a = sx-1
for b = sy-1
if image[a+b*sx] > RGB(255,0,0) or image[a+b*sx] < RGB(255,0,0) then SETPIXEL sx,sy,image[a+b*sx]
NEXT
NEXT

Ian Price

SETPIXEL is too slow to use like that in real time on a pc, let alone a Caanoo.

All we need is to be able to draw a solid pink (RGB 255,0,128) image onto a virtual screen and then display the screen with transparency. GLB does it already with DRAWRECT, but other drawing options don't work the same (even SETPIXEL).
I came. I saw. I played.

graffix989

and thats only on the caanoo?? interesting, ive heard of how many color bits the image is created in will affect transparancy findings.. however i would assume you already tried setting all images to ,like 8bit colors ?? maybe a coded C workaround might be in order :|

erico

Not only on the caanoo, but you can quite go around on PC doing heavier stuff or using alphamode 1, etc.
A C++ workaround I think could do it, but too advanced for me and unknown how it would go on those smaller hardwares.

A fast multiplatform solution would come cool here.

Thanks for taking a shoot on it. :good:

erico

#39
Hey Ian,

First, I tried v11 beta, and it works fine on compiling to caanoo.
It installs by default on a different folder, so I keep both just in case.

But HEY!
Got an idea!

You said drawing rectangles works out, sorry I haven´t tried that.
But...
...maybe drawing a set of quads to get to a more pixelated kind of circle could help the caanoo port? (each quad on the img lets say 10 pixels square?)

Being "low res", you won´t need the dread cos/syn stuff.
You can draw a set of horizontal rectangles to get there.

You can draw each frame differently on a supposed to be circle, 2 frames, and alternating them is sure to give a fake ´transparency´ on the borders.
I think it may even look cool considering the game style and that the shark itself seems to be drawn on a different resolution too. :)

I leave you an example PNG depicting the blocks needed.
What do you think? It could even be very cool! :good:

EDIT: typos and...If those are too many blocks, it can be done with even less :booze:

EDIT2: Wampus, giving up, never! =D There must always be a way! :good:

[attachment deleted by admin]

fuzzy70

Here's my take using MEM2SPRITE, no idea how it will run on a Cannoo etc as don't have one to test on. The code is not the tidiest as just slapped together to test the idea  :D. Also no error checking to see if the cutting sprite is in bounds of the array etc but shouldn't be to difficult to add.

The example uses a sprite with white being the colour you want to use as the cutter & make sure it has no transparency or you get odd results sometimes  :D.

Lee

Code (glbasic) Select
// --------------------------------- //
// Project: mem2sptest
// Start: Friday, February 08, 2013
// IDE Version: 10.283


// FREE-VERSION:
// Need Premium for Features:
// 3D Graphics
// Network Commands
// INLINE C/C+++ code

SETCURRENTDIR("Media") // go to media files

GLOBAL screenpix%[]
GLOBAL cutsprite%[]

GLOBAL sw%,sh%,loop%

LOCAL cx%=100

SETSCREEN 640,480,0

GETSCREENSIZE sw%,sh%

DIM screenpix%[sw%*sh%]


LOADSPRITE "round2.bmp",10
SPRITE2MEM (cutsprite%[],10)



WHILE TRUE

SEEDRND 10

FOR loop%=0 TO 100
DRAWRECT RND(600),RND(450),RND(70),RND(70),RGB(RND(255),RND(255),RND(255))
NEXT

GOSUB resetbackgound

cutshape(cx,100,128,128,cutsprite%[],screenpix%[])
MEM2SPRITE (screenpix%[],1,640,480)
DRAWSPRITE 1,0,0

INC cx,1
IF cx>sw-64 THEN cx=100

SHOWSCREEN

WEND


SUB resetbackgound:
LOCAL l%

FOR l%=0 TO sw%*sh%-1
screenpix%[l%]=bOR(RGB(0,0,0), ASL(255, 24))
NEXT
ENDSUB

FUNCTION cutshape: x%,y%,sprw%,sprh%,src%[],dest%[]

LOCAL xl%,yl%

FOR yl=0 TO sprh%-1
FOR xl=0 TO sprw%-1

IF src%[xl+yl*sprw%]=bOR(RGB(255,255,255), ASL(255, 24))
dest%[(x+xl)+(y+yl)*640]=bOR(RGB(0,0,0), ASL(0, 24))
ENDIF
NEXT
NEXT

ENDFUNCTION


[attachment deleted by admin]
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

erico

I will take a look fuzzy70! and try it out on caanoo too.
Thanks for the help, it is always best when it is said impossilbe :good:

Arrays is a bit off to me to handle deeply, just recently I can manage a few and very simple ones :-[

Such making an alpha paste, drawing alpha bits with current tools (in my mind) is important, should be implemented.

In my case, it is for a future rogue zombi surviving project, in case of Ian, he is in a compo!!
Let´s hold the team up! Time is short! :good: :good: :good: hehe

fuzzy70

The code I posted is far from optimised & more of a "Proof of concept", the weakest part is definitely the resetbackground sub as that fills the entire array. One way to optimise it is just logging the pixels that have changed from the cutshape function & putting only those back into the screenpix[] array.

The code is easily changed to deal with alpha sprites by changing
Code (glbasic) Select
IF src%[xl+yl*sprw%]=bOR(RGB(255,255,255), ASL(255, 24))
with
Code (glbasic) Select
IF src%[xl+yl*sprw%]<>bOR(RGB(0,0,0), ASL(255, 24))

then anything that is not the same pure black as in the background will get changed to whatever the sprite colours/alphas are.

Am not at my main PC at the moment so can't play around with it at the moment but will see how far I can push it & optimise it later.

QuoteSuch making an alpha paste, drawing alpha bits with current tools (in my mind) is important, should be implemented.

I agree with that  =D

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Kitty Hello

Can you tell me how to do alpha drawing in other languages? The mem2sprite thing should work. Also, drawrect can draw alpha on an offscreen.

Ian Price

#44
Cheers Fuzzy - that certainly works well on pc. Will test on Caanoo and Pandora later. :)

[EDIT] Nope. Doesn't work on Caanoo - just shows a black screen.

[EDIT 2] Just tested for speed and this method is slower than my method (which also has all game logic running etc.), so it wouldn't work at a decent speed on Caanoo anyway. :(
I came. I saw. I played.