123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|676|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> Palettes and Bitmap Fonts

Sat, 25 Oct 2008, 22:42
LostUser
In some sprite rips I've seen on the Internet there is sometimes a "palette" of different colors (usually in a small rectangle).

My question is, can Blitz Basic 2D apply palettes to images, or specifically in my case, Bitmapped Fonts?

I'm using the font maker library (see below), but the thing is I'm going to have to make a new font image for every color I want to use, in every size.

Therefore, is it not possible to tell Blitz Basic to say "OK, I want to use a Yellow version of my bitmap font" and it does it, without me creating a specific Yellow version?

I have another question... Should one worry about Fonts at all? I want to use a series of fonts, but something in the back of my head tells me that using "SETFONT/LOADFONT" is the wrong way to make Blitz games.

Finally, if you're using Bitmap fonts, can you still use "FontHeight()" and "StringWidth()"... I use these two mainly to automate the distance between menu items.

Question summary;

1) Is it possible to use palettes on Bitmap fonts and images?
2) Should I worry about the fonts, or just include them in my "public" folder and don't worry about it?
3) Can you still use FontHeight/StringWidth for bitmap fonts?

The library I'm using;







Sat, 25 Oct 2008, 23:45
LostUser
I've figured out how to solve the distance issue I raised in my previous post.

I added;


And I used in this example;


Sun, 26 Oct 2008, 01:15
Jayenkai
No, color's out. Since Blitz doesn't have realtime colorising, it's just not going to work. Sorry.
Technically, you could retrofit the Bitmap font image display routine into a 2D-in-3D engine, and have it work that way, using that to recolour things, but you wouldn't be able to draw too much to the screen, and.. quite frankly it'd be really slow to do something so dull.
In most cases, you're probably better off just using standard fonts instead.

-=-=-
''Load, Next List!''
Sun, 26 Oct 2008, 01:44
JL235
First you should be able to just make a function to change all the colours for you pixel by pixel. So the actual colour change is trivial. Conceptually you can wrap it up to look like the image colours are tied to a set pallette of colours.

The hard part comes from when you want to make these colour changes because it's typically quite expensive. If you only want to change the colours before the game starts then you can just make this function, use it, and the problem is done.

If you want to change the colours lots of times during the main loop and it's only involving a few images and fonts then you could pregenerate them before the main loop and store them in a look up table.

If it involves lots and lots of images or needs to be generate dynamically (i.e. you don't know what colours you gonna be using until run-time) then you could generate the images at run-time but always store them a cache. When you want to change the colours of an image you first check the cache to see if the image your generating is already in there. If so you then just return that image. If not, you generate it, store it in the cache and then return it.

Storing all those images though will use lots of memory. If that becomes an issue then you should probably try to track how much memory the cache is using (based on the size of each image added and removed stored) and maybe a reference counting system for when images are accessed. You might also want to slowly lower the reference count for all images over time so that images referenced lots during one section of the game are freed later in the game if they are rarely needed.

I implemented something similar in Java recently to increase the speed of realtime rotation where it caches all the rotated images that are generated. It meant that when I rotate an image I often just return a copy from my image cache and so no rotation is actually performed. They were also stored using soft references which automatically freed the image referenced if my program needed the memory. Java Garbage Collectors are also encouraged to have a bias towards collecting the least accessed soft references, so I didn't need to track image or memory usage.

This idea worked well for me.
Sun, 26 Oct 2008, 04:15
Phoenix
Simple example of replacing color in an image:



Like DD said, this isn't something you should call all the time as it's a fairly slow function. In Blitz, you have to pregenerate or use some 2D-in-3D approach, or use a cache method like DD said.
Sun, 26 Oct 2008, 04:36
JL235
I didn't say it wasn't thesable, just that you ought to use some sort of lookup table or cache to help reduce when and how often you need to change or generate the image.
Sun, 26 Oct 2008, 04:58
Phoenix
I usually only skim through posts longer than a couple of lines
Sun, 26 Oct 2008, 05:30
LostUser
Hi, JL235.

Geez that does sound very complex.

I really don't want to make it more complex than it already is.

I mean, if pushed; I don't mind generating Bitmap Fonts for different colors, and sizes and effects... and encountering for mouseovers/mousein's ....

Geez, with all those different combinations it makes me wonder why even bother with bitmapped fonts in the first place.

I think I'll just have to keep adding different bitmap fonts until I get so frustrated I rip out every bitmap font routine and just use text.

Sun, 26 Oct 2008, 05:48
Jayenkai
I originally made the bitmap font routine for using in a completely different language. I couldn't get OpenGL to do basic text printing, so I cheated and made the bitmap fonts.
In most cases, though, since the font is being generated by code, you can just replace the bitmap font with a bit of fancy text printing..



-=-=-
''Load, Next List!''
Sun, 26 Oct 2008, 05:54
LostUser
Wow, those font effects are pretty cool.

But its still technically requiring the user to have the font you used.

How do you get around this issue?

Thanks
Sun, 26 Oct 2008, 06:08
Jayenkai
Stick a font in the folder!

https://www.aenigmafonts.com/
Get a font from there, make sure that the font's filename is the same as it's actual name.. (+.ttf on the end)

So, eg, EditUndo.ttf should be renamed to "Edit Undo BRK.ttf", etc.
Stick it in the folder with the rest of your data, and just load it as LoadFont("data folder/edit undo brk.ttf",size) or whatever..

-=-=-
''Load, Next List!''
Sun, 26 Oct 2008, 06:47
LostUser
I never knew you could do that! (Slaps head)

I always assumed that Blitz would look in the windows System fonts folder and that if you even dare tried to use an alternate folder Blitz would start crapping out!

I'm going to try it now (and remove the font from my windows system fonts folder) I'll be so relieved.

Thanks for the heads up!

UPDATE:

Hey, that works! Once I renamed it like you said, it worked like a charm!

Thanks a lot!
Sun, 26 Oct 2008, 08:45
Andy_A

My question is, can Blitz Basic 2D apply palettes to images, or specifically in my case, Bitmapped Fonts?



Yes, and you can do it as fast as displaying two images to the screeen or a buffer.

https://socoder.net/index.php?snippet=12528
Sun, 26 Oct 2008, 23:40
LostUser
Thanks for the code, I've looked at it; and whilst I'd love to go back to Bitmap Fonts - I don't think I will be. Mainly because of all the headaches I was encountering.

Secondly Jay offered an easy fix solution, just include the fonts; which I thought you couldn't do -- but it does work.