Happy Friday everyone.
I've been working on this little function as a matter of exercise more than functionality. In a nutshell it draws something to a non-zero bitmap and gets the image there, then puts that image into a sprite. However when the sprite was being drawn onto bitmap 0 it was getting stretched out (see attached). I was able to remedy this by deleting the sprite I was initially setting up in the procedure that found the first available sprite number.
I'm not sure why this would cause the sprite to be stretched.
Any one got some ideas?
At any rate I essentially have it fixed, but I noticed another peculiarity; the text seems to get thinner when it is in the sprite versus when it is drawn with a text command to bitmap 0. I have a feeling that this is due to how windows or direct x is handling the drawing of a font vs. what is actually in video memory, but I'm way to new to this to be sure of such a judgement call. Also when I take a screenshot of this effect and paste it into GIMP there is no difference between the two which is even stranger.
Any insight on this is welcome.
`----------------------------------------------------
` CreateBitmapSprite()
`----------------------------------------------------
` This function will draw to an available bitmap
` and then create a sprite from the bitmap.
` Set any (or all) parameter(s) to 0 and the next
` sprite, image, or bitmap number will be found.
` There must be a sprite or image number available
` between 500 and 1,000 this can be altered below.
` Insert your drawing commands where indicated.
`==========================================SM20111202
`~~~~~~~~~Test Driver~~~~~~~~~
set display mode 800,600,32
set window on
set window position 0,0
CreateBitmapSprite(0,0,0)
wait key : end
`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function CreateBitmapSprite( AvailableBitmap, AvailableImage, AvailableSprite)
w = screen width()
h = screen height()
`==== Sprite Boundaries ====
x0 = 0 : y0 = 0
x1 = w : y1 = h
`==== Setup Bitmap, Image, and Sprite numbers ====
gosub setup_sub
setup_return:
`==== Insert your code here to draw to the available bitmap ====
`Draw text to non-zero bitmap then copy to screen for comparison only
set current bitmap BitmapNum
center text w/2,h/2, "Test text"
box 50,50,100,100
copy bitmap BitmapNum, 0
wait key
`Draw text to non-zero bitmap again since copy bitmap seems to actually remove data from other bitmap
set current bitmap BitmapNum
center text w/2,h/2, "Test text"
box 50,50,100,100
`==== Create the sprite and display it ====
get image ImageNum, x0,y0,x1,y1
set current bitmap 0
sprite SpriteNum,0,0, ImageNum
show sprite SpriteNum
delete bitmap BitmapNum
exitfunction
`========================= SETUP_SUBROUTINE ============================
setup_sub:
`==== Find an available bitmap ====
if AvailableBitmap > 0
BitmapNum = AvailableBitmap
create bitmap BitmapNum,w,h
else
c = 2
repeat
if not bitmap exist(c)
BitmapNum = c
create bitmap BitmapNum,w,h
endif
inc c
until bitmap exist(c-1) = 1 or c > 32
if c > 32
print "ERROR: no available bitmap to draw to."
exitfunction
endif
endif
`==== Find an available image ====
if AvailableImage > 0
ImageNum = AvailableImage
else
c = 500
repeat
if not image exist(c)
ImageNum = c
get image ImageNum,0,0,1,1
endif
inc c
until image exist(c-1) = 1 or c > 1000
if c > 1000
print "ERROR: no available image available between 500 and 1000."
exitfunction
endif
endif
`==== Find an available sprite ====
if AvailableSprite > 0
SpriteNum = AvailableSprite
else
c = 500
repeat
if not sprite exist(c)
SpriteNum = c
sprite SpriteNum,0,0, ImageNum
endif
inc c
until sprite exist(c-1) or c > 1000
if c > 1000
print "ERROR: no available sprite between 500 and 1000."
exitfunction
endif
endif
delete image ImageNum
delete sprite SpriteNum //comment this line to see stretching
gosub setup_return
endfunction
Hopefully the code is straight forward. I aim for clean code!
Thanks for the help.
EDIT:
After some messing around I see that the pixel loss of the text seems less when running the displayed sprite in a synced loop. But there is still some loss to the clarity / sharpness of the text. Would be nice to get over that hump.
EDIT 2:
I'm over the hump, but not completely sure why.
I set the texture flag on the get image command and it prevented any noticeable pixel loss. This worked with texture flag 1 and 3 only. Both of which have no stretching set, not sure why that would make a difference. I was thinking it might be something to do with the alpha, but it doesn't appear to be so since texture flag 1 uses colorkey and texture flag 3 retains alpha.
Insight is still highly sought.
~Napland Games~