#159216 - sUPREz - Fri Jun 27, 2008 11:31 am
Hi,
I'm currently working om my game's 3d interface.
I have lots of button with the same background but the text is each time different. If I add one pcx per button, the memory isn't large enough. So I'm trying to "write" some text on generated texture I can render on additional quads.
A friend tell me this advice but I really don't know how to get started with this.
Where can I find tutorials or examples talking about that ?
thanks !
#159218 - silent_code - Fri Jun 27, 2008 12:03 pm
Some example images would help - I don't get the idea and I also don't think there's some info about it out there...
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#159221 - sUPREz - Fri Jun 27, 2008 1:14 pm
I have something like 30 buttons like that :
[Images not permitted - Click here to view it]
I'm looking for a code that write text in a small graphic buffer I can use as a texture. So that I only load my button once and I can wrote the text I want on it.
Maybe it's more clear now ? :)
#159225 - elwing - Fri Jun 27, 2008 2:50 pm
you might want to check Cearn marvelous work:
http://www.coranac.com/
specialy what's related to TTE. it is written for the GBA, but most of the NDS 2D hardware is the same...
#159765 - Fury - Sun Jul 06, 2008 12:26 pm
If you pre-generate a character set, say 8-bit and choose one colour for transparency (say palette entry 0) then it shouldn't be too hard to blit the chars over the button texture, skipping any 0's
If memory is _really_ tight, you can use a 4 or 1-bit character set, but your algorithm gets more complicated.
#159786 - dovoto - Sun Jul 06, 2008 7:42 pm
The simple way is to put your font in a single large texture. You could then composite the background button graphics with a series of foreground quads mapped such that their textures have the appropriate letter on them. However, the DS is very limited in its quads per frame so this may not be a viable approach.
Pre-rendered buttons will generally look better than rendering text onto a button without advanced techniques so another thing to consider is compressing the button textures by reducing their size, their color depth, or using the compressed texture format on the DS.
Also you could do a more traditional compression such as one supported by the DS bios or a more standard png or jpg format. You would have to decompress them into vram as you need them of course.
Keep in mind that if you render the texture bitmaps you will not save any vram used only save the size of your rom unless you use the first approach above which composites the button and the text.
One final method which might result in the best trade off is to use a single texture for the button background and a single texture for each string. You could build the texture for the text in main memory from a font stored in main memory using standard bit blitting techniques (do a google on software bit blitting and rendering fonts). Once the texture is complete you can load it into vram (you could also also build it directly in vram however the 16 bit bus is sort of a pain to blit low color depth stuff to).
What you gain by doing the above is a much more dynamic way of storing your buttons in memory (you can create new buttons on the fly by assigning them a size, a background, and a string). You also can use a very low color count on the text textures and only one background per button type which may result in a bit of vram savings.
What you lose is quality (a pre-rendered button is going to have smoother more readable text), a bit of speed (it takes time to render and load textures), and a quad per button (each button will take two quads to render it, a limiting factor in a system that only gives you 1500 or so quads to play with).
One final note is that you can use a 2D background layer for your buttons. If you are currently not using the 2D hardware in your engine this might be a good approach as the process is the similar to that above and you save a few precious quads for your 3D scene.
_________________
www.drunkencoders.com
#159793 - ZeroSum - Sun Jul 06, 2008 9:03 pm
I use the method dovoto described above, having a font texture and rendering a quad per letter. As he said though it depends on how many quads you have spare and how many strings you want to draw.
In case it's useful heres the relevant images/code:
My font texture: [Images not permitted - Click here to view it]
How it looks: [Images not permitted - Click here to view it]
The code: http://rafb.net/p/MePCWi15.html
#159796 - silent_code - Sun Jul 06, 2008 10:33 pm
You could also use (Sprite) Objects. That method (like any other) has its limitations, but it might be worth experimenting with. ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#159802 - DensitY - Mon Jul 07, 2008 1:28 am
silent_code wrote: |
You could also use (Sprite) Objects. That method (like any other) has its limitations, but it might be worth experimenting with. ;^) |
^^ works reasonably well if you want mostly single words.
#159804 - silent_code - Mon Jul 07, 2008 1:36 am
Well, you could use up to 128 8 pixel wide, unrotated objects per scanline, so I guess it would be more than enough, right? ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#159806 - DensitY - Mon Jul 07, 2008 1:43 am
what i do is actually make a 32x16 sprite and draw a 4x8 font into it. that gives me about 8 characters over 2 lines.. just join a few together to get a sentance. to make things fast I store the font in a special 4x8 tile format so I can do :
Code: |
while(heightofletter--) // ie 8 pixels
{
int words = 2; //(4 bytes basically)
while(words--)
{
// you can do color replacement here as well if need be.
*dest++ = *src++;
}
// skip the next 4 bytes, as its the second half of the 8x8 tile, and our
// font is 4x8
dest+=2;
}
|
and just write it directly into the sprites vram address. its pretty quick.
(Warning: at work, just wrote in what I remembered off the top of my head lol).
#159824 - elwing - Mon Jul 07, 2008 6:48 am
don't want to sound rash, but tonc's text engine on the website I mentionned contain link to a tonclib (and it's source) and it is able to render fixed, variable width font to tiled, afine and bitmap bg... that seems to contain all what you need. and if you want to make the text renderer by yourself looking at tte would be a great idea...