I've added a bit to use sprite pasting but for some reason, the screen goes blue and images and sprites are not being drawn to the screen.
Can anyone figure out what's wrong with it please?
Rem Project: Bitmap Font Gen
Rem Created: Saturday, May 21, 2011
Rem ***** Main Source File *****
WL_TRACE_INIT("trace_file.txt")
SCREEN_SETUP()
FONT_INIT()
font1=FONT_MAKE("arial black",120,FONT_GRAB_127)
max_count=1500 : sync
count=0 : add#=0
repeat
FONT_DRAW_STRING("Hello World! 1",0,0,font1)
add#=add#+screen fps()
sync
inc count
until count>max_count
WL_TRACE_WRITE("Using FONT_UTIL FPS = "+str$(add#/count))
count=0 : add#=0
repeat
text 0,0,"Hello World! 2"
add#=add#+screen fps()
sync
inc count
until count>max_count
WL_TRACE_WRITE("Using NORMAL FONTS FPS = "+str$(add#/count))
count=0 : add#=0
repeat
FONT_DRAW_STRING("Hello World! 3",0,0,font1)
add#=add#+screen fps()
sync
inc count
until count>max_count
WL_TRACE_WRITE("Using FONT_UTIL FPS = "+str$(add#/count))
FONT_ALPHA(255) : FONT_DIFFUSE(255,0,255)
count=0 : add#=0
repeat
FONT_DRAW_STRING_SPRITE("Hello World! 4",0,0,font1)
add#=add#+screen fps()
sync
inc count
until count>max_count
WL_TRACE_WRITE("Using FONT_UTIL_SPRITES FPS = "+str$(add#/count))
WL_TRACE_CLOSE()
end
Rem ***** Included Source File *****
function SCREEN_SETUP()
set bitmap format 21
set display mode 1024,768,32
set window off
sync rate 0
sync on
endfunction
Rem ***** Included Source File *****
#constant FONT_GRAB_ALL 1 ` grab chars 1 to 255
#constant FONT_GRAB_255 2 ` grab chars 32 to 255
#constant FONT_GRAB_127 3 ` grab chars 32 to 127
#constant FONT_DEF_BM 30 ` default bitmap to use
#constant FONT_DEF_SP 999 ` default sprite ID to use
type FONT_GLOBALS
bm as integer ` temp bitmap
r as word ` diffuse colour
g as word
b as word
alpha as word ` alpha
sp as integer ` default sprite
endtype
type FONT_CHAR
img as integer
wid as integer
hgt as integer
endtype
type FONT_SETTINGS
name as string
size as integer
start as integer
count as integer
ftype as integer
endtype
function FONT_INIT()
` define global tables to hold image font lists
global dim fchars() as FONT_CHAR
global dim fsets() as FONT_SETTINGS
global fontg as FONT_GLOBALS
fontg.bm = FONT_DEF_BM
fontg.r = 255
fontg.g = 255
fontg.b = 255
fontg.alpha = 255
fontg.sp = FONT_DEF_SP
endfunction
function FONT_MAKE(fname$, size, ftype)
` Create an image font/character list
fnum as integer : start as integer : count as integer : c as integer
fnum = array count(fsets()) + 1
array insert at bottom fsets()
fsets().name=fname$
fsets().size=size
select ftype
case FONT_GRAB_ALL
start=1 : count=255
endcase
case FONT_GRAB_255
start=32 : count=255-32
endcase
case FONT_GRAB_127
start=32 : count=127-32
endcase
endselect
fsets().start=array count(fchars())+1
fsets().count=count
fsets().ftype=ftype
` setup the bitmap, font and colors to use
if bitmap exist(fontg.bm) then delete bitmap fontg.bm
create bitmap fontg.bm,512,512 ` should be big enough for now
` add each char to the image list
set text font fname$ : set text size size
ink 0xffffff,0x000000 : set text opaque
set image colorkey 0,0,0
for c=start to start+count
FONT_GRAB_CHAR(c)
next
` cleanup
delete bitmap fontg.bm
` now setup a default sprite for later abuse
sprite fontg.sp,0,0,fchars(1).img
hide sprite fontg.sp : offset sprite fontg.sp,0,0
endfunction fnum
function FONT_GRAB_CHAR(c as integer)
` add a char to the list
char as string : w as integer : h as integer
char = chr$(c)
w=text width(char) : h=text height(char)
if w=0 then w=1
if h=0 then h=1
cls : text 0,0,char
array insert at bottom fchars()
fchars().img=FONT_FIMG() : fchars().wid=w : fchars().hgt=h
get image fchars().img,0,0,w,h
endfunction
function FONT_FIMG()
c as integer : c=1
while image exist(c)
inc c
endwhile
endfunction c
` is a smidging faster than mine
function FONT_DRAW_STRING(chars as string,x as integer,y as integer,font as integer)
c as integer : w as integer
a as integer : b as integer
w=0
` precalc the length
stringSize as integer
StringSize=len(chars)
` pull the start value into a temp
a=fsets(font).start
` precalc the offset
FontTypeOffset as integer
FontTypeOffset=-32
if fsets(font).ftype = FONT_GRAB_ALL
FontTypeOffset=-1
endif
for c=1 to StringSize
b=a+asc(mid$(chars,c)) +FontTypeOffset
paste image fchars(b).img,x+w,y
w=w+fchars(b).wid
next
endfunction
function FONT_DRAW_STRING_SPRITE(chars as string,x as integer,y as integer,font as integer)
c as integer : w as integer
a as integer : b as integer
w=0
set sprite alpha fontg.sp,fontg.alpha
set sprite diffuse fontg.sp,fontg.r,fontg.g,fontg.b
` precalc the length
stringSize as integer
StringSize=len(chars)
` pull the start value into a temp
a=fsets(font).start
` precalc the offset
FontTypeOffset as integer
FontTypeOffset=-32
if fsets(font).ftype = FONT_GRAB_ALL
FontTypeOffset=-1
endif
for c=1 to StringSize
b=a+asc(mid$(chars,c)) +FontTypeOffset
set sprite image fontg.sp,fchars(b).img
paste sprite fontg.sp,x+w,y
`paste image fchars(b).img,x+w,y
w=w+fchars(b).wid
next
endfunction
function FONT_ALPHA(alpha as integer)
fontg.alpha=alpha
endfunction
function FONT_DIFFUSE(r as integer,g as integer,b as integer)
fontg.r=r : fontg.g=g : fontg.b=b
endfunction
Rem ***** Included Source File *****
` Create a trace file so as I can track various parts of the program
function WL_TRACE_INIT(file$)
global WL_TRACE_FP as integer
c as integer : c=1
while ( c <= 32 and file open( c ) )
inc c
endwhile
if ( c <= 32 )
WL_TRACE_FP=c
else
exitfunction
endif
if ( file exist(file$) ) then delete file file$
open to write WL_TRACE_FP,file$
write string WL_TRACE_FP,"Trace file created : "+get date$()+", "+get time$()
write string WL_TRACE_FP,"File handle used : "+str$(WL_TRACE_FP)
endfunction
function WL_TRACE_CLOSE()
write string WL_TRACE_FP,"EOF Trace file (safe program exit)"
close file WL_TRACE_FP
endfunction
function WL_TRACE_WRITE(t$)
write string WL_TRACE_FP,t$
endfunction
Once I've got this bit sussed then I'm going to add scale and rotation to it... Fingers crossed I can get this sussed out soon.
EDIT: Fixed... Typo... Should've been StringSize not StingSize...
Warning! May contain Nuts!