Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Drawing 3D view to RenderTarget not working on iOS — Gideros Forum

Drawing 3D view to RenderTarget not working on iOS

One of my games uses 3D models to create 2D sprites by drawing the 3D view to RenderTargets. Using any of the more recent Gideros versions (at least since 2023-07) it works fine except when running on iOS. It works on Android, the Gideros player on Windows and MacOS, but on iOS nothing appears on the RenderTarget, so all the dynamically generated 2D sprites are empty. I believe it worked on all platforms when I was using Gideros 2022-12.

The issue can be reproduced by adding the code below to an existing app and running on iOS. After a few seconds it will create a 3D cube (using the code from the 3D Cube example) and add it to the stage, then draw it to a render target, make a bitmap and add that to the stage. When working correctly you should see the rotating 3D cube appear, and a stationary copy of the cube (the 2D sprite from the RenderTarget) off to the right. On iOS the rotating 3D cube is there, but the stationary one from the RenderTarget is missing:
Timer.delayedCall(5000,
	function()
		local function face(color,rx,ry)
			-- Create a colored face
			c=Sprite.new()
			s=Shape.new()
			s:setFillStyle(Shape.SOLID, color,0.8)
			s:beginPath()
			s:moveTo(-1,-1)
			s:lineTo(-1,1)
			s:lineTo(1,1)
			s:lineTo(1,-1)
			s:lineTo(-1,-1)
			s:endPath()
 
			s:setZ(-1)
			c:addChild(s)
			c:setRotationX(rx)
			c:setRotationY(ry)
			return c;
		end
 
		--Create a cube
		cube=Mesh.new(true)
		cube:addChild(face(0xFF0000,0,0))
		cube:addChild(face(0xFFFF00,90,0))
		cube:addChild(face(0xFF00FF,-90,0))
		cube:addChild(face(0x00FF00,180,0))
		cube:addChild(face(0x00FFFF,0,90))
		cube:addChild(face(0x0000FF,0,-90))
 
		--Set up the 3D view and projection
		local sw,sh=800,600
		local projection=Matrix.new()
		projection:perspectiveProjection(45,sw/sh,0.1,1000)
		local view=Viewport.new()
		view:setProjection(projection)
		view:setPosition(sw/2,sh/2)
		view:setScale(-sw/2,-sh/2,1)
		stage:addChild(view)
 
		--Add our cube to the scene
		view:setContent(cube)
		--Look at it from -8 units in Z direction
		view:lookAt(0,0,-8,0,0,0,0,1,0)
 
		cube:setRotationX(20)
		cube:setRotationY(49)
		cube:setRotation(30)
		cube:addEventListener(Event.ENTER_FRAME,function ()
			cube:setRotationX(cube:getRotationX()+1)
			cube:setRotationY(cube:getRotationY()+1.2)
			cube:setRotation(cube:getRotation()+1.3)
		end)
 
 
		-- Draw the cube the the render target and add a Bitmap using it to the stage, offset from the 3D version:
		local rt = RenderTarget.new(800, 600)
		rt:draw(view)
		b = Bitmap.new(rt)
		b:setPosition(300, 0)
		stage:addChild(b)
	end
)
Any ideas?

Comments

Sign In or Register to comment.