why is viewport texture smaller than game screen ?

siskasiska Posts: 5Member
edited February 6 in Programming


Hi,
I'm looking at the Godot 3.0.6 demo "screen capture" and I don't understand why

    var img = get_viewport().get_texture().get_data()
    img.flip_y()


produces a screenshot that's smaller than the game screen. Also, why is the screen capture fipped by default ?

Tagged:

Tags :

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 1,049Admin
    Answer ✓

    The reason the screenshot is smaller than the screen is because the TextureRect node that the result of the screenshot is applied to is sized to be smaller than the full screen. In actual pixels, the texture within the TextureRect node is exactly the same size as the game screen, but because the node is smaller it is scaled down.

    The reason for this is so you can see the results of hitting the capture screen button. If it was the exact same size as the game screen, nothing would seem to happen when you press the capture screen button.


    As for why the capture is flipped by default, this is just how Godot renders Viewport textures by default. If you make a Viewport node, you can enable a option to flip the screen on the Y axis automatically, but in the case of the screen capture demo, it is using the root viewport so the flip on the Y axis has to be done in code (otherwise the game screen would be flipped outside down).

    Hopefully this helps! :smile:

  • siskasiska Posts: 5Member

    Oh ... I totally overlooked the scale property ! Thank you very much for pointing that out to me, TwistedTwigleg !

    Mmm ... Still trying to wrap my head around this ...When I use the same code in my own project, with the scale of the TextureRect set to 1, but with proj setts > window > test w and h set to half of the 'normal' size w and h, I also get a screenshot that's smaller than the game screen size. Not what I expected (and a bit inconvenient) :)

  • TwistedTwiglegTwistedTwigleg Posts: 1,049Admin
    Answer ✓

    @siska said:
    Oh ... I totally overlooked the scale property ! Thank you very much for pointing that out to me, TwistedTwigleg !

    Mmm ... Still trying to wrap my head around this ...When I use the same code in my own project, with the scale of the TextureRect set to 1, but with proj setts > window > test w and h set to half of the 'normal' size w and h, I also get a screenshot that's smaller than the game screen size. Not what I expected (and a bit inconvenient) :)

    No problem, I'm happy to help how I can.

    As for why it it still smaller than the game size, I think it is because of the TextureRect node itself, not anything in the project settings. The TextureRect has a property called size, and if you set size to the same resolution as your game window and position it so that the corners of the TextureRect node align with the corners of the camera viewport preview (the purple lines), then it should (hopefully) work.

    Here's a picture showing the size (on a different project):

    Hopefully it will help. I think that will fix the screenshot being a different size than the game window.

    All of that said, it has been awhile since I've looked at the demo, so it is quite possible I'm forgetting something :smile:

  • siskasiska Posts: 5Member

    Yes, that solved it !
    I also had to set the stretch mode to 'keep aspect centered'.

    Thank you very much !

  • TwistedTwiglegTwistedTwigleg Posts: 1,049Admin

    @siska said:
    Yes, that solved it !
    I also had to set the stretch mode to 'keep aspect centered'.

    Thank you very much !

    No problem, I'm happy to have helped! :smile:

Sign In or Register to comment.