Main Menu

Alpha tests

Started by stef, February 20, 2007, 05:50:01 PM

Previous topic - Next topic

stef

Hi!

That's just an experimental speedtest (with different particle-sizes and particle-numbers)

First code:
(needs PB 1.65 or higher)
3Dimages, alphablended

Second code:
VIimages

results with PB1.65 (laptop, P4) 800x600, 32Bit

First code (3D):

Maxparticles        Particlesize      FPS

100                       24               190
                            48               170

500                       24                51
                            48                45

1000                      24                27
                            48                23


Second code (VI):

Maxparticles        Particlesize      FPS

100                       24               270
                            48               220

500                       24                83
                            48                56

1000                      24                46
                            48                32

OpenScreen 800,600,32,2


Global maxparticles=100
Global particlesize=24


Global halfparticlesize=particlesize/2

Dim im(maxparticles)
Dim x#(maxparticles)
Dim y#(maxparticles)
Dim dx#(maxparticles)
Dim dy#(maxparticles)
Dim angle#(maxparticles)
Dim speed#(maxparticles)
Dim alpha#(maxparticles)
Dim alphaangle#(maxparticles)



initparticles()

Do
RenderToScreen
Cls 0
Print FPS()
Print MaxParticles

calcparticles()

Loop



Function initparticles()

For x= 0 To maxparticles

im(x)=GetFreeImage()
Create3DImage im(x),particlesize,particlesize
RenderToImage im(x)
CircleC halfparticlesize,halfparticlesize,halfparticlesize,1,RndRGB()


x#(x)=400
y#(x)=300
angle#(x)=Rnd(359)
speed#(x)=RndRange#(0.2,3)
dx#(x)=Cos(angle#(x))*speed#(x)
dy#(x)=Sin(angle#(x))*speed#(x)
alphaangle#(x)=2*Rnd(179)
alpha#(x)=0.5+Sin(rnd(alphaangle#(x)))*0.5


Next

EndFunction



Function calcparticles()


RenderToScreen

For x= 0 To maxparticles

DrawAlphaImage im(x),x#(x)-halfparticlesize,y#(x)-halfparticlesize,alpha#(x),1

x#(x)=x#(x)+dx#(x)
y#(x)=y#(x)+dy#(x)

alphaangle#(x)=alphaangle#(x)+2
if alphaangle#(x)>359 then alphaangle#(x)=0
alpha#(x)=0.5+sin(alphaangle#(x))*0.5

If x#(x)<halfparticlesize Or x#(x)>800-halfparticlesize Then dx#(x)=-dx#(x)
If y#(x)<halfparticlesize Or y#(x)>600-halfparticlesize Then dy#(x)=-dy#(x)

Next

Sync


EndFunction





OpenScreen 800,600,32,2


Global maxparticles=100
Global particlesize=24


Global halfparticlesize=particlesize/2

Dim im(maxparticles)
Dim x#(maxparticles)
Dim y#(maxparticles)
Dim dx#(maxparticles)
Dim dy#(maxparticles)
Dim angle#(maxparticles)
Dim speed#(maxparticles)



initparticles()

Do
RenderToScreen
Cls 0
Print FPS()
Print MaxParticles

calcparticles()

Loop


Function initparticles()

For x= 0 To maxparticles

im(x)=GetFreeImage()
CreateImage im(x),particlesize,particlesize
RenderToImage im(x)
CircleC halfparticlesize,halfparticlesize,halfparticlesize,1,RndRGB()


x#(x)=400
y#(x)=300
angle#(x)=Rnd(360)
speed#(x)=RndRange#(0.2,3)
dx#(x)=Cos(angle#(x))*speed#(x)
dy#(x)=Sin(angle#(x))*speed#(x)


Next

EndFunction



Function calcparticles()


RenderToScreen

//LockBuffer

For x= 0 To maxparticles


DrawImage im(x),x#(x)-halfparticlesize,y#(x)-halfparticlesize,1

x#(x)=x#(x)+dx#(x)
y#(x)=y#(x)+dy#(x)

If x#(x)<halfparticlesize Or x#(x)>800-halfparticlesize Then dx#(x)=-dx#(x)
If y#(x)<halfparticlesize Or y#(x)>600-halfparticlesize Then dy#(x)=-dy#(x)

Next

//UnLockBuffer

Sync



EndFunction










stef

#1
Hi!

another test :)

realtime rotation,realtime scaling,realtime alphablending :)
of a 800x600 image (scaling is from 0.5 (50%) to 3.0 (300%))

result: not bad! :) (got average FPS 150 with cls, FPS 200 without cls on my old laptop)

spacekey toggles cls
needs PB 1.65 or above



SCREENW=800
SCREENH=600



openscreen SCREENW,SCREENH,32,2
;setfps 60

scal#=1.5
scalfac#=1


im=getfreeimage()
create3dimage im,SCREENW,SCREENH
rendertoimage im
cls rgb(255,255,255)

for x= 0 to SCREENW-50 step 100
for y= 0 to SCREENH-50 step 100
boxc x,y,x+50,y+50,1,rgb(10,10,10)
boxc x+50,y+50,x+100,y+100,1,rgb(10,10,10)
next
next


sp=getfreesprite()
createsprite sp
spriteimage sp,im
spritedrawmode sp,2+4
autocenterspritehandle sp,true


do
rendertoscreen

if spacekey() then clear=1-clear
flushkeys
if clear=0 then cls rgb(0,0,100)

             ;drawimage im,0,0,1

rotatesprite sp,-ang
scalesprite sp, scal#
positionsprite sp, SCREENW/2,SCREENH/2
SpriteAlphaLevel sp, Alpha#
drawsprite sp

inc ang
if ang=360 then ang=0

scal#=scal#-(0.01*scalfac#)
if scal#<0.5 or scal#>3.0 then scalfac#=scalfac#*-1

alphaangle#=alphaangle#+1
If alphaangle#>359 Then alphaangle#=0
alpha#=0.5+Sin(alphaangle#)*0.5


text 0,0, str$( fps())
sync
if esckey()=true then end
loop