Author Topic: Bitmap Fonts from Amiga Font Gifs + Small Copper Printing  (Read 4055 times)

0 Members and 1 Guest are viewing this topic.

Offline spathi

  • C= 64
  • **
  • Posts: 78
  • Karma: 5
    • View Profile
Code: [Select]
'Blitzmax Font Stripper
' By SpayThee

' If you get this harmless error "D3DERR: Unable to lock render target surface" it means you are
' trying to draw a pixmap outside of the screen boundaries... the image needs to be large enough
' to accomodate the font strip it will make when generating the font image.

' These settings will work with this image: http://www.algonet.se/~guld1/fonts/062.gif
' BUT!  You have to load it up in paint and save it as a bmp, because it won't like loading a gif...
' Save it in a ./media directory...

WIDTH=1024:Int
HEIGHT=480:Int
Graphics WIDTH,HEIGHT

Global ORIGIMAGESIZEX:Int=320, ORIGIMAGESIZEY=52
Global FONTSIZE:Int=16
Global FONTOUTPUTNAME:String = "fontstrip.png"
Local fontpixmap:TPixmap=LoadPixmap("media/062.bmp")  ' Font Name Goes Here
Local fontstrip:TImage=CreateImage(ORIGIMAGESIZEX*FONTSIZE,FONTSIZEY)  ' Create image the size of fontstrip
Global pixwindow:TPixmap
Global savepixmap:TPixmap

' The next string needs to contain the characters in the order they appear in the bitmap.
' This is used as a lookup string for fontprint()
Global characters:String="-.!0123456789:'(),? ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Cls

'  This block of three FOR clauses chops up the bitmap and renders it all out as a strip.
'  It's three clauses because all of the bitmap fonts are different anyway so you have to jigger
'  this differently depending on how the font maker set his bitmap up.

For i = 0 To ORIGIMAGESIZEX Step 16  'Step expression must be constant!?
pixwindow = PixmapWindow(fontpixmap,i,0,FONTSIZE,FONTSIZE)
DrawPixmap pixwindow, i,0
Next

For i = 0 To ORIGIMAGESIZEX Step 16
pixwindow = PixmapWindow(fontpixmap,i,FONTSIZE+1,FONTSIZE,FONTSIZE+1)
DrawPixmap pixwindow, i+320,0
Next

For i = 0 To ORIGIMAGESIZEX Step 16
pixwindow = PixmapWindow(fontpixmap,i,FONTSIZE*2+2,FONTSIZE,FONTSIZE+2)
DrawPixmap pixwindow, i+640,0
Next

' Save the stripfont so we don't need to go through all this rigamarole each time we want to load the font image.  Could also reorder
' the letters if you wanted to, if you had a bunch of fonts...  all these old demoscene fonts have all sorts of weird letter orders and fucked up
' conventions that they adhere to.

savepixmap=GrabPixmap(0,0,ORIGIMAGESIZEX*3,FONTSIZE)
SavePixmapPNG(savepixmap,FONTOUTPUTNAME)
Local charmap:tmap=CreateMap()

'Driver, Test, Copper
Global ticks:Int=0

SetBlend MASKBLEND
teststrip:TImage = CreateImage(480,fontsize,1,DYNAMICIMAGE|MASKEDIMAGE)

fontprint("COPPER TEXT... I MISS ROBOTRON",10,10)

'This chunk is to build the TImage for the copper.  Necessary because pixmaps won't
'allow you to draw in maskmode (that I know of)
'Major hackwork in order to allow you to get a mask image.

GrabImage teststrip,10,10 
SetColor 255,255,255
DrawRect 0,0,1024,480
SetColor 0,0,0
DrawImage teststrip,10,10
GrabImage teststrip,10,10

Local xorig:Int
Local yorig:Int
While Not KeyHit(KEY_ESCAPE)
xorig=width/2-Cos(ticks)*100-240
yorig=height/2-Sin(ticks)*100
ticks=ticks+1
Cls
SetColor 255,0,0
copperbar(0+xorig,10+yorig,478+xorig,25+yorig)
SetMaskColor 255,255,255
SetColor 1,0,0
DrawImage teststrip, 0+xorig,10+yorig
fontprint("-.!0123456789:'(),?", 10,10)
fontprint("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 10,27)
fontprint("JUST A LITTLE FONT DEMO", 10,46)
fontprint("NOT MUCH TO LOOK AT", 10,66)
Flip
Wend

' A very basic time-sliding copper
Function copperbar(ux:Int,uy:Int,lx:Int,ly:Int)
frequency = Sin(ticks)*25+50
For Local y:Int = uy To ly
SetColor 128*Sin(ticks *frequency +(y-uy)*50)+128,128*Cos(ticks *frequency +(y-uy)*50)+128,Rand(255)
DrawLine ux,y, lx,y
Next
End Function

Function fontprint(stringtoprint:String,x:Int,y:Int)
' you will probably want to touppercase this string, otherwise it will not handle lowercase right
' unless the font is set up for that.  Or just type in all caps. 
For Local i:Int = 0 To stringtoprint.length-1
Local chartoprint:Int=characters.find(Chr(stringtoprint[i]))
If chartoprint = -1 chartoprint=13
pixwindow=PixmapWindow(savepixmap,chartoprint*FONTSIZE,0,FONTSIZE,FONTSIZE)
DrawPixmap pixwindow, x+i*FONTSIZE,y
Next
End Function

The image it uses is here...
« Last Edit: January 03, 2012 by spathi »