Hello all,
I wondered if anyone could show me how to properly use RenderToImage() and DrawSprite() together.
I’m trying to build a rounded box as a sprite by pasting together images of the corners and sides, etc. if you see what I mean. The problem is, DrawSprite seems to mess up the sprite’s transparency so that there’s a line round the transparent bit.
The one on the left is the sprite which I pasted onto the render image. The one on the right is a sprite created from the render image.
Here's the code. This is the first time I've used SetRenderToImage and I don't know what I'm doing
// set window properties
SetWindowTitle( "RenderToImage" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
// Load a background sprite
iBackSprite = CreateSprite(LoadImage("Back.png"))
// Create the final sprite which will use the iRenderImage.
iCompletedSprite = CreateSprite(0)
SetSpriteSize(iCompletedSprite,100,200)
SetSpritePosition(iCompletedSprite,100,0)
// Create the image to render onto
iRenderImage = CreateRenderImage(512,512,0,0)
// Load the image I'm going to paste
iSpriteToPaste = CreateSprite(LoadImage("ThingToPaste.png"))
// Set RenderToImage & make sure rez is the same as the app's
SetRenderToImage(iRenderImage,0)
SetVirtualResolution(1024,768)
ClearScreen()
// Do all the sprite pasting here. For now, I'll just stick one on.
DrawSprite(iSpriteToPaste)
// Back to rendering to the screen
SetRenderToScreen()
// Calculate and set the CompletedSprite's UV so it's displaying ONLY the rounded box
// which I put together and not the whole 512x512 RenderImage
SetSpriteImage(iCompletedSprite,iRenderImage)
fSpriteHoriz# = GetSpriteWidth(iCompletedSprite) / GetImageWidth(iRenderImage)
fSpriteVert# = GetSpriteHeight(iCompletedSprite) / GetImageHeight(iRenderImage)
SetSpriteUV(iCompletedSprite, 0,0, 0,fSpriteVert#, fSpriteHoriz#,0, fSpriteHoriz#,fSpriteVert#)
do
Sync()
loop
I'm attaching the media (2 pics).
Thanks for any help,
James