News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Saving Frame Sets (Making Videos)

Started by kevin, August 31, 2012, 09:54:01 AM

Previous topic - Next topic

kevin

 Saving Frame Sets (Making Videos)

  This is a variation of the little frame work that i use when knocking up the 'thread' video for code snippets.    The only difference is that this version is set out to be project where you drop your 'effect' code into.   Where I'd normally cut/n/paste the functions into the project I want to capture.   Either way, same result.  

  The aim of this source code is save a group of sequentially names bitmap files to a folder on your  computer.   To build a video I use Virtual Dub.   To do this,  load up Virtual Dub, then simply drag the one of the bitmap files onto the VirtualDub video area and it'll work out that want to make movie from the files.     The only thing you'll have to do is set the output frame rate and compression codec.


PlayBASIC Code: [Select]
   #include "freeimage"

constant MaxSaveFrames =360
Constant SAveFolder$ ="E:\Anim_Frames\"

Screen = NewIMage(800,600,2)


Do

; ------------------------------------
; Draw the Effect you want to record
; ------------------------------------
Render_Effect(Screen)


; ------------------------------------
; Draw the standard "cheesy" overlays of the PB demos
; ------------------------------------
Render_Messages_And_Screen(Screen,"Demo Of Saving Frame Sets")


; -------------------------------------------------
; Save Frames
; -------------------------------------------------
if SaveMode=true
file$="Frame"+Digits$(CurrentFrame,4)+".bmp"
FreeImage_SaveBMP(SAveFolder$+File$,Screen)
CurrentFrame++
if CurrentFrame>MaxSaveFrames then savemode=false
text 20,20,"Saving:"+Str$(CurrentFrame)+" of "+Str$(MaxSaveFrames)
else
if spacekey()
Savemode=true
CurrentFrame=0
endif
endif


Sync
loop



Psub Render_Effect(Screen)
rendertoimage Screen


; clear the
cls $203040

cx=GetSurfaceWidth()/2
cy=GetSurfaceHeight()/2

For lp =0 to 18

Angle#=BaseAngle#+(lp*5)

x2=cx+cos(Angle#)*300
y2=cy+Sin(Angle#)*200

Line cx,cx,x2,y2

next

Baseangle#=wrapangle(BaseAngle#+1)


EndPsub



Function Render_Messages_And_Screen(Screen,MessageTop$,MEssageBottom$="www.PlayBASIC.com")

ShadedText(Screen,GetScreenWidth()/2,10,MessageTop$)
ShadedText(Screen,GetScreenWidth()/2,GetSCreenHeight()-70,MessageBottom$)

rendertoscreen
drawimage screen,0,0,false

EndFunction



Function ShadedText(Screen,Xpos,Ypos,Message$,CenterX=true)
CurrentSurface=getSurface()

rendertoimage screen

screenwidth =GetSurfaceWidth()
screenHeight=GetSurfaceHeight()

if GetFontStatus(2)=false
LoadFont "verdana",2,56,1,8
FontDrawmode 2,1
setfont 2
endif

if CenterX=true
Xpos-=GetTextWidth(Message$)/2
endif

setfont 2
ThisRGB=rgb(50,50,50)

Level=$90
for lp =0 to 2

ink rgbfade(ThisRgB,40) or Argb(level,0,0,0)
text Xpos,Ypos,Message$
Level+=$8
Xpos+=2
Ypos+=1
next

Rgb1=rgb(20,70,170)
Rgb2=rgb(220,230,230)

Rows=GetTextHeight("|")
For lp =0 to Rows
scaler#=float(lp)/Rows
ThisRGB=RgbAlphaBlend(Rgb1,RGB2,Scaler#*100) and $00ffffff
ink $f0000000 or ThisRGB
Ypos2=Ypos+lp
imageviewport Screen,0,ypos2,800,ypos2+1
text Xpos,Ypos,Message$
next

imageviewport Screen,0,0,screenWidth,ScreenHeight

rendertoimage oldSurface


endFunction





  Here's a video of what the demo renders.  





More Example Videos

   Most of the videos in the source and tutorials are made like this,  

   eg
    * Parallax Mountain Range In Triangles
    * Sliding Collision Around A Track
    * Vertical Sprite Depth Ordering

     etc