I first followed this tutorial which resulted in this turkey: turtle.svg (file name is a typo).
Then I made my own duck drawing(s): duck.svg (it is beautiful, isn't it?)
Both ducks converted to BMP (via PNG and GIMP) with transparency: duck1.bmp and duck2.bmp
And put some test code together:
Code: Select all
#include once "file.bi"
const as ulong C_DARK_GRAY = RGB(63, 63, 63)
type int2d
as integer x, y
end type
'-------------------------------- Graphics.bi ----------------------------------
union rgba_union
value as ulong
type
b as ubyte
g as ubyte
r as ubyte
a as ubyte
end type
end union
type bitmap_header field = 1
bfType as ushort
bfsize as ulong
bfReserved1 as ushort
bfReserved2 as ushort
bfOffBits as ulong
biSize as ulong
biWidth as ulong
biHeight as ulong
biPlanes as ushort
biBitCount as ushort
biCompression as ulong
biSizeImage as ulong
biXPelsPerMeter as ulong
biYPelsPerMeter as ulong
biClrUsed as ulong
biClrImportant as ulong
end type
enum image_draw_mode
IDM_PSET
IDM_TRANS
IDM_ALPHA
end enum
enum image_horz_align
IHA_LEFT
IHA_CENTER
IHA_RIGHT
end enum
enum image_vert_align
IVA_TOP
IVA_CENTER
IVA_BOTTOM
end enum
type image_type
dim as any ptr pFbImg
dim as int2d size, half
dim as integer hAlign, vAlign, drawMode
declare sub create(sizeInit as int2d, colorInit as ulong)
declare function createFromBmp(fileName as string) as integer
declare sub setProp(hAlign as integer, hAlign as integer, drawMode as integer)
declare sub drawxy(x as integer, y as integer)
declare sub destroy()
declare destructor()
end type
sub image_type.create(sizeInit as int2d, colorInit as ulong)
pFbImg = imagecreate(sizeInit.x, sizeInit.y, colorInit)
size = sizeInit
half.x = size.x \ 2
half.y = size.y \ 2
setProp(IHA_LEFT, IVA_TOP, IDM_PSET)
end sub
function image_type.createFromBmp(fileName as string) as integer
dim as bitmap_header bmp_header
dim as int2d bmpSize
if fileExists(filename) then
open fileName for binary as #1
get #1, , bmp_header
close #1
bmpSize.x = bmp_header.biWidth
bmpSize.y = bmp_header.biHeight
create(bmpSize, &hff000000)
bload fileName, pFbImg
'print "Bitmap loaded: " & filename
return 0
end if
'print "File not found: " & filename
return -1
end function
sub image_type.setProp(hAlign as integer, vAlign as integer, drawMode as integer)
this.hAlign = hAlign
this.vAlign = vAlign
this.drawMode = drawMode
end sub
sub image_type.drawxy(x as integer, y as integer)
select case hAlign
case IHA_CENTER : x -= half.x
case IHA_RIGHT : x -= size.x
end select
select case vAlign
case IVA_CENTER : y -= half.y
case IVA_BOTTOM : y -= size.y
end select
select case drawMode
case IDM_PSET : put (x , y), pFbImg, pset
case IDM_TRANS : put (x , y), pFbImg, trans
case IDM_ALPHA : put (x , y), pFbImg, alpha ', alphaval
end select
end sub
sub image_type.destroy()
if (pFbImg <> 0) then
imagedestroy(pFbImg)
pFbImg = 0
end if
end sub
destructor image_type()
destroy()
end destructor
'---------------------------------- Main ---------------------------------------
const NUM_DUCK_IMG = 2
dim as image_type duck(NUM_DUCK_IMG - 1)
dim as string fileName
screenres 800, 600, 32
fileName = "duck1.bmp"
if duck(0).createFromBmp(fileName) <> 0 then
print "Error: '" & fileName & "' not found!"
sleep
end -1
end if
duck(0).setProp(IHA_LEFT, IVA_TOP, IDM_ALPHA)
fileName = "duck2.bmp"
if duck(1).createFromBmp(fileName) <> 0 then
print "Error: '" & fileName & "' not found!"
sleep
end -1
end if
duck(1).setProp(IHA_LEFT, IVA_TOP, IDM_ALPHA)
dim as integer iDuckImg = 0
while inkey <> chr(27)
line(0, 0)-(799, 599), C_DARK_GRAY, bf
'put (350, 250), duck(iDuckImg).pFbImg, alpha
duck(iDuckImg).drawxy(350, 250)
iDuckImg += 1
if iDuckImg >= NUM_DUCK_IMG then iDuckImg = 0
sleep 300
wend
sleep
If only there was a library to read and render SVG directly in freeBASIC ;-)