GLBasic forum

Main forum => GLBasic - en => Topic started by: erico on 2013-Feb-07

Title: Mask for background animations and transparencies
Post by: erico on 2013-Feb-07
Hi everyone.

While coding this one game, I finally came into slowdowns on more simple platforms.
All my fault of course as I simply ditched code till it could not handle anymore and frames dropped.

Now I´m looking into speeding things up and trying to understand how can I achieve the same without much trouble.

So, in this game, I have clouds moving on the background, the middleground, I´m pasting a huge sprite every cicle to cover those.

Game has no transparencies so smoothshade is off.
Is there a better/faster way to create this mask?

On another note, is there any performance issues (considering a caanoo) when I use png 32 bits instead of the purple sprite method?

Thanks for any help on that.
Title: Re: Mask for background animations
Post by: Wampus on 2013-Feb-07
If the slowdown is due to lots of rendering 2D textures, are you using Polyvector? If so, have you put all your sprites into as few sprite sheets as possible?
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
No polyvectors, just standard sprite commands.

I best illustrate the case, the TOO BIG SPRITE goes over the background so to cover the clouds.
Is there a way I can use a mask over the background clouds or something similar and less taxing?

Also, I´m drawing the hearts and hud stuff every frame, not needed, can I simply paste a sprite on the background and avoid that too?

[attachment deleted by admin]
Title: Re: Mask for background animations
Post by: Wampus on 2013-Feb-07
I can't be sure but from what I can see of the specs the Caanoo should be able to take a lot more than that without slowing up. You shouldn't need a mask. Hmm.

If you are calling Drawsprite many times you could speed things up by converting the sprite commands to polyvector commands. I can help you do that if you like.
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
Thanks Wampus! Really welcome!

The caanoo can sure handle a lot more then that, it is just that I went on bashing flat coding without ever thinking on optimization issues or anything else. and there is also a lot going over that image not into this example.

Part of the plan was to see when the little caanoo would not handle anymore of my slopy code and exactly where I would have to take care next time I code something I´d wish to also run on it.

Pc version goes fine, altough sometimes I get black flashes when the rain kicks in, but that is probably my cheap scalling routine :-[

Last year I did a code-test to check performance on caanoo considering sprite/polyvector commands.
At that GLB version, I got the best fps when using SPRITE commands.
kitty also stated that the caanoo is best optimized for those.
Here the thread:
http://www.glbasic.com/forum/index.php?topic=7197.msg59212#msg59212

Thing is, the game is just about done, missing very few features and sound/music, front end and end sequences.

I think if I can´t find a solution, it is best maybe to reduce the clouds area so to reduce the sprite pasted and maybe giggle a bit the other huge sprite goings.

I really appreciate  your offer though, thanks a million! :good:

Title: Re: Mask for background animations
Post by: Wampus on 2013-Feb-07
Ah ok. Sprite commands are optimized for Caanoo. Sorry for distracting you with that. I don't own such a device and I guess its faster for CPU rather than hardware render in 2D. And ok, so maybe the Cannoo can't take *too* much. I read the thread you linked to and I've also been reading this: http://caanoo-code.blogspot.ca/2011/12/2d-drawing-performance.html (http://caanoo-code.blogspot.ca/2011/12/2d-drawing-performance.html). I can see why you might be considering using a mask. That is...a bit tricky.

Fixing the refresh rate to 30 FPS, separating background into layers that include the clouds a bit like this (https://www.youtube.com/watch?v=QBymnt0uZYo) and seeing if making sure you're saving your sprites as RGB888 makes a difference are the only suggestions I can think of. Using a mask could be done but I've never done this.
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
No need to be sorry, I suspect polyvectors could gain some here, but on my tests, I could not make it run properly on caanoo, but then again, was an older version of GLB and I never used them in first place, altough my tests worked on pc as it should.

Thanks for the link! A bit too advanced for me, but it is great read, I do have to learn more on these. :good:

The backround clouds are composed of those 3 clouds that move with distinct speed.
I can get them smaller too as there will probably be some background and that will make it easier on the handheld.

Since things has been 60fps from the beguinning and it is an action game, I will cry(truly) if I have to lower that... :-[

I will try the rgb888 (that is no alpha channel right? using a color as mask, usually that purple/pink right?).

I´m not sure about a mask either, maybe I could draw the clouds on a different off screen and delete the part, but grabbing it back and pasting on the former screen sounds as an even more taxing thing...at least in my mind :(

Clouds are there to show the wind/storm movement and they change speed every other time.
Thanks for all the hints, let me see if the png24bit+pink/purple handles better then the png32bit.
Super thanks :good:

EDIT: oh, you mean rbg888 as 8bits per channel right? no alpha..
Title: Re: Mask for background animations
Post by: Wampus on 2013-Feb-07
No alpha. Correct. I don't know what it would do but its worth a try. Why not try RGB565 too because that is often *very well* optimised for lower end hardware. It may make a significant difference or none at all.
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
It did  :O :O :O

I could not use PNGs though, so I converted some of the heavier GFX to BMP rgb888.
Now things are all going around the 60fps again :O

Oh my :) :'( I think I can increase the number of sprites on the rain and add so much more special effects! :happy:
...and I only converted the bigger sprites!

I´m incredibly happy now, you can´t tell! :)

I didn´t know such could be a difference, I thought things were converted to the same inside GLB but had no idea about how the alpha would be handled, specially on lower handhelds!

Gee, super ultra 7 hardcore special thank you!!

I will try the RGB565 too.

I think I have a few beers over the fridge, will do a little celebration! :booze:
Awesome!

ps: the game is to sport many endings, you just made yourself into one now... I hope this thread helps other caanoo users on the issue too! :good:

EDIT: on another front, the black flashing square I was getting during rain on PC also disappeared. But I also got my smoothshading to false and alphamode to 0. yeeeahhhh :good:

EDIT2: heck, not quite gone the blinking, but waaay reduced, will check the scalling later :good:


Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-07
The Caanoo is pretty good with sprites, but rubbish with Polyvectors (I'm having a nightmare trying to get the dark sections in AquaVenture running at any decent speed - they're great on pc, good enough on the Pandora, but Caanoo? No way).

What you are doing should be no bother for the Caanoo - My "Shadow Of The Beast" demo runs with 11 parallax layers and huge tree sprites and full character control at 60FPS on the GP2X and Wiz - what you were asking shouldn't have any problems at all. Glad you got it sorted in the end though :)

I can't wait to see this game in action - you seem to have been working on it for a while, constantly teasing us with those lovely images :)
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
Thanks Ian.

The huge sprites are fine, the real problem is my coding.
I´m not instructed on doing so properly.

I learned BASIC on a coco 2 from the manual, an then advanced to AMOS, I never researched coding techniks nor anything related to how I should do it.
The AMOS factory community helped me a lot on this front.
I always took the approach of achieving the things no matter what, and always relied on the power of the language.
Many times I had to downgrade some ideas for performance because I just didn´t knew better.

It is one thing I love in GLB, I can just get things done, computers are so powerfull nowadays.

Still, I have to improve my coding abilities, in this case, I´m doing collisions on variables, not even using the collision commands ;/
Everything is drawn and checked all the time, I´m wasting A LOT of the caanoos power on that.
I do hope to use it as a way of learning to better code.

GLB is great and this community rocks, I can´t state that enough. <3

EDIT:what dark sections?? :O Don´t tell me please...

Title: Re: Mask for background animations
Post by: mentalthink on 2013-Feb-07
Hi Erico the graphics are very nice... this it's pixel art, or it's LW whit some filter... very very nice!!!

Whats it's bmp 888, bmp can contain transparency?¿...  :blink: :blink: If it's true, I'm a bit Donkey... 4 years using GLbasic and now I know this...  :nw:
Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-07
QuoteEDIT:what dark sections?? :O Don´t tell me please...
Unless I can pull a rabbit out of a hat, you won't be seeing them on the Caanoo I'm afraid :(

They don't look particularly good in static screenies so I attached a small (jerky) video. Don't watch if you don't want to ;) :P

[attachment deleted by admin]
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
Quote from: mentalthink on 2013-Feb-07
Hi Erico the graphics are very nice... this it's pixel art, or it's LW whit some filter... very very nice!!!
Whats it's bmp 888, bmp can contain transparency?¿...  :blink: :blink: If it's true, I'm a bit Donkey... 4 years using GLbasic and now I know this...  :nw:

Pixel art. I did cheat a bit by using some hand draw and photo references, still those are not the final, but are close.
I can´t lightwave small sprites, it has to be hand done. :(

Like those on Ian Price game (which are really awesome).
He is getting pretty good at that!

The 888 I guess refers to the bits per channel, ye 8 bits for red, 8 for green , etc.
On photoshop, when saving BMP, there is an advanced button, there you can state the type.
But even if I use 32 bit to save, when loading I can´t see the alpha, altough the channel is there in full black.
I never knew BMP could handle 32 bit either.

On the BMP888 type, the transparency will be that pink color 255,0,128.
It is just a mask, no antialiase or degrees of transparencies.
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
Quote from: Ian Price on 2013-Feb-07
QuoteEDIT:what dark sections?? :O Don´t tell me please...
Unless I can pull a rabbit out of a hat, you won't be seeing them on the Caanoo I'm afraid :(
They don't look particularly good in static screenies so I attached a small (jerky) video. Don't watch if you don't want to ;) :P

..as if I have the choice not to see it :rant:
At least it is not spoiling the puzzle hehe :good:

Now let me see if I get it.
The idea is that each thing that produces a light, has a filled circle over it and that is the only seen part of the stage?

Seems simple at first, and such must be able to be done as I want similar on my ´living dead rogue´ game.
First thought would be to use some offscreen buffer, but I´m not sure how fast they move on caanoo, but they seem fast on PC.
Something like:

-draw the game on an off screen 1.
-create another off screen 2 in black.
-draw a pink (to be transparent) circle over the objects that produce light on this screen 2.
-grab screen 2 and paste over scree 1
-show the result.

In this way of thinking (which you probably thought of it too), lots of off screen things going, I´m not sure if the caanoo can handle such.

I will see if I can think of any other way. It must be possible!


Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-07
Almost right, but...
Quote-draw a pink (to be transparent) circle over the objects that produce light on this screen 2.
You can't. There is no way to draw a pink (255,0,128) circle onto the black screen unless you build it up out of rectangles. You can't display a pink POLYVECTOR, DRAWLINE, DRAWSPRITE or even SETPIXEL and have it show through as if the pink was transparent. I've tried a hundred and one different ways to do that. You can use DRAWRECT but that requires multipls squares to draw a circle. And you can't change the transparency on the fly with SETTRANSPARENCY.

What i had to do is use the background graphic in the POLYVECTOR and draw it using COS&SIN, which are very slow even from a lookup table.

So I'm drawing -
- background screen
- black virtualsprite with polyvector halos
- drawing virtualsprite over background
- scaling the whole lot up/down to relevant screensize.

The Caanoo  is working really hard to get 30FPS, but it's not really enjoyable.

If I could find a way to draw the pink circle without COS&SIN (or even without POLYVECTOR) I think this would be playable. However I asked Gernot about this for something else I was doing back in September and he couldn't come up with another answer. In fact you took part in the discussion erico - http://www.glbasic.com/forum/index.php?topic=8587.msg72601#msg72601
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
QuoteYou can't. There is no way to draw a pink (255,0,128) circle onto the black screen unless you build it up out of rectangles. You can't display a pink POLYVECTOR, DRAWLINE, DRAWSPRITE or even SETPIXEL and have it show through as if the pink was transparent. I've tried a hundred and one different ways to do that. You can use DRAWRECT but that requires multipls squares to draw a circle. And you can't change the transparency on the fly with SETTRANSPARENCY.

Now for a dumb question, can´t you do a PNG sprite of the pink circle and paste it drawsprite style? That way the pink goes on.
I´m not sure when grabbing this virtual screen and applying over the normal one the transparency will remain, but why would not?
I guess I would have to give it a test to check.

Let me re-check that forum topic.
Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-07
Nope - pasting a transparent sprite won't work. For starters the black background comes through in the pink and even if it didn't, how would you draw the hole transparent, but not the surrounding image anyway. If you draw the outline in black, if you draw two circles interlinked you'd see the black outline.

I've tried literally dozens of different ways to achieve the outcome - now and before. Obviously it does work (on pc very well), but not on lower specced machines. It's something I really wanted in my other game and this, for all formats.
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
Altough I think I´m understanding what you want (ye the hole stuff), there is no way to talk/solve it.
I guess I have to experience it myself to understand it better.

I will give it a go now on a very simple project and test on the caanoo to check it out.
If you tried million ways, and being a more advanced coder than me, I will probably fail.
But there is no other way I can understand it better if not trying.

Let´s see, give me a moment.
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
So far I can create the virtual screen with pink circles by drawing sprites, but grabbing and pasting it back does not count that pink as transparent at all.
I wonder if it has anything to do with alphatesting as the example on the manual is supposed to show holes.

It dosen´t on my end, on the online manual, it states it is a v11 feature.

Heck, so I will just download the v11 beta and give it go, I think if the alphatesting works as the example there should be no reason my won´t. :rant:
Title: Re: Mask for background animations
Post by: Wampus on 2013-Feb-07
Erico so happy you got that performance boost. Its such a buzz to be able to add *more* stuff to a game because of that.

Ian, sometimes there just isn't a way for something to work the same on all formats. I have to wonder if giving up on that kind of visual effect for some platforms and looking for an alternative could be a possible way forward.
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
I have done the mask as Ian was trying! :)
Let me give a go on the caanoo now!
Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-07
QuoteIt dosen´t on my end, on the online manual, it states it is a v11 feature.
I suspect that Gernot added it after I brought it up. i haven't downloaded the V11 beta as I need to be able to compile for other platforms - esp Pandora and caanoo. Is this possible in the beta?

QuoteIan, sometimes there just isn't a way for something to work the same on all formats.
I know that. I do already have a work around but it would mean a few level changes for the Caanoo version.

Any luck then erico?
Title: Re: Mask for background animations
Post by: Wampus on 2013-Feb-07
Oh, I know you'd know that technically. I was wondering whether it was something you were strongly attached to is all.
Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-07
It's something I wanted to add and the other version severely limits the dramatic effect, but it still adds challenge to the game. So yeah, one way or another it's staying in some form, but maybe limited. Depends on erico's test. :)
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
As usual, it works out on PC.

I´m facing a few problems on the caanoo though, I´m starting to think it dosen´t support virtual screens.

First I thought we could solve the mask problem by using a 32bit PNG, that way, I can print the pink color on the virtual screen.
As for the overlapping, no problem either.

I have been messing with it the whole afternoon.
My last attempts don´t even deal the pink color, just plain black or white.
I can´t seem to settransparency on that, it is all a mixed up confusion.

I will try again using the pink.

Wors case I upload the code here so you can take a look, maybe it inspires.
I do believe there is a way of doing it by using 32bit PNGs and caanoo can deal that as my game was using it to this point.

On the virtual screen, maybe gernot can share some light on that on the caanoo?

EDIT: alphamode 1 does good on PC too, but I think it dosen´t work on caanoo at all, so I´m trying to achieve without it.
Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-07
You can definitely use a virtual screen on the Caanoo - you've seen the result already in AquaVenture erico. That uses a virtual screen to draw the map on and the creatures etc. are drawn on top and then scaled. There might be limitations on its use though, maybe you can only use one? Dunno.
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
Quote from: Wampus on 2013-Feb-07
Erico so happy you got that performance boost. Its such a buzz to be able to add *more* stuff to a game because of that.

Again, super thanks Wampus, that was really great!

Ian,

Strange, I´m using only one virtual screen, that is to draw a black and white image to be used over the original as a mask.
I think it can be done when using png32bit.

I must rest my mind a bit, will get back to it later, I see no reason why it should not work. :rant:
Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-07
I have to admit that i have not tried 32Bit .PNG, but you have given me an idea...
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-07
I actually made it work without alphamode 1 and without grabsprite.

Now I messed so much the code can´t get back to what it was.
This sure pisses me off.

It was suppose to be a surprise hehe! Imagine if a noob like me could resolve such!
But I´m sure it can be resolved somehow.
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-08
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]
Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-08
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.
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-08
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.
Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-08
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:
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-08
It sure would be nice if we could draw transparencies, as a color.
Title: Re: Mask for background animations
Post by: graffix989 on 2013-Feb-08
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
Title: Re: Mask for background animations
Post by: Ian Price on 2013-Feb-08
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).
Title: Re: Mask for background animations
Post by: graffix989 on 2013-Feb-08
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 :|
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-08
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:
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-09
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]
Title: Re: Mask for background animations
Post by: fuzzy70 on 2013-Feb-09
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]
Title: Re: Mask for background animations
Post by: erico on 2013-Feb-09
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
Title: Re: Mask for background animations
Post by: fuzzy70 on 2013-Feb-09
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
Title: Mask for background animations and transparencies
Post by: Kitty Hello on 2013-Feb-09
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.
Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-09
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. :(
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-09
Quote from: Kitty Hello on 2013-Feb-09
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.

In BlitzBasic/3D by default RGB(0,0,0) is transparent & thus anything you draw (sprites or rects etc) in black is automatically seethru.
here is the code in Blitz3d
Code (glbasic) Select

Graphics 800,600,32,2

hole = LoadImage("hole.bmp")


mask = CreateImage(800,600)
MaskImage mask,255,0,128    ;by default Blitz3D treats black as transparent


SetBuffer ImageBuffer(mask) ;draw directly onto the newly created image to be used as the mask

Color 0,0,0
Rect 0,0,800,600,1 ;fill the image with black
DrawImage hole,100,100 ;draw our hole sprite

SetBuffer BackBuffer() ;go back to our double buffering

While Not KeyHit(1)

Cls

For loop = 0 To 100 ;draw some random background
Color Rand(255),Rnd(255),Rnd(255)
Rect Rand(1,700),Rand(1,500),Rand(1,200),Rand(1,100),1
Next

DrawImage mask,0,0 ;draw our created mask

Flip

Wend


also attached the code & exe.

Lee


[attachment deleted by admin]
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-09
OK I have sussed it, lots of experiments & head scratching I came to the following conclusion.

As we know DRAWRECT works with no problems drawing alpha so here is my solution


BTW the 'hole' sprite has to be transparent in the area you want to see through, could not get it to work using RGB(255,0,128), see the attached  :D

Also if you want to cut more than one item out it has to be done inside the cutshape function for obvious reasons due to it drawing a full size black rect  :D

the code

Code (glbasic) Select

SETCURRENTDIR("Media") // go to media files
LOADFONT "smalfont.bmp",1


GLOBAL sw%,sh%,loop%,starttime,totaltime

LOCAL cx%=10

SETSCREEN 240,320,0

GETSCREENSIZE sw%,sh%

LOADSPRITE "round.png",10

CREATESCREEN 2,1,240,320
CREATESCREEN 3,2,240,320

USESCREEN 2
SEEDRND 10

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

USESCREEN -1

WHILE TRUE

starttime=GETTIMERALL()

DRAWSPRITE 1,0,0

cutshape(cx,0,64,64)

DRAWSPRITE 2,0,0

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

totaltime=1000/(GETTIMERALL()-starttime)
PRINT "FPS="+INTEGER(totaltime),0,300,1
SHOWSCREEN

WEND

FUNCTION cutshape: x%,y%,sprw%,sprh%

USESCREEN 3
SETTRANSPARENCY RGB(255,0,128)
DRAWRECT 0,0,sw,sh,RGB(0,0,0)
DRAWRECT x,y,sprw,sprh,RGB(255,0,128)
DRAWSPRITE 10,x,y
USESCREEN -1

ENDFUNCTION


Lee

edit: using a black sprite the size of the screen maybe quicker than drawing the full screen rect on some devices

edit2: The above works perfectly except if you have more than one sprite that overlaps with another sprite as you then see the corners of it that are not transparent. ARRGGGHHHHH back to the drawingboard  :rant:

[attachment deleted by admin]
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-09
Sorry for the triple post, my bad

I have got round the problem by not using sprites at ALL. Seeing as DRAWRECT works no problem I changed the cutter function to draw circles using a modifying a Midpoint circle algorithm using rects. Its a hell of a lot quicker then the MEM2SPRITE version, has none of the problems associated with the sprite version if things overlap & uses pure integers so no sin/cos performance loss on lower end machines  =D.

I tested it on my pocket pc (xscale 400mhz cpu & no graphics chip that I'm aware of) & got an average of 160fps, compared to 95fps on the sprite version (with it's overlap issues) & 20fps on the MEM2SPRITE version. That was with 2 circles with a 32px radius, hopefully the caanoo etc should have no problems as am pretty sure it is specced better than my ancient pocket pc  :D.

Lee

Code (glbasic) Select
SETCURRENTDIR("Media") // go to media files

GLOBAL sw%,sh%,loop%,starttime,totaltime

LOCAL cx%=10

SETSCREEN 240,320,0

GETSCREENSIZE sw%,sh%


CREATESCREEN 2,1,240,320
CREATESCREEN 3,2,240,320

USESCREEN 2
SEEDRND 10

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

USESCREEN -1

WHILE TRUE

starttime=GETTIMERALL()

DRAWSPRITE 1,0,0

cutshape(cx,100,64)

DRAWSPRITE 2,0,0

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

totaltime=1000/(GETTIMERALL()-starttime)
PRINT "FPS="+INTEGER(totaltime),0,300,1
SHOWSCREEN

WEND

FUNCTION cutshape: cx%,cy%,r%

LOCAL f%, x%, y%, ddx%, ddy%

USESCREEN 3

SETTRANSPARENCY RGB(255,0,128)

DRAWRECT 0,0,sw,sh,RGB(0,0,0)

f% = 1 - r% ; y% = r% ; ddy% = - 2*r%

DRAWRECT cx%-r%,cy%,r%*2,1,RGB(255,0,128)

WHILE x% < y%

IF f% >= 0
          DEC y%,1
          INC ddy%,2
          INC f%,ddy%
        ENDIF

        INC x%,1
        INC ddx%,2
        INC f%,ddx% + 1

        DRAWRECT cx%-x%,cy%+y%,x%*2,1,RGB(255,0,128)
        DRAWRECT cx%-x%,cy%-y%,x%*2,1,RGB(255,0,128)
        DRAWRECT cx%-y%,cy%+x%,y%*2,1,RGB(255,0,128)
        DRAWRECT cx%-y%,cy%-x%,y%*2,1,RGB(255,0,128)

WEND

USESCREEN -1

ENDFUNCTION
Title: Re: Mask for background animations and transparencies
Post by: erico on 2013-Feb-09
I get some error (global definition) on the r%.
Is that normal? I´m using v11.
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-09
Quote from: erico on 2013-Feb-09
I get some error (global definition) on the r%.
Is that normal? I´m using v11.

Just to check I started another project & pasted the code from here & it ran fine  :S

The r% is used only in the cutshape function as a parameter & inside the function so shouldn't get an error (i'm still using 10.283). try replacing all occurrences of r% with something else like cr% for example. Perhaps r% is reserved in v11 beta otherwise no idea  :O

Lee
Title: Re: Mask for background animations and transparencies
Post by: erico on 2013-Feb-09
Ok,

I got both installed, will try v10
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-09
Quote from: erico on 2013-Feb-09
Ok,

I got both installed, will try v10

Changed the code so that no variables that are used in the function are used outside just in case & attached the project

Lee

Code (glbasic) Select

// --------------------------------- //
// Project: cutter2
// Start: Saturday, February 09, 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
SETCURRENTDIR("Media") // go to media files

GLOBAL sw%,sh%,loop%,starttime,totaltime

LOCAL plotx%=10

SETSCREEN 240,320,0

GETSCREENSIZE sw%,sh%


CREATESCREEN 2,1,240,320
CREATESCREEN 3,2,240,320

USESCREEN 2
SEEDRND 10

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

USESCREEN -1

WHILE TRUE

starttime=GETTIMERALL()

DRAWSPRITE 1,0,0

cutshape(plotx,100,64)

DRAWSPRITE 2,0,0

INC plotx,1
IF plotx>sw-64 THEN plotx=10

totaltime=1000/(GETTIMERALL()-starttime)
PRINT "FPS="+INTEGER(totaltime),0,300,1
SHOWSCREEN

WEND

FUNCTION cutshape: cx%,cy%,r%

LOCAL f%, x%, y%, ddx%, ddy%

USESCREEN 3

SETTRANSPARENCY RGB(255,0,128)

DRAWRECT 0,0,sw,sh,RGB(0,0,0)

f% = 1 - r% ; y% = r% ; ddy% = - 2*r%

DRAWRECT cx%-r%,cy%,r%*2,1,RGB(255,0,128)

WHILE x% < y%

IF f% >= 0
          DEC y%,1
          INC ddy%,2
          INC f%,ddy%
        ENDIF

        INC x%,1
        INC ddx%,2
        INC f%,ddx% + 1

        DRAWRECT cx%-x%,cy%+y%,x%*2,1,RGB(255,0,128)
        DRAWRECT cx%-x%,cy%-y%,x%*2,1,RGB(255,0,128)
        DRAWRECT cx%-y%,cy%+x%,y%*2,1,RGB(255,0,128)
        DRAWRECT cx%-y%,cy%-x%,y%*2,1,RGB(255,0,128)

WEND

USESCREEN -1

ENDFUNCTION


[attachment deleted by admin]
Title: Re: Mask for background animations and transparencies
Post by: erico on 2013-Feb-09
Worked with V10 of GLB.
Tried on Caanoo, works like a charm, can this be used, let´s say to have multiple balls?

I first thought of drawing a black virtual screen (sprite or rec) and then draw the multiple balls on a very low res, like those uploaded some pages ago. Balls made of a set of rectangles, considering the speed of drawrect, it could be even a set of horizontal blocks, or a combination of bigger and smaller ones to reduce drawrec calls. I would not be a pixel perfect circle, more a blown up pixelated one. ;)

You function is really cool, very little amount of code going there.
I have to study it a bit. Fear for functions creeps in :-[

Thanks a lot for a solution fuzzy70!

I hope this all can help Ian too.

EDIT: ps. those marks on the right of my screen protection is all your fault Ian! (Drench!)

EDIT2: sorry to ask, how can I change the diameter of the ball?

[attachment deleted by admin]
Title: Re: Mask for background animations and transparencies
Post by: kanonet on 2013-Feb-09
Interestingly this does not work for me, I only see a black screen (with fps counter). Looks like i can not set the transparency colour with DRAWRECT.
Using V11 on an integrated intel graphic card.
Title: Re: Mask for background animations and transparencies
Post by: erico on 2013-Feb-10
I will try the last version on v11  to check...
On version 11 of GLB I get the black screen too. GTX460.

...works fine on v10 O_O
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-10
here's a hack that draws 5 circles

to change the size of the ball erico just call the cutshape from the 1st example with the radius you want, the last parameter is the one.

Code (glbasic) Select
cutshape(x position,y position ,radius)

better still play with the one below  :D

Lee

Code (glbasic) Select
// --------------------------------- //
// Project: cutter2
// Start: Saturday, February 09, 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

TYPE Tcircles
x%
y%
radius%
ENDTYPE

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

GLOBAL sw%,sh%,loop%,starttime,totaltime
GLOBAL circles[] AS Tcircles

LOCAL plotx%=10

SETSCREEN 240,320,0

GETSCREENSIZE sw%,sh%


CREATESCREEN 2,1,240,320
CREATESCREEN 3,2,240,320

DIM circles[5]

FOR loop=0 TO 4
circles[loop].x=RND(sw)
circles[loop].y=RND(sh)
circles[loop].radius=RND(32)+16
NEXT



WHILE TRUE

starttime=GETTIMERALL()

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


DRAWSPRITE 1,0,0

FOR loop%=0 TO 1
INC circles[loop%].x,RND(2)-1
INC circles[loop%].y,RND(2)-1

IF circles[loop].x=sw OR circles[loop].x=0 THEN circles[loop].x=RND(sw)
IF circles[loop].y=sh OR circles[loop].y=0 THEN circles[loop].y=RND(sh)
NEXT
cutshape()

DRAWSPRITE 2,0,0

INC plotx,1
IF plotx>sw-64 THEN plotx=10

totaltime=1000/(GETTIMERALL()-starttime)
PRINT "FPS="+INTEGER(totaltime),0,300,1
SHOWSCREEN

WEND

FUNCTION cutshape:

LOCAL lo%

USESCREEN 3

SETTRANSPARENCY RGB(255,0,128)

DRAWRECT 0,0,sw,sh,RGB(0,0,0)

FOR lo%=0 TO 4

drawcircle(circles[lo%].x,circles[lo%].y,circles[lo%].radius)

NEXT

USESCREEN -1

ENDFUNCTION

FUNCTION drawcircle: cx%,cy%,r%

LOCAL f%, x%, y%, ddx%, ddy%

f% = 1 - r% ; y% = r% ; ddy% = - 2*r%

DRAWRECT cx%-r%,cy%,r%*2,1,RGB(255,0,128)

WHILE x% < y%

IF f% >= 0
          DEC y%,1
          INC ddy%,2
          INC f%,ddy%
        ENDIF

        INC x%,1
        INC ddx%,2
        INC f%,ddx% + 1

        DRAWRECT cx%-x%,cy%+y%,x%*2,1,RGB(255,0,128)
        DRAWRECT cx%-x%,cy%-y%,x%*2,1,RGB(255,0,128)
        DRAWRECT cx%-y%,cy%+x%,y%*2,1,RGB(255,0,128)
        DRAWRECT cx%-y%,cy%-x%,y%*2,1,RGB(255,0,128)

WEND
ENDFUNCTION


There does seem to be an issue with V11 by the look of things  :O

Looking forward to Ians response to see if he gets any improvement out of this :)

Lee
Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-10
Cheers Lee. :)

I haven't tested any of these yet as I've not long got home form work. It looks as though you've finally put this to bed though. I'll have a play tomorrow now. I'm using V10, so whatever the problem may be with v11 it shouldn't affect me :)
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-10
Quote from: Ian Price on 2013-Feb-10
Cheers Lee. :)

I haven't tested any of these yet as I've not long got home form work. It looks as though you've finally put this to bed though. I'll have a play tomorrow now. I'm using V10, so whatever the problem may be with v11 it shouldn't affect me :)

No problems Ian, just feel sorry for Gernot as not only is he looking for how to draw other items with transparency it appears I have uncovered something thats changed in V11  :'(

Btw just done the above test on my pocket pc & got 70fps with the 5 random balls & drawing the 100 coloured rects in the background randomly each frame. Hardly game logic I know but pushes my little pocket pc harder than my previous example  =D

Lee
Title: Re: Mask for background animations and transparencies
Post by: erico on 2013-Feb-10
Tried the latest on GLB V10:

works fine on PC.
works fine on caanoo.

With GLB V11:

black on PC.
black with pink balls on caanoo. :O

Strange, I hope it helps Gernot on the reason for this.

EDIT: This might be the reason I could not make it work back again on my sprite attempts beguinning of this thread after I changed to V11. I´m sure I did something cool but was not able to come back to it. At that point though, I was using a worse self method, with alphamode 1, which is killer on caanoo and while it worked on PC, none worked on caanoo. I hope, for Gernot´s sake, that I was allucinating...but I´m pretty sure of it. Now I wish I had saved versions, specially those that worked on PC on V10 :(
Have to learn to save versions the hard way.
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-10
Quote from: erico on 2013-Feb-10
Tried the latest on GLB V10:

works fine on PC.
works fine on caanoo.

With GLB V11:

black on PC.
black with pink balls on caanoo. :O

Strange, I hope it helps Gernot on the reason for this.

Hmmm, either something has changed in V11 in the way DRAWRECT works or SETTRANSPARENCY is broken.

I cannot think of another way to do the routine, my circle routine is about as optimised as it can be I think(no trig & pure integer math) & so far it seems DRAWRECT is the only command currently that works with SETTRANSPARENCY. I have not tried SETPIXEL as I know that is slow & I would not gain any speed boost at all using it.

Lee
Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-10
Really sorry, but I've still not tried this yet - been working on an animated intro for AquaVenture. It's pretty simple, but it's taken a lot longer than I expected.
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-10
Quote from: Ian Price on 2013-Feb-10
Really sorry, but I've still not tried this yet - been working on an animated intro for AquaVenture. It's pretty simple, but it's taken a lot longer than I expected.

No rush Ian. 1st I enjoyed the challenge & 2nd bought up an issue that would be great to get sorted  =D

Lee
Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-11
Hi Lee

Just had a look at your code and it's doing what I said in this thread - http://www.glbasic.com/forum/index.php?topic=8906.msg75910#msg75910

QuoteThere is no way to draw a pink (255,0,128) circle onto the black screen unless you build it up out of rectangles.

And...

QuoteYou can use DRAWRECT but that requires multipls squares to draw a circle

So, it's the same solution that I came up with originally.  :D
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-11
Sorry Ian I must have misread it as you just needed to make holes that showed whatever underneath while blanking the rest of the screen.

Do you use the same circle routine as mine as I'm sure I saw something about sin/cos which mine does not use (then again that could have been a different topic  :D)

Well even if I/We have failed to reach the required goal at least it has thrown an issue up that should hopefully get resolved  ;)

Lee
Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-11
I came up with two routines - the one with SIN and COS was for the POLYVECTOR solution, not the DRAWRECT one (which doesn't use SIN or COS).

My DRAWRECT solution was pretty much the same - just use several rects to draw pink circles onto the black background.

The POLYVECTOR solution used the background screen as a texture and used SIN & COS to draw circles directly onto the screen.
Title: Re: Mask for background animations and transparencies
Post by: fuzzy70 on 2013-Feb-11
Some form of direct buffer access (while locked) would be nice & could do it with no problems, mem2sprite & sprite2mem are a step in the right direction but suffer a performance hit when they are called.

Ideally of course anything that is drawn be it a rect, sprite or whatever should take into account the transparency  colour.

Lee
Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-11
QuoteIdeally of course anything that is drawn be it a rect, sprite or whatever should take into account the transparency  colour.
That's pretty much exactly what I said last year. :(
Title: Mask for background animations and transparencies
Post by: Kitty Hello on 2013-Feb-11
In v11 play with alphamode -1 od/or alphatesting values.
Title: Re: Mask for background animations and transparencies
Post by: erico on 2013-Feb-11
Quote from: Kitty Hello on 2013-Feb-11
In v11 play with alphamode -1 od/or alphatesting values.

I did try some of it on my tests Kitty, but could not achieve the desirable results.
I´m away from home (carnaval in brasil!! :D) so can´t give an update on my tries.

I will look into it when I get back home.
Title: Re: Mask for background animations and transparencies
Post by: erico on 2013-Feb-11
and then...a double post! ;/

Did any of the solutions here helped the caanoo port Ian?
What about the blocky ball´s idea?

Maybe a mix of everything can do?

Cheers!
Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-11
QuoteDid any of the solutions here helped the caanoo port Ian?
No. The speed is still too slow and, as stated, my own methods produced better results. I could probably optimise the code and make it more Caanoo specific, rather than for all devices and it might work then, but I don't think I have time now.  The Pandora is my main focus, but I will continue to work on all versions.

There is one way I can make the Caanoo faster, but that would require the game to be played without scaling. I might try that tomorrow.
Title: Re: Mask for background animations and transparencies
Post by: erico on 2013-Feb-12
So scalling is the more taxing issue?

zooming 320x240 polyvectors or same size zoomsprite hooged on caanoo on my old tests.
I did get a bit better speed by using smaller bits though.

Good luck. :good:
Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-12
Well, I've now got it working at a playable <>45FPS on the Caanoo whether it's light or dark and scaled to fill the screen :D

I've had to sacrifice the water effect in the background, but I can live with that. The only issue I have now is it now crashes after the end of a level, but that shouldn't take too long to identify and sort out.

Need to try the same code on the Pandora to ensure that what I've fixed on one machine doesn't bugger up the other!
Title: Mask for background animations and transparencies
Post by: Kitty Hello on 2013-Feb-12
You want a super mario n64 screen fadeout with a circle?
Would be worth a try to draw the black part using polyvectors. It's a bit of a math, but if you draw an outer and an inner circle, its easier. Know what I mean?
Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-12
No Gernot. Did you look at the video I attached in this post? - http://www.glbasic.com/forum/index.php?topic=8906.msg75906#msg75906    [EDIT] Post #12 - the forum isn't showing the actual post ???

I've already got the halos showing in-game on pc, Pandora and Caanoo. I worked out two routines - one with DRAWRECTs on a black background, the other by using the actual graphic background as a texture in POLYVECTORS. While both worked well, the Pandora and Caanoo both suffered speed loss as a result of using both methods. Just being able to plonk a pink (255,0,128) sprite onto a black background and have the image behind show through would reduce some speed loss.

However, I've now optimised things to a level where the game is comfortably playable on a Caanoo now. The Pandora hasn't improved significantly just a few FPS, but it was always playable anyway.
Title: Re: Mask for background animations and transparencies
Post by: Kitty Hello on 2013-Feb-13
now I see. We need something like stencil buffers then.
That's pretty complex for caanoo to program. But I add it to the list.
Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-13
I wouldn't worry about it Gernot. We now have a couple of ways of achieving this effect and there's only a couple of us here that develop for the Caanoo anyway. iOS and Android systems are far more powerful so they probably don't need anything better than what we have now. But if you want the challenge... :)
Title: Re: Mask for background animations and transparencies
Post by: erico on 2013-Feb-13
But I kind of think it is important to be able to draw transparent, with polyvectors or drawsprite. ::) on all platforms
If the caanoo´s part gets to be a bit taxing(let´s say like rotozoomsprite), it is fine.

Such way of drawing is quite similar to how photoshop or standard drawing programs go about.
It is (IMHO) what would be expected for a new user coming around GLB first time.

For this last reason I take it to be quite important.
I hope it won´t cause too much trouble to implement.

Thanks a lot for looking into it! :good:
Title: Re: Mask for background animations and transparencies
Post by: doimus on 2013-Feb-16
Quote from: Kitty Hello on 2013-Feb-13
now I see. We need something like stencil buffers then.
That's pretty complex for caanoo to program. But I add it to the list.

Yes, please!!  :good:

Ability to POLYVECTOR draw with transparency would be awesome!
Even more awesome would be the usage of alpha-masks.
As Erico said, just as Layer Mask in photoshop: 256-level grayscale image which determines the alpha value of another image(sprite).

Title: Re: Mask for background animations and transparencies
Post by: Ian Price on 2013-Feb-16
That's what I wanted too (I requested this last year) - just to be able to draw with transparency onto a virtual image (with sprites or POLYs, I don;t mind). Stencil buffers are a tad different - http://en.wikipedia.org/wiki/Stencil_buffer
Title: Re: Mask for background animations and transparencies
Post by: erico on 2013-Feb-16
I think these 2 may fit the spot better:

http://en.wikipedia.org/wiki/Mask_(computing)#Image_masks
^ The OR operation is the one discussed on this thread I guess.

---

http://en.wikipedia.org/wiki/Alpha_compositing
^ Maybe a tweek on the current alpha blending stuff could do the thing too?