Code archives/3D Graphics - Misc/3d movie playback
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
| I recommend you use animstrips instead of avi files due to the limitations playing movies brings. This example is suited to the beginner wanting to try cool 3D effects. The 168k zip file includes a movie to test with. Grab it from here: http://www.redsoft.pwp.blueyonder.co.uk/files/movie3d.zip | |||||
. |
Comments
| ||
| broken link |
| ||
| since it's pubic domain, is there anybody who's got movie3d.zip on their hardrive? Please repost, even if it's only the source without media. thanks. Meanwhile, use this: ; playing a movie in a texture Graphics3D 640,480,32,2 SetBuffer BackBuffer() camera=CreateCamera() TranslateEntity camera,0,0,-4 light=CreateLight() RotateEntity light, 45,45,0 cube=CreateCube() tex=CreateTexture(256,256,256) EntityTexture cube,tex movie_file$="test.avi" movie=OpenMovie(movie_file$) While KeyDown(1)=0 dummy=DrawMovie(movie,0,0,256,256) ; here you can scale the movie to the texture size most efficiently CopyRect 0,0,256,256,0,0,BackBuffer(),TextureBuffer(tex) If MoviePlaying(movie)=0 Then CloseMovie movie movie=OpenMovie(movie_file$) ; reload when finished = loop EndIf TurnEntity cube,.2,.4,.6 RenderWorld() Flip Wend CloseMovie movie End |
| ||
; Simple movie on 3D Object example (rob@...)
; sample avi was a simple quicktime trailer preview converted.
; for best results and efficient memory usage please use power of two sizes.
; ie. 256x256
Graphics3D 640,480,16,2
camera=CreateCamera()
light=CreateLight()
;create texture for the movie & 3d entity
movietex = CreateTexture(256,256,256+48)
cube = CreateCube()
EntityTexture cube,movietex
MoveEntity cube,0,0,6
EntityFX cube,16
EntityBlend cube,3
For i=0 To 3
temp=CopyEntity(cube,cube)
PositionEntity temp,Rnd(-10,10),Rnd(-10,10),Rnd(-10,10)
Next
;load movie
movie = OpenMovie("sample.avi")
While Not KeyHit(1)
; this is just a delay before updating movie
If t>2
t=0
If MoviePlaying(movie)=0 Then movie = OpenMovie("sample.avi")
DrawMovie(movie)
CopyRect 0,0,256,128,0,0,BackBuffer(),TextureBuffer(movietex)
EndIf
t=t+1
TurnEntity cube,-.4,.4,0
RenderWorld
Flip
Wend
End |
| ||
Thanks Puki. Note:
If MoviePlaying(movie)=0 Then movie = OpenMovie("sample.avi")
is likely to cause a memory leak, so it should be:
If MoviePlaying(movie)=0 Then
closemovie movie
movie = OpenMovie("sample.avi")
endif
I even recall when you end the program with an opened movie then this may result in some kind of error - at least on some OSes. In the first version of the directShow implementation this didn't happen, but after the compiler bugfix for a general movie memory leak, closing all movies became mandatory. |
| ||
| I still prefer this method: Set up the texture on the model:- movietex = CreateTexture(256, 256 * Float(MovieHeight(hmovie)) / Float(hmovie)) ) EntityTexture_(Model,movietex) Play directly on to that texture:- SetBuffer TextureBuffer(movietex) DrawMovie(hmovie,0,0,MovieWidth(hmovie),MovieHeight(hmovie)) SetBuffer BackBuffer() |
| ||
| Hah - I knew I had it somewhere. Playing a movie onto an object without CopyRect(). Isn't that strange - other than that, Puki's code looks very like mine.
Graphics3D 800,600,32,2
SetBuffer BackBuffer()
font=LoadFont("arial",20) : SetFont font
camera=CreateCamera() : light=CreateLight()
cube = CreateCube() : MoveEntity cube,0,0,3 : ScaleEntity cube,1,0.5,1
movietex = CreateTexture(256,128) : EntityTexture cube,movietex
movie$ = "sample.avi" ; <- your movie here ; any AVI or MPG
hmovie = OpenMovie(movie$)
framePeriod = 1000/30 : frametimer = CreateTimer(framePeriod)
While Not KeyHit(1)
WaitTimer frametimer
If t>5
t=0
If Not MoviePlaying(hmovie)
CloseMovie(hmovie)
hmovie = OpenMovie(movie$)
frame = 0
Else
SetBuffer TextureBuffer(movietex)
DrawMovie(hmovie)
frame = frame + 1 : Color 255,255,255 : Text 0,0,"Frame "+frame
SetBuffer BackBuffer()
EndIf
EndIf
t=t+1
TurnEntity cube,0,.4,0
UpdateWorld() : RenderWorld()
Text 0,0,"AvailVidMem() "+AvailVidMem()
Flip()
Wend
End
|
| ||
| The version from jfk EO-11110 seems like a solid flexible implementation. John Blackledge's example about playing direct on texture doesn't work on my system. Also, playing AVIs don't work at all on all these examples, neither does vob files from DVDs, only MPG, MPEG or WMVs play ok here. |
Code Archives Forum