Hi!
The simplest way to get animated textures. Just load avi file of any size or length using Load_Movie, then start it by Start_Movie, and use Update_Movie in main loop.
If your avi, wmv (you can use DivX, mpeg4 etc. as well) has for example ressolution of 640x480 and your texture/image/frontbuffer has the ressolution of 256x128 just set XSize and YSize parameter to 256,128 when loading movie.
XSize and YSize are optional parameter - don't fill them if movie has the same ressolution as image/texture buffer - it will work a bit faster.
I think that's all.
Include file:
And example (change "ktech.avi"!)
Have Fun!!!
The simplest way to get animated textures. Just load avi file of any size or length using Load_Movie, then start it by Start_Movie, and use Update_Movie in main loop.
If your avi, wmv (you can use DivX, mpeg4 etc. as well) has for example ressolution of 640x480 and your texture/image/frontbuffer has the ressolution of 256x128 just set XSize and YSize parameter to 256,128 when loading movie.
XSize and YSize are optional parameter - don't fill them if movie has the same ressolution as image/texture buffer - it will work a bit faster.
I think that's all.
Include file:
;########################################################### ;############### kTecH Movies ################ ;########################################################### Type TMovieStorage Field Movie Field DestBuffer Field File$ Field XSize Field YSize Field Play End Type Function Load_Movie.TMovieStorage(File$, Buffer, XSize=0, YSize=0) MovieStorage.TMovieStorage = New TMovieStorage MovieStorage\DestBuffer = Buffer MovieStorage\File = File$ MovieStorage\XSize = XSize MovieStorage\YSize = YSize MovieStorage\Play = False Return MovieStorage.TMovieStorage End Function ;######################################## ;### This Function uses BackBuffer!!! ### ;######################################## Function Update_Movies() For MovieStorage.TMovieStorage = Each TMovieStorage If MovieStorage\Play Then If MovieStorage\XSize=0 Then DrawMovie MovieStorage\Movie CopyRect 0, 0, MovieWidth(MovieStorage\Movie), MovieHeight(MovieStorage\Movie), 0,0, BackBuffer(), MovieStorage\DestBuffer Else DrawMovie MovieStorage\Movie, 0,0, MovieStorage\XSize, MovieStorage\YSize CopyRect 0, 0, MovieStorage\XSize, MovieStorage\YSize, 0,0, BackBuffer(), MovieStorage\DestBuffer End If If MoviePlaying(MovieStorage\Movie) = False Then CloseMovie (MovieStorage\Movie) MovieStorage\Movie = OpenMovie (MovieStorage\File$) End If End If Next End Function Function Stop_Movie (MovieStorage.TMovieStorage) CloseMovie(MovieStorage\Movie) MovieStorage\Play = False End Function Function Start_Movie (MovieStorage.TMovieStorage) MovieStorage\Movie = OpenMovie (MovieStorage\File$) MovieStorage\Play = True End Function Function Free_Movie (MovieStorage.TMovieStorage) CloseMovie (MovieStorage\Movie) Delete MovieStorage End Function Function Free_Movies() For MovieStorage.TMovieStorage = Each TMovieStorage CloseMovie (MovieStorage\Movie) Delete MovieStorage Next End Function
And example (change "ktech.avi"!)
Include "kTecH Movies.bb" Graphics3D 800,600,16 ,2 SetBuffer BackBuffer() Tekstura = CreateTexture (512,256) ;--------------------------------------- ; Remember that movie is stopped on load ;--------------------------------------- MyMovie.TMovieStorage = Load_Movie ("ktech.avi", TextureBuffer(Tekstura),512,256) ;--------------------------------------- Cube = CreateCube() EntityTexture Cube, Tekstura EntityFX Cube, 1 Camera = CreateCamera() PositionEntity Camera, -5,0,0 PointEntity Camera, Cube ;--------------------------------------- ; Startig Movie (it's stopped on load) ;--------------------------------------- Start_Movie(MyMovie) ;--------------------------------------- Global fps_milli=MilliSecs() Global fps_counter=0 Global update_frequency=10 While Not KeyHit(1) fps_counter=fps_counter+1 If fps_counter=update_frequency fps=1000/Float(((MilliSecs()-fps_milli))/update_frequency) fps_milli=MilliSecs() fps_counter=0 EndIf ;----------------------------------------------------- ; Update_Movie (you don't have to call it each frame - it keeps timing ;----------------------------------------------------- Update_Movies() ;----------------------------------------------------- TurnEntity Cube, 1,1,1 RenderWorld Text 520,20,"FPS:"+fps Flip Wend ;----------------------------------------------------- ; Release ;----------------------------------------------------- Free_Movies()
Have Fun!!!