Hi,
All is working on the laptop, very cool!
For the EndGraphics thingie, you can use clearworld as well. Like this:
; Render to Texture Demo #3
;
; How to handle resetting the Graphics3D system (ClearWorld)
Graphics3D 1024,768,32,2
;Jump back to here when user hits SPACE
.NewScene
; Clear all entities and textures and brushes
ClearWorld True,True,True
;If using this DLL, *always* call this function before calling EndGraphics()
;This is needed because the variables returned from SystemProperty$() change
;each time Graphics3D is called!
RemoveSystemProperties()
;Must let the DLL know a few things about Blitz3D!
d3d=SystemProperty$("Direct3D7")
dev7=SystemProperty$("Direct3DDevice7")
draw7=SystemProperty$("DirectDraw7")
hwnd=SystemProperty$("AppHWND")
instance=SystemProperty$("AppHINSTANCE")
If SetSystemProperties(d3d,dev7,draw7,hwnd,instance) RuntimeError "Error setting 1 or more System Propertys!"
;Does hardware support Renderable Textures?
If Not SupportsRenderTexture() RuntimeError "Ho hardware support for Renderable Textures"
; Camera.. Light(s).. Action!
cam=CreateCamera()
PositionEntity cam,0,2,-7
CameraRange cam,.5,100
CameraClsColor cam,100,120,200
light=CreateLight()
TurnEntity light,-50,0,0
;---------------------------
;Create a Renderable Texture
;---------------------------
;Let the DLL know the *NEXT* texture being created should be one
;we can use as a Render Target
UserRenderTexture
;Create a Renderable Texture, MUST HAVE +256 in flags (256 = Local Vid Mem)
;Texture Size must be ^2 (128,256,512 e.t.c), it doesn't *have* to be the same
;size as the Graphics Viewport though!
texSize=512
tex=CreateTexture(texSize,texSize,256+1)
;By default, a Render Texture is created without a Z-Buffer, but you can add one using..
AddZBuffer tex
;This cube will use the Render Texture
cube=CreateCube()
EntityTexture cube,tex
sky=CreateSphere(32)
FlipMesh sky
EntityColor sky,130,180,220
ScaleEntity sky,50,50,50
; Sexeh checkered ground!
ground=CreateCube()
ScaleEntity ground,50,.1,50
EntityFX ground,1
groundTex=CreateTexture(512,512,1+8)
ScaleTexture groundtex,.1,.1
;ScaleTexture groundTex,.025,.025
SetBuffer TextureBuffer(groundtex)
Color 140,25,0
Rect 0,0,255,255,True
Rect 256,256,255,255
Color 200,160,0
Rect 256,0,255,255,True
Rect 0,256,255,255,True
SetBuffer BackBuffer()
EntityTexture ground,groundTex
PositionEntity ground,0,-1.5,0
Color 0,0,0
fps=0
counter=0
timer=MilliSecs()
MoveMouse GraphicsWidth()*.5,GraphicsHeight()*.5
While Not KeyDown(1)
t=MilliSecs()
If KeyHit(2)
texSize=texSize/2
If texSize<4 Then texSize = 4
FreeTexture tex
UserRenderTexture
tex=CreateTexture(texSize,texSize,256+1)
AddZBuffer tex
EntityTexture cube,tex
Else If KeyHit(3)
texSize=texSize*2
If texSize>2048 Then texSize = 2048
FreeTexture tex
userRenderTexture
tex=CreateTexture(texSize,texSize,256+1)
AddZBuffer tex
EntityTexture cube,tex
End If
If MouseDown(2) TurnEntity cube,0,0,.05
v#=.005
If KeyDown(42) v=.0005
If KeyDown(30) MoveEntity cam,-v,0,0
If KeyDown(32) MoveEntity cam,v,0,0
If KeyDown(17) MoveEntity cam,0,0,v
If KeyDown(31) MoveEntity cam,0,0,-v
If KeyHit(57) Goto NewSCene
RotateEntity cam,180+MouseY()*.5, -(MouseX()-500)*.5,0
If MouseDown(1)=False
;Set the Render Texture as the target surface RenderWorld will render to
SetRenderTarget tex
;Disable Color Clearing, useful for mirror in mirror effects
CameraClsMode cam,0,1
;Set the viewport to same size as the render texture
CameraViewport cam,0,0,TextureWidth(tex),TextureHeight(tex)
;Render scene to Texture
RenderWorld
;Set the render target back to the old render target (the BackBuffer())
RestoreRenderTarget
CameraViewport cam,0,0,GraphicsWidth(),GraphicsHeight()
CameraClsMode cam,1,1
End If
;Render the scene normaly
RenderWorld
;Update FPS counter
counter=counter+1
If MilliSecs() - timer > 999
fps=counter
counter=0
timer=MilliSecs()
End If
Text 0,0,"FPS: "+fps
Text 0,12,"w,s,a,d, mouse to move, Left Shift to move slowly, RMB turns cube, LMB disables Render to Texture"
Text 0,24,"Texture Size (1,2 adjusts): "+texSize+"x"+texSize
Text 0,36,"Free Video Memory: "+AvailVidMem() / 1024
Text 0,50,"Hit SPACE to restart Graphics3D system"
Flip 0
Wend
End