Mod_ttf

Started by Sandman, October 10, 2009, 11:00:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Sandman

There were some bugs in the older mod_ttf or something; well at least the one I and some others had. So I packaged a new one with freetype 2.3.5 and it actually works.

See: http://wiki.bennugd.org/index.php?title=Mod_ttf
-- Sandman

DCelso

Monstruos Diabólicos

"A PAck of classic GAMEs For BennuGD" en desarrollo
http://code.google.com/p/apagame4be/

DCelso

I have changed the examples of the wiki, updating they to the new format.
It goes very well in 16 bits mode, but if  you try to load in 32 bits mode the ttf_loadaa does not load well the font and colors. You can try the effect using the new example of the ttf_load tha I put in the wiki changing set_mode(320,200,16) by this other set_mode(320,200,32)
Monstruos Diabólicos

"A PAck of classic GAMEs For BennuGD" en desarrollo
http://code.google.com/p/apagame4be/

Sandman

#3
Yes this may be a problem, didn't think of it. I gave it a brief look and fixed the 16bit on 32bit failure. 32bit fonts in 32bit mode still doesn't work though...

Upload new version ( http://wiki.bennugd.org/images/2/29/Mod_ttf.zip ).

Good job on the examples.

[EDIT]
And 32bit in 32bit mode is also fixed now.
-- Sandman

DCelso

Yeah, now runs well in all modes.
Karma up.
Monstruos Diabólicos

"A PAck of classic GAMEs For BennuGD" en desarrollo
http://code.google.com/p/apagame4be/

Windgate

wait wait wait...

Sorry for my english but... I think you are talking about .ttf fonts support for Bennu.

DCelso was working on a 32 bits FNT editor, but it only had an option in order to establish a constant alpha on shadow and border...

.ttf is an "almost" vectorial format, and curves can estabish the correct alpha in ALL pixels... The curvature is PERFECT. A .ttf is a TRUE font... I have just downloaded the new DLL, I'm very excited.

Cooking a karma...
Iván García Subero. Programador, profesor de informática, monitor de actividades culturales y presidente de TRINIT Asociación de Informáticos de Zaragoza. http://trinit.es

Windgate

Dudes, I have just installed mod_ttf (copy+paste), but I don't know how to use a .ttf file.

I hope there was a FUNCTION load_ttf ( string ) and I can use write ( ) as always using the load_ttf identifier as first parameter.

Please, copy+paste any code you have used, it will be very helpful :P

(Still cooking the karma, trust me)
Iván García Subero. Programador, profesor de informática, monitor de actividades culturales y presidente de TRINIT Asociación de Informáticos de Zaragoza. http://trinit.es

Sandman

That is how it works, yes.

On the mod_ttf page you will find two functions:
ttf_load(STRING filename , INT height), also called load_ttf()
ttf_loadaa(STRING filename , INT height , INT colordepth , INT backgroundcolor , INT textcolor), also called load_ttfaa()

They both return a fontID of a newly generated font, using the TTF file and other settings.
-- Sandman

DCelso

Yes, I tested the examples of the wiki with the president ttf file and they work well.
Splinter left the president ttf link in the topic of the bennu3d logo
http://forum.bennugd.org/index.php?action=dlattach;topic=128.0;attach=435
Monstruos Diabólicos

"A PAck of classic GAMEs For BennuGD" en desarrollo
http://code.google.com/p/apagame4be/

Windgate

Ok, I'm testing it now... Sandman, if it works well I'll invite all Bennu comunity to give you a Karma.

It will be a Karmageddon xD
Iván García Subero. Programador, profesor de informática, monitor de actividades culturales y presidente de TRINIT Asociación de Informáticos de Zaragoza. http://trinit.es

josebita

Great, Sandman!

This was really needed. :)

DCelso

#11
Is possible to do that the background were a little bigger or it could be configurable?
And
Is possible to do an offset in x and y to the background, similar to fntedit do currently?
Monstruos Diabólicos

"A PAck of classic GAMEs For BennuGD" en desarrollo
http://code.google.com/p/apagame4be/

Sandman

#12
There's no such thing as a background actually. The 'bg' color is used to perform anti-aliasing, nothing more. It cannot be moved. Of course you can build this functionality, but that would be a new functionality.

For some reason write_in_map() doesn't like 32bit mode, in that it doesn't work... after many hours of trying to build Bennu, and finally succeeding by using codeblocks, I'm giving up. Never ask me to build Bennu again...  :-\
Anyway, here's the code. It's all yours, Splinter. You may have to change the TTF file path:

import "mod_text"
import "mod_key"
import "mod_ttf"
import "mod_video"
import "mod_map"
import "mod_draw"
import "mod_say"

Process Main()
Private
int f;
int* ip;
int i;
Begin

set_mode(320,240,32);
frame;
f = ttf_loadx("C:\Windows\fonts\vladimir.ttf",40,32,rgba(255,255,255,255),rgba(255,255,255,0),0);

map_clear(0,0,rgb(0,255,0));
drawing_map(0,graph);
drawing_color(rgb(255,0,0));
draw_box(100,100,200,200);
graph = write_in_map(f,"HELLOLLO",0);
say("depth: " + map_info(0,graph,G_DEPTH));
write(f,10,10,0,"HELLOLLO");

x = 50;
y = 50;
size = 400;

ip = map_buffer(0,graph);
for(i=0;i<20; i++)
ip[i] = 080FFFFFFh;
end

While(!key(_ESC))
frame;
End

End


[EDIT]
I should note that TTF_LoadX() is a new function. I actually wanted to add more parameters, but then I got fed up with the write_in_map() issue. ;)
-- Sandman

DCelso

For testing the new ttf_loadx I did a new example

import "mod_key"
import "mod_proc"
import "mod_map"
import "mod_video"
import "mod_ttf"
import "mod_text"
import "mod_screen"
global
  int id_ttfs[4];
  int id_bg;
  int depth = 16;
Begin
    set_mode(320,240,depth);
    id_bg = new_map(320,240,depth);
    map_clear(0,id_bg,RGB(0,255,0));
    put_screen(0,id_bg);
    id_ttfs[0] = load_ttf("resources/presdntn.ttf",48);
    id_ttfs[1] = load_ttfaa("resources/presdntn.ttf",48,depth,RGBA(255,0,0,255),RGBA(255,0,0,0));
    id_ttfs[2] = ttf_loadx("resources/presdntn.ttf",48,depth,RGBA(0,0,255,255),RGBA(0,0,255,0),1);
    id_ttfs[3] = ttf_loadx("resources/presdntn.ttf",48,depth,RGBA(0,0,255,255),RGBA(0,0,255,0),100);
    id_ttfs[4] = ttf_loadx("resources/presdntn.ttf",48,depth,RGBA(0,0,255,255),RGBA(0,0,255,0),255);
    write(id_ttfs[0],25,30,0,"Hello");
    set_text_color(rgb(255,0,255));
    write(id_ttfs[0],155,30,0,"World");
    write(id_ttfs[1],25,130,0,"Bye");
    write(id_ttfs[2],155,90,0,"World");
    write(id_ttfs[3],155,130,0,"World");
    write(id_ttfs[4],155,170,0,"World");
    Repeat
        frame;
    Until(key(_ESC))

    unload_fnt(id_ttfs[4]);
    unload_fnt(id_ttfs[3]);
    unload_fnt(id_ttfs[2]);
    unload_fnt(id_ttfs[1]);
    unload_fnt(id_ttfs[0]);
    unload_map(0,id_bg);
End

Then I discovered a strange thing. If you try the example with depth=16 it work well (or it is that I think), but if you try the example with depth=32, the id_ttfs[2] and the id_ttfs[3] get the same result instead of a different result.
Monstruos Diabólicos

"A PAck of classic GAMEs For BennuGD" en desarrollo
http://code.google.com/p/apagame4be/

Sandman

Try a different font, because they are different here.
-- Sandman