Posted: 25th Jul 2022 20:17
Hello

I want to load 3D objects, move the camera above it, take a screenshot and write an image.
So far everything works, except for taking a screenshot and exporting it. The image is always blank.
I read the documentation here: https://www.appgamekit.com/documentation/Reference/Image/GetImage.htm

So, this is the relevant code:

+ Code Snippet
SetObjectVisible(objects[0], 1)
SetCameraPosition(1, 0, 1.1, 0)
SetCameraLookAt(1, 0, 0, 0, 0)

do
	Update(0)
	Render()
	img = GetImage(135, 135, 665, 665)
	SaveImage(img, "test.png")
	Swap()
        End
loop



I promptly see the object (as expected, As Swap() is called before End())
If I comment out the GetImage and SaveImage lines, the objects is shown perfectly.

What is wrong with the code here?

Thanks for any help!
Posted: 26th Jul 2022 0:00
Try this.
+ Code Snippet
GetCapturedImage()
Posted: 26th Jul 2022 10:24
Hi pavelman

Can you elaborate a bit more? The documentations contradicts your advice as the command is deprecated and seems to be for capturing a device camera rather than a screenshot of the rendered screen?

Thank you!
Posted: 26th Jul 2022 12:42
this is the relevant code:

i think there's more going on but check out this thread
Posted: 26th Jul 2022 13:50
delete Update(0)
and change swap() -> Sync()

+ Code Snippet
render()
 image=GetImage( 0, 0, GlobalWidth, GlobalHeight )
    rem Sync()
    SaveImage( image, "1.png" )
    end
Posted: 26th Jul 2022 16:29
Thanks Virtual Nomad and pavelman.

I'm getting somewhat closer, when I omit the SetObjectColor() command the code works as expected.
@pavelman: Switching Swap() -> Sync() doesn't make a whole lot of difference because Sync() does a Swap(). I have deleted update() from the code.

So, this works, uncomment the SetObjectColor line and the image is empty. I have no idea why this is happening. Is this a bug, or is this perfectly explainable? Either way, does anyone knows how to take a screenshot with a object colors instead of textures?
+ Code Snippet
// Project: TestScreenshot 
// Created: 2022-07-26

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "TestScreenshot" )
SetWindowSize( 800, 800, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 800, 800 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
CreateObjectBox(1, 1, 1, 1)
//SetObjectColor(1, 255, 0, 0, 0) -> Uncomment this line and the image is empty.
SetCameraPosition(1, 0, 2, 0)
SetCameraLookAt(1, 0, 0, 0, 0)
DO
    Render()
    img = GetImage(0, 0, 800, 800)
    SaveImage(img, "test.png")
    Swap()
    End
LOOP

Posted: 26th Jul 2022 20:16
AFter lots of testing I have found the solution:

I was setting the ObjectColor with Alpha 0, in normal rendering, the color is rendered normally (I actually don't know why, it should be transparant I think?)
But with the GetImage function it is applied and the whole object is transparant, even with objectalpha untouched.

It seems odd to me that the object is displayed differently on different outputs, I don't know if it's a bug or expected, but either way, If I set the Alpha to 255 the Image is as expected.

Thanks for all help!