About Monkey 2 › Forums › Monkey 2 Programming Help › Render camera to a small area of the screen
This topic contains 1 reply, has 2 voices, and was last updated by 
 Mark Sibly
 1 year ago.
- 
		AuthorPosts
 - 
		
			
				
April 5, 2018 at 7:42 pm #14263
Hi,
I’m trying to get the camera to render to a small area on the top left of an image canvas. I’m setting the viewport on both the camera and the image canvas, but it doesn’t work – it still renders to the entire image canvas. Am I doing something wrong? I also tried the same approach on a regular canvas (without rendering to an image), same result.
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677Namespace myapp3d#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"Using std..Using mojo..Using mojo3d..Class MyWindow Extends WindowField _scene:SceneField _camera:CameraField _light:LightField _donut:ModelField imageTarget:ImageField imageCanvas:CanvasMethod New( title:String="Simple mojo3d app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )Super.New( title,width,height,flags )imageTarget = New Image( 640, 480, TextureFlags.FilterMipmap | TextureFlags.Dynamic )imageCanvas = New Canvas( imageTarget )EndMethod OnCreateWindow() Override'create (current) scene_scene=New Scene_scene.ClearColor = New Color( 0.2, 0.6, 1.0 )'create camera_camera=New Camera( Self )_camera.AddComponent<FlyBehaviour>()_camera.Move( 0,2.5,-5 )'create light_light=New Light_light.CastsShadow=True_light.Rotate( 45, 45, 0 )'create donutLocal donutMaterial:=New PbrMaterial( Color.Red, 0.05, 0.2 )_donut=Model.CreateTorus( 2,.5,48,24,donutMaterial )_donut.Move( 0,2.5,0 )EndMethod OnRender( canvas:Canvas ) OverrideRequestRender()_donut.Rotate( .2,.4,.6 )_scene.Update()Local smallView := New Recti(0,0,320,240)imageCanvas.Viewport = smallView_camera.View = Null_camera.Viewport = smallView_camera.Render( imageCanvas )imageCanvas.Flush()canvas.DrawImage( imageTarget, 0, Height, 0, 1.0, -1.0 )canvas.DrawText( "FPS="+App.FPS,0,0 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndI didn’t post an issue on Github because I’m not sure I’m doing it correctly…
P.S. I know I can render to a small texture and draw it in the corner, but I need it to work with a viewport in an image canvas, otherwise I’d need two image canvases…
April 5, 2018 at 10:39 pm #14266Fix coming in next update, along with fix for upside down image!
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.