AB4D Forum
DXViewportView.RenderToBitmap no longer working - Printable Version

+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Ab3d.DXEngine (https://forum.ab4d.com/forumdisplay.php?fid=11)
+--- Thread: DXViewportView.RenderToBitmap no longer working (/showthread.php?tid=4477)



DXViewportView.RenderToBitmap no longer working - SLH - 02-28-2025

Hello, Just updating AB4D to the latest version from v7.1 and it looks like it has broken some of my code for doing an offscreen render then saving to a bitmap.

Calling RendToBitmap on a DXViewportView used to work. But now it's just a blank image. Rendering the camera still works, but is very slow.

Any ideas on a fix?

Best regards,

Simon

Code snippet below

Code:
  var viewport3D = new Viewport3D();
            var directxViewPort = new DXViewportView();
            directxViewPort.InitializeScene();

            directxViewPort.BeginInit();

            directxViewPort.Viewport3D = viewport3D;
            directxViewPort.Height = 2048;
            directxViewPort.Width = 2048;

            viewport3D.Width = 2048;
            viewport3D.Height = 2048;

            var camera = new FirstPersonCamera();
            camera.Position = new Point3D(0, 0, 0);
            camera.Bank = 0;
            camera.Heading = 0;
            camera.Attitude = -90;
            camera.FieldOfView = 92;
            camera.TargetViewport3D = viewport3D;

            foreach (var m in objs.Values)
            {
                viewport3D.Children.Add(m.CreateModelVisual3D());
            }

            camera.Refresh();


            directxViewPort.EndInit();

            var img2 = directxViewPort.RenderToBitmap(2048, 2048, -1, 96, 96);  //this line used to work, but now the image is just blank

            var img = camera.RenderToBitmap(backgroundBrush);  //this works but is very very slow



RE: DXViewportView.RenderToBitmap no longer working - abenedik - 03-03-2025

I am sorry that the new version does not work anymore with your code.

I have fixed that so this will work again in the next version.

Unitil then, please reorder the code so that the size of the DXViewportView is set before calling the InitializeScene:

Code:
            var viewport3D = new Viewport3D();
            var directxViewPort = new DXViewportView();

            directxViewPort.Viewport3D = viewport3D;
            directxViewPort.Height = 2048;
            directxViewPort.Width = 2048;

            viewport3D.Width = 2048;
            viewport3D.Height = 2048;

            directxViewPort.InitializeScene();

After that the directxViewPort.RenderToBitmap will produce the bitmap with rendered 3D objects.


RE: DXViewportView.RenderToBitmap no longer working - SLH - 03-03-2025

Excellent - that seems to have fixed it.

Thanks again for your fast help!