Quote: "I tried to compose images off-screen and found that they just get corrupted. The only way to create an image to grab seems to be within the screen constraints...or do you have another secret?"
I've just uncovered a way to do this. I'm currently on a mac so I had to make do with tier 2, you should be able to get the gist of what I'm doing though.
// Includes, namespace and prototypes
#include "template.h"
using namespace AGK;
app App;
// App prototype
void AppForceExit ( void );
int img, spr, spr2, spr3, identify;
// function declaration
int getImage(int, int, int, int);
// Begin app, called once at the start
void app::Begin( void )
{
// use device resolution
agk::SetVirtualResolution ( m_DeviceWidth, m_DeviceHeight );
// create 2 sprites, set their sizes, colours and positions (offscreen)
spr = agk::CreateSprite(0);
spr2 = agk::CreateSprite(0);
agk::SetSpriteColor(spr, 255, 0, 0, 255);
agk::SetSpriteColor(spr2, 0, 255, 0, 255);
agk::SetSpritePosition(spr, agk::GetVirtualWidth(), 0);
agk::SetSpritePosition(spr2, agk::GetVirtualWidth(), 50);
agk::SetSpriteSize(spr, 20, 20);
agk::SetSpriteSize(spr2, 20, 30);
// create a new sprite from our grabbed image, position it and rotate it
spr3 = agk::CreateSprite(getImage(agk::GetVirtualWidth(), 0, 100, 100));
agk::SetSpritePosition(spr3, 50, 50);
identify = agk::CreateSprite(0);
agk::SetSpritePosition(identify, agk::GetSpriteX(spr3), agk::GetSpriteY(spr3));
agk::SetSpriteAngle(spr3, 90); //toggle the comment/uncomment on this line to see the difference
}
// Main loop, called every frame
void app::Loop ( void )
{
agk::Print("Hello World");
agk::Sync();
}
// Called when the app ends
void app::End ( void )
{
}
// as there is no swap() call, the user won't see this happening
int getImage(int x1, int y1, int w, int h) {
// set the world coordinates to the coordinates for which we want to grab the image
agk::SetViewOffset(x1, y1);
// update the positions and render to the back buffer
agk::Update();
agk::Render();
// get the image
int lspr = agk::GetImage(agk::WorldToScreenX(x1), agk::WorldToScreenY(y1), w, h);
// reset the view and update and render
agk::SetViewOffset(0, 0);
agk::Update();
agk::Render();
return lspr;
}
So basically, this creates two sprites (one red, one green) and positions them off screen. The function getImage() will grab the image of the two sprites offscreen and return an image number. Spr3 is created from the grabbed image and positioned onscreen.
What is actually happening is I'm offsetting the Camera so that the image I'm grabbing is technically within the screen constraints however, I only update() and render() but I don't swap(). So the user doesn't see it happen. Update() updates the positions and render draws the current screen to the back buffer. The getImage() (agk's function) will grab the image from the backbuffer and then my function will reset the Camera, update() and render() again. This could be a little expensive processing wise though.
I hope all of that made sense?