; RenderWorldToCanvas Example ; --------------------------- ; Requires Extended mode. Const EVENT_WINDOW_CLOSE=$803 ; Build a GUI window with a 3D canvas window=CreateWindow("RenderWorldToCanvas",100,100,640,480,0,15) canvas=CreateCanvas(8,8,608,400,window) label=CreateLabel("The 3D world renders into the GUI canvas above. Esc: exit",8,416,608,32,window) Graphics3DCanvas canvas ; The scene lives in the default world world=GetWorld() camera=CreateCamera() PositionEntity camera,0,1,-5 SetCanvasCamera canvas,camera light=CreateLight() RotateEntity light,45,45,0 cube=CreateCube() PositionEntity cube,0,1,0 EntityColor cube,80,165,240 frame=0 running=True While running ; Pump GUI events so the window stays responsive event=WaitEvent(1) While event<>0 If event=EVENT_WINDOW_CLOSE And EventSource()=window Then running=False event=PeekEvent() Wend If KeyHit(1) Then running=False TurnEntity cube,0,1,0 frame=frame+1 ; Build the pending 3D frame for the canvas; nothing is presented ; yet, and the selected world is not changed RenderWorldToCanvas canvas,world ; A 2D overlay drawn on the canvas buffer joins the pending frame SetBuffer CanvasBuffer(canvas) Color 235,242,255 Text 8,8,"RenderWorldToCanvas frame "+frame SetBuffer BackBuffer() ; FlipCanvas presents the 3D frame plus the overlay FlipCanvas canvas,True Wend EndGraphics FreeGadget window End