libtcod FONTS
BlitzMax Forums/Brucey's Modules/libtcod FONTS
| ||
Ok, Brucey, I can not get any fonts to work if they are not 8x8???? Even your example code breaks if you change the font. Am I doing something wrong, or is this a bug??? Simple code follows: SuperStrict Import BaH.libtcod 'Local font:String = "fonts/terminal8x8_gs_ass.png" Local font:String = "fonts/arial10x10.png" Local scrheight:Int = 60 Local scrwidth:Int = 80 'TCODConsole.SetCustomFont(font, TCOD_FONT_LAYOUT_ASCII_INCOL) TCODConsole.setcustomfont(font, tcod_font_layout_tcod) TCODConsole.InitRoot(scrwidth, scrheight, "ScreenCommands", False) TCODConsole.root.SetForegroundColor(TCODColor.White) TCODConsole.root.SetBackgroundColor(TCODColor.Blue) TCODConsole.root.Clear TCODConsole.root.PrintFrame(0,0,40,40,1,"Main Edit Window") TCODConsole.root.PrintLeft(0,59,1,"F1=Move - F2=Resize - F3=Load - F4=Save - Esc=Quit") Repeat If KeyDown(key_escape) Exit End If TCODConsole.Flush() Until TCODConsole.IsWindowClosed() End If you change the code to arial8x8.png it works fine. Any other 8x8 font seems to work ok as well. What gives? (I assume I'm doing something stupid.) :( Anyway, if I try to use any other font it just appears garbled, like some offset if set wrong and it's reading in the image incorrectly. Don't know how to post a screen shot to show what I'm talking about. Any help would be appreciated, Shortwind :) |
| ||
Yes, I'd say it's a bug at the moment. I think my math is failing me somewhere... |
| ||
Thanks for the reply. I was hoping it wasn't me, or my setup. |
| ||
Hello, I've been looking at your text.bmx code. First, I guess I don't understand what the f.u1[cur] and f.v1[cur] float values are. They are the same no matter what the original font.img size. Run the below code maybe it will help explain what's happening: Local f_widthMultiplier:Float, f_heightMultiplier:Float Local f_fontwidth:Int, f_fontheight:Int Local img_width:Int, img_height:Int Local fontNbCharHoriz:Int = 32, fontNbCharVertic:Int = 8 Local inRow:Int = 0, i:Int 'Load image TCOD layout at 8x8 char size img_width = 256 img_height = 64 f_widthMultiplier = 1.0 / img_width f_heightMultiplier = 1.0 / img_height Print f_widthMultiplier+" "+f_heightMultiplier f_fontWidth = img_width / fontNbCharHoriz f_fontHeight = img_height / fontNbCharVertic Print f_fontWidth+" "+f_fontHeight Local j:Int, x:Float, y:Float j=0 For i = 0 Until 5 If inRow Then x = Float((j Mod fontNbCharHoriz)*f_fontWidth) y = Float((j /fontNbCharHoriz)*f_fontHeight) Print "i = "+i Print "x = Float((j Mod fontNbCharHoriz)*f_fontWidth) "+x Print "y = Float((j /fontNbCharHoriz)*f_fontHeight) "+y Else x = Float((j /fontNbCharVertic)*f_fontWidth) y = Float((j Mod fontNbCharVertic)*f_fontHeight) Print "i = "+i Print "x = Float((j /fontNbCharVertic)*f_fontWidth) "+x Print "y = Float((j Mod fontNbCharVertic)*f_fontHeight) "+y End If j:+1 Print " f.u0[cur] = x * f.widthMultiplier "+(x * f_widthMultiplier) Print " f.v0[cur] = y * f.heightMultiplier "+(y * f_heightMultiplier) Print " f.u1[cur] = (x + f.fontWidth) * f.widthMultiplier "+((x + f_fontWidth) * f_widthMultiplier) Print " f.v1[cur] = (y + f.fontHeight) * f.heightMultiplier"+((y + f_fontHeight) * f_heightMultiplier) Next 'Load image TCOD layout at 10x10 char size img_width = 320 img_height = 80 f_widthMultiplier = 1.0 / img_width f_heightMultiplier = 1.0 / img_height Print f_widthMultiplier+" "+f_heightMultiplier f_fontWidth = img_width / fontNbCharHoriz f_fontHeight = img_height / fontNbCharVertic Print f_fontWidth+" "+f_fontHeight j=0 For i = 0 Until 5 If inRow Then x = Float((j Mod fontNbCharHoriz)*f_fontWidth) y = Float((j /fontNbCharHoriz)*f_fontHeight) Print "i = "+i Print "x = Float((j Mod fontNbCharHoriz)*f_fontWidth) "+x Print "y = Float((j /fontNbCharHoriz)*f_fontHeight) "+y Else x = Float((j /fontNbCharVertic)*f_fontWidth) y = Float((j Mod fontNbCharVertic)*f_fontHeight) Print "i = "+i Print "x = Float((j /fontNbCharVertic)*f_fontWidth) "+x Print "y = Float((j Mod fontNbCharVertic)*f_fontHeight) "+y End If j:+1 Print " f.u0[cur] = x * f.widthMultiplier "+(x * f_widthMultiplier) Print " f.v0[cur] = y * f.heightMultiplier "+(y * f_heightMultiplier) Print " f.u1[cur] = (x + f.fontWidth) * f.widthMultiplier "+((x + f_fontWidth) * f_widthMultiplier) Print " f.v1[cur] = (y + f.fontHeight) * f.heightMultiplier"+((y + f_fontHeight) * f_heightMultiplier) Next Rem j:+ 1 f.u0[cur] = x * f.widthMultiplier f.v0[cur] = y * f.heightMultiplier f.u1[cur] = (x + f.fontWidth) * f.widthMultiplier f.v1[cur] = (y + f.fontHeight) * f.heightMultiplier Next Thanks |
| ||
Okay, I've spent ages trying to get to the bottom of the problem. It appears to be a scaling issue with the underlying texture. I've committed some changes which should hopefully help this a bit. I'm still having some issues with the "tcod" font layout files, where the first row isn't rendering properly... fun fun :-p Oh, and the font files should be "alpha" transparent. I've converted most of the example files in the included font folder, but there are still a few to be done. |