looking for some possible help with a few questions

Previous topic - Next topic

mmalficia

Hi folks   been quiet lately but  ive been lurking .. and playing with GLB in my spare time.

Ive been working threw some book examples and such for some time now building  a library of functions im interested in for some future projects and gotten to the point were im either clueless or  the forum search isnt helping much. Any help or pointers to info would be highly appreciated but im not looking for handouts, and im full well aware im asking alot a questions so i apologize in advance :>

Topic 1 is about text and font routines  .. background(im working on a simple epub reader and cbz to epub comic converter)

Searching the forums for how to handle font scaling isnt working to good so how does one handle it  in GLB short of having  separate fonts for each scale  taking into account im looking to be able to reflow text into a predefined area.

on the topic of fonts for later projects  im looking to be able to texture or apply gles2 sharers to larger scaled fonts (only to the  Whitespace etc) im guessing poly vectors is going to be the way to go or rendering the fonts to a surface   but not to sure how thats going to work any ideas?

topic 2:

Ive stalled in converting two projects  from C++  to glb   because if their heavy use of pointers ..  (ones dealing with sound visualization techniques , the others dealing with random world generation ,love SpriteZ BTW.. wheres my 3d? (J/K)). in general how  do you all deal with not being able to use pointers  what are the workarounds etc  im at a loss short of rolling my own and reinventing the wheel, but im sure ill run into this again and hitting the same brick wall.

Those of you coding for  handhelds or writing portable code  how does GLB handle low memory environments  is there a standard way of tracking what memory im using etc (basically like in the case of the epub reader n such  if its on a desktop im really not worried about memory constraints  but if it were ported to ipad/iphone etc  ide have to be)   does GLB handle it all for you  or is  there some standard way of doing / tracking things.

well thats more than enough for me to bother you all with and  to get my head around if i get any help ... for now :>

Thanks a million  :nw:
MMal

Slydog

For your font questions, I don't think a scaled font would look good, although I've never tried it.
I would think the best option would be to render each font size to a separate file.
I looked at Moru's font routines, and they would probably be what you are looking for.
You can render them to an area, and it flows properly to the next line, etc.
Search the forum, or here's his website (wasn't working just a second ago tho):
http://gamecorner.110mb.com/

I ended up writing my own using fonts generated from the Bitmap Font Generator here:
http://www.angelcode.com/products/bmfont/
It packs the fonts tightly and creates a text file that describes each character (ie location, size, etc).

Here's some GLB code to read this file:

Code (glbasic) Select
GLOBAL _Fonts[] AS TFont
CONSTANT FILE_MODE_READ = 1

TYPE TFontChar
xy AS TPoint // x,y position of character in font texture
size AS TSize // Size (w,h) of character
offset AS TPoint // x,y offset amount when drawing character
xadvance% // Move this many pixels left to draw next character, don't use character width
ENDTYPE

TYPE TFont
id% // ID of this font definition
sprite_id% // The sprite that holds this font texture
sprite_size  AS TSize // Width / Height of font texture
spacing%
height% // General height of a font character
chars[] AS TFontChar
ENDTYPE

FUNCTION Font_New%: fn$, font_id%, height%, spacing%
CONSTANT PATH$ = "Graphics/Fonts/" // Path to 'Fonts' folder
LOCAL fh% // File Handle
LOCAL font AS TFont // Temporary 'TFont' type
LOCAL ascii% // Ascii value of current character
LOCAL line$ // Current line data from '.fnt' file
DEBUG ">Font_New: " + fn$ + ", id:" + font_id + "\n"
font.id = font_id // Unique id to reference this font for drawing
font.sprite_id = Sprite_Load(PATH$ + fn$ + "_0.png") // Load font texture sprite
font.spacing = spacing // Default spacing between characters
font.height = height                                                                       // If you want a general line height (and not calculated)
Sprite_GetSize(font.sprite_id, font.sprite_size) // Get font texture width, height
DIM font.chars[ASCII_MAX + 1] // Initialize character array

// --------------------------------------------------------------------
// PARSE ".FNT" FILE
// --------------------------------------------------------------------
fh = GENFILE() // Get available file handle
IF OPENFILE(fh, PATH$ + fn$ + ".fnt", FILE_MODE_READ) = FALSE // Open font's '.fnt' file
RETURN FALSE // Exit and return 'FALSE' if can't open
ENDIF

// First 4 lines aren't needed
READLINE fh, line$
READLINE fh, line$
READLINE fh, line$
READLINE fh, line$

// Read and parse character data from file
WHILE ENDOFFILE(fh) = FALSE
READLINE fh, line$ // Read next line of data for the next character
IF LEN(line$) <= 0 THEN BREAK // End of the character data (skip any kerning data)
IF MID$(line$, 0, 4) <> "char" THEN GOTO SKIP // Character data begins with 'char', skip to next line
ascii = MID$(line$,   8, 3) // Ascii value
IF (ascii < 0) OR (ascii > ASCII_MAX) THEN GOTO SKIP // Ascii value is out of range, skip to next line
font.chars[ascii].xy.x = MID$(line$,  15, 4) // [X Position]
font.chars[ascii].xy.y = MID$(line$,  23, 4) // [Y Position]
font.chars[ascii].size.w = MID$(line$,  35, 4) // [Width]
font.chars[ascii].size.h = MID$(line$,  48, 4) // [Height]
font.chars[ascii].offset.x = MID$(line$,  62, 4) // [X Offset]
font.chars[ascii].offset.y = MID$(line$,  76, 4) // [Y Offset]
font.chars[ascii].xadvance = MID$(line$,  91, 4) // [X Advance]
SKIP:
WEND
CLOSEFILE fh // Close '.fnt' file

//Debug_Font(font)

DIMPUSH _Fonts[], font // Add new font definition to global font list
RETURN TRUE // Font added successfully
ENDFUNCTION


It uses other code from my project (ie 'Sprite_Load(), and Sprite_GetSize()) but that's easily worked around.
And it uses two other TYPES TPoint, and TSize, which are just (x, y) and (w, h) but can be recode too.
I could post those functions / types too if you need them.

But then you have to write some routines to actually plot the text, using polyvectors for speed and flexibility (ie. easily change the colors (including gradient effects)).  I guess you could easily change the scale too to stretch the font, but non-pixel perfect fonts may look ugly. 

Oh, and if you want to save draw calls (which I did), buffer your text writing to one routine.  (ie. each 'TextDraw()' call only actually adds your text to a queue, then have a final 'TextDrawAll()' to generate the polys.)
Use only one STARTPOLY / ENDPOLY for ALL your font writing, then use POLYNEWSTRIP to start each new character / string.

Then to reflow your text to predefined areas, just plot each word in the string (space delimited) and calculate the width of the next word, and if the running total has enough room to fit the word, draw it and update the running total, or reset the running total and move to the next line and draw the word.  This is my next routine to write for my project!

Good luck,
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]