To anyone interested, I was able to accomplish what I set out to do. Here is a screenshot of the results of rendering to a 320x192 image and then pasting it to the screen as a sprite.
Edit: Thanks Markus, you beat me to posting, but I was able to figure it out on my own and I'm very satisfied with the results. Pretty cool functionality, for sure.
Here's my code, cleaned up and commented a bit too:
// Project: asteroids
// Created: 2015-02-05
// set window properties
SetWindowTitle( "asteroids" )
SetWindowSize( 1280, 768, 0 )
// set display properties
SetVirtualResolution( 320, 192 )
SetOrientationAllowed( 1, 1, 1, 1 )
EnableClearColor(1)
setClearColor(0,0,0) // black background
setDefaultMinFilter(0)
setDefaultMagFilter(0)
//store asteroid data
type type_asteroid
size as integer
polygons as integer
chaosMin as integer
chaosMax as integer
pX as float
pY as float
rotation as float
endType
dim asteroid[9] as type_asteroid
//store thier randomly generated shape data
type type_asteroidShape
radius as integer
endType
dim oidShape[500] as type_asteroidShape
//Generate asteroids
shapeData = 0
for a = 0 to 9
asteroid[a].size = random(6,32)
asteroid[a].polygons = asteroid[a].size/1.5
if asteroid[a].size<8 then asteroid[a].polygons = 8
asteroid[a].chaosMax = random(4,7)
asteroid[a].chaosMin = random(0,3)
asteroid[a].pX = random(0,320)
asteroid[a].pY = random(0,200)
for s = 0 to asteroid[a].polygons
oidShape[shapeData].radius = random(asteroid[a].size/2,asteroid[a].size/2+random(asteroid[a].chaosMin,asteroid[a].chaosMax))
shapeData = shapeData + 1
next s
next a
//store player information
type type_player
pX as float
pY as float
rotation as float
lives as integer
score
endType
dim player[0] as type_player
//define player data
player[0].pX = 160
player[0].pY = 100
player[0].score = 0
player[0].lives = 3
do
//check to see if our render image exists and delete it if so
if GetImageExists(1000)=1
deleteImage(1000)
endif
//create a new render image each frame and render our graphics to the image instead of the screen
CreateRenderImage (1000,320,192,0,0)
SetRenderToImage( 1000, 0 )
//Control asteroids
shapeData = 0
for a = 0 to 9
asteroid[a].rotation = asteroid[a].rotation + 0.5
angle# = 360/asteroid[a].polygons
lineAngle# = 0
for s = 0 to asteroid[a].polygons-1
radius1 = oidShape[shapeData].radius
radius2 = oidShape[shapeData+1].radius
shapeData = shapeData + 1
X# = asteroid[a].pX+sin(lineAngle#+asteroid[a].rotation)*radius1
Y# = asteroid[a].pY-cos(lineAngle#+asteroid[a].rotation)*radius1
if s = 0
startX# = X#
startY# = Y#
endif
lineAngle# = lineAngle# + angle#
if s = asteroid[a].polygons-1
nextX# = startX#
nextY# = startY#
else
nextX# = asteroid[a].pX+sin(lineAngle#+asteroid[a].rotation)*radius2
nextY# = asteroid[a].pY-cos(lineAngle#+asteroid[a].rotation)*radius2
endif
drawSpriteLine(x#,y#,nextX#,nextY#,255,255,255)
next s
next a
//Control Player
if getRawKeyState(38)=1
//move player forward
player[0].pX = player[0].pX+sin(player[0].rotation)*1
player[0].pY = player[0].pY-cos(player[0].rotation)*1
endif
if getRawKeyState(37)=1
//rotate player left
player[0].rotation = player[0].rotation - 5
endif
if getRawKeyState(39)=1
//rotate player right
player[0].rotation = player[0].rotation + 5
endif
//Draw Player ship
noseX# = player[0].pX+sin(0+player[0].rotation)*4
noseY# = player[0].pY-cos(0+player[0].rotation)*4
wing1X# = player[0].pX+sin(135+player[0].rotation)*4
wing1Y# = player[0].pY-cos(135+player[0].rotation)*4
wing2X# = player[0].pX+sin(-135+player[0].rotation)*4
wing2Y# = player[0].pY-cos(-135+player[0].rotation)*4
drawLine(noseX#,noseY#,wing1X#,wing1Y#,0,255,0)
drawLine(noseX#,noseY#,wing2X#,wing2Y#,0,255,0)
drawLine(wing2X#,wing2Y#,wing1X#,wing1Y#,0,255,0)
// Return rendering back to the screen to draw the image we just captured
SetRenderToScreen()
// Delete the sprite used in the last loop and create a fresh one
if getSpriteExists(1000)=1
deleteSprite(1000)
endif
createSprite(1000,1000)
drawSprite(1000)
Sync()
//clear the render image for the next loop to eliminate the 'house of mirrors' effect
SetRenderToImage( 1000, 0 )
clearScreen()
loop
function drawSpriteLine(x1#,y1#,x2#,y2#,r,g,b)
line=999
if getSpriteExists(line) = 0
createSprite(line,0)
endif
dx# = x2# - x1#
dy# = y2# - y1#
length# = sqrt(dx#*dx#+dy#*dy#)
angle# = ATanFull(x2#-x1#,y2#-y1#)
setSpriteColor(line,r,g,b,255)
setSpriteSize(line,1,length#)
SetSpriteOffset(line, 0.5, length#)
setSpriteAngle(line,angle#)
setSpritePositionByOffset(line,x1#,y1#)
drawSprite(line)
endFunction
Screenshot: