SetRenderToImage ?

Started by Pfaber11, April 17, 2023, 14:51:24

Previous topic - Next topic

Pfaber11

I'm trying to use setrendertoimage to control the screen resolution but not having much success . Any help appreciated .

loadimage(150,"resscreen.png")
 
  setrendertoimage(150,0)
My problem is how do I render the image onto the screen? 
Thanks for reading hope you can help.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz
HP Desktop AMD 3700 16GB ram 2 GB graphics card windows 10

steve_ancell

#1
You need to create a render image, create a sprite with that image and then set render to the render image. All the time render is set to that image any draw commands and DrawSprite will plonk stuff onto it, remember to use SetRenderToScreen() to go back to normal.

For the line LoadSprite("Sprite.png") you'll need to put a sprite in the media folder.

// Project: RenderToImage
// Created: 23-04-17

// show all errors

SetErrorMode(2)

// set window properties
SetWindowTitle( "RenderToImage" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // 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 )


global renderImage as integer
global screenSprite as integer
global sprite as integer

renderImage = CreateRenderImage(GetVirtualWidth(), GetVirtualHeight(), 0, 0)
screenSprite = CreateSprite(renderImage)
sprite = LoadSprite("Sprite.png")

SetSpriteVisible(sprite, 0)
RenderStuff()


do
    if GetRawKeyReleased(27) then exit
   
    sync()
   
loop

end


function RenderStuff()
    local newSprite as integer
   
    newSprite = CloneSprite(sprite)
   
    SetSpriteVisible(newSprite, 1)
    SetRenderToImage(renderImage, 0)
    ClearScreen()
   
    for i = 0 to 19
        SetSpriteDepth(newSprite, 0)
        SetSpritePosition(newSprite, random(0, GetVirtualWidth() - GetSpriteWidth(sprite)), random(0, GetVirtualHeight() - GetSpriteHeight(sprite)))
        DrawSprite(newSprite)
       
    next i
   
    DeleteSprite(newSprite)
    SetRenderToScreen()
   
endfunction

Pfaber11

Hi Steve thanks for the excellent example .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz
HP Desktop AMD 3700 16GB ram 2 GB graphics card windows 10

steve_ancell