Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Need help understanding SetRenderToImage and SetRenderToScreen

Author
Message
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 21st Jul 2019 20:48 Edited at: 21st Jul 2019 20:52
Hi all,

A very long time ago, I made a 3D game in AppGameKit for the ill-fated Ouya, a console that seemed promising for indie games. The game wasn't very fluid on the device because it's fill-rate was very slow. One solution for this was to render everything to an image and then display this image as a screen-filling sprite, once all drawing-operations were complete.

Now, I'd like to use that technique again for a 2D game. However, I'm having a hard time getting things to work. Regarding SetRenderToImage and SetRenderToScreen, my assumptions on how to use these commands where these:

  • Set the program to draw to an image
  • Draw stuff
  • Copy the image to a sprite
  • Clear the image
  • Set the program to draw to the screen
  • Position the sprite


I've searched the forum and looked at the examples in the help-files, and I'm... sort of... getting a result. In the code below, I need to hide all the sprites I've positioned or they will show up in both the image and the sprite. This seems wrong and very costly regarding framerates in a game. Can someone help me out and explain what I am doing wrong? I'd appreciate it a lot!

Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 21st Jul 2019 20:57
Instead of Sync( ) use Swap( )

As Sync( ) performs all of the Update ( ) > Render( ) > Sync ( ) operations... it's basically a simple "Handle all my Frame Updates" Function., where-as Swap( ) simply updates the Front/Back Buffer presenting them to the Display Device.
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 21st Jul 2019 21:20
Thank you for responding Raven. I've tried using Swap(), but found that - when I replaced Sync() with it - nothing would display. Perhaps I am positioning it wrong.. but surely it must be called after all other functions and commands have been executed?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Jul 2019 21:31
The problem might be that you are trying to render the rendered image on the rendered image. Like putting two mirrors facing each other and the image repeats infinitely. Unless that's what you're trying to do

Try his;
Just before you SetRenderToImage()
SetSpriteVisible(sprrender, 0)

Just Before Sync()
SetSpriteVisible(sprrender, 1)
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 21st Jul 2019 21:57
Hi blink0k,

thank you as well for your suggestion. I've encountered the mirroring-problem you describe and tried to counter it with hiding the individual sprites in the scene (a solution I'm not really happy with ). If I add the suggested lines and rem the part where I explicitly hide the sprites, the result is this:



Here's the modified code for completeness:
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 22nd Jul 2019 21:58 Edited at: 22nd Jul 2019 21:58
Here is how you could use Swap() to render only the Image. No need to all the sprites invisible if you don't render them, at all.



Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Jul 2019 23:22
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 23rd Jul 2019 05:49 Edited at: 23rd Jul 2019 07:55
Wow Golelorn and Blink0k, this is it!

I didn't realize that I needed to call DrawSprite() for the image rendered, before Swap(). I had experimented with SetSpriteImage(), but that just left a grey screen (with the 75, 75, 75 color). Thank you for helping me figure this out.. I've been racking my brain for days. The combination of hiding and un-hiding the render-sprite, along with the DrawSprite() and Swap()-commands, makes sure I don't need to set the individual sprites visible- an invisible anymore. Here's the final revised code:


Login to post a reply

Server time is: 2024-04-23 20:41:38
Your offset time is: 2024-04-23 20:41:38