index.php

Avances (parte I) – Fuentes a partir de imágenes

BennuGD ha tenido muchas mejoras últimamente. Como escribirlas todas en un único mensaje podría resultar muy largo y aburrido, voy a escribir una serie de artículos resaltando algunas mejoras que me parecen interesantes.

A finales del año pasado (28 de Diciembre), Splinter añadió dos nuevas funcionalidades a fnt_new(). Se utilizan con la siguiente sintaxis:
FNT_NEW (CHARSET, DEPTH);
FNT_NEW (FILE, GRAPH, CHARSET, WITDH, HEIGHT, FIRST, LAST, FLAGS);

Seguid leyendo para más detalles.

Como podeis ver, hay un parámetro llamado CHARSET que puede valer:
CHARSET_ISO8859
CHARSET_CP850

De esta forma, se puede controlar el conjunto de caracteres (charset) que se quiere usar en vuestra nueva fuente.

No sólo eso, también existe una parámetro FLAGS, que puede ser:
NFB_VARIABLEWIDTH
NFB_FIXEDWIDTH

Así podeis elegir si quereis que vuestra fuente sea equiespaciada o no.
Con esta nueva funcionalidad, podeis crear una nueva fuente en memoria desde una imagen que haya sido cargada previamente. Splinter ha escrito el siguiente código mostrando el efecto.

import "mod_video";
import "mod_wm";
import "mod_text";
import "mod_map";
import "mod_key";

private
    a,b,c;
    g;
    font, font2;

begin
    set_mode(640,480);
    g = png_load("font.png");
    font = fnt_new(0,g,CHARSET_ISO8859,16,16,0,255,0);
    write_int(font,0,0,0,&a);
    write_int(font,0,20,0,&b);
    write_int(font,0,40,0,&c);
    write(font,0,60,0,"hello world!");

    write_int(0,320,0,0,&a);
    write_int(0,320,20,0,&b);
    write_int(0,320,40,0,&c);
    write(0,320,60,0,"hello world!");

    font2 = fnt_new(0,g,CHARSET_ISO8859,16,16,0,255,1);
    write_int(font2,0,100,0,&a);
    write_int(font2,0,120,0,&b);
    write_int(font2,0,140,0,&c);
    write(font2,0,160,0,"hello world!");

    while( !key( _ESC ) && !exit_status )
        a++;
        b--;
        c*=2;
        if ( c == 0 ) c = 1; end
        frame;
    end
end

El código necesitará una imagen como esta:

Y la usará para, inicialmente, crear una fuente en memoria (que podeis salvar después con fnt_save()) y escribir algún texto en pantalla, de forma equiespaciada o con ancho de caracter ajustado:

Some text rendered with the previous font

¡Espero que lo encontreis útil!

PD: Estas nuevas funcionalidades aún no están documentadas. ¿Quereis ayudar? ¡Id a la página de documentación sobre fnt_new() e incorporad la nueva información!

Progress (part I) – Fonts from bitmaps

BennuGD has seen a lot of improvements lately. As writing about all of them in a single post would result in a boringly long one, I’m going to write a series of articles highlighting some improvements I find interesting.

Late last year (28th December) Splinter added two new functionalities to fnt_new(). They’re used with the following syntax:
FNT_NEW (CHARSET, DEPTH);
FNT_NEW (FILE, GRAPH, CHARSET, WITDH, HEIGHT, FIRST, LAST, FLAGS);

Read on for more details.

As you can see, there’s now a new CHARSET parameter which can be one of these:
CHARSET_ISO8859
CHARSET_CP850

This way, you can control the charset used in your new font.

Not only that, but there’s a new FLAGS parameter, which can be one of:
NFB_VARIABLEWIDTH
NFB_FIXEDWIDTH

This way, you can specify if your new font will be monospaced or not.
With this new functionality, you’ll be able to create a new font in memory from a bitmap that’s already been loaded. Splinter posted the following code showing the effect.

import "mod_video";
import "mod_wm";
import "mod_text";
import "mod_map";
import "mod_key";

private
    a,b,c;
    g;
    font, font2;

begin
    set_mode(640,480);
    g = png_load("font.png");
    font = fnt_new(0,g,CHARSET_ISO8859,16,16,0,255,0);
    write_int(font,0,0,0,&a);
    write_int(font,0,20,0,&b);
    write_int(font,0,40,0,&c);
    write(font,0,60,0,"hello world!");

    write_int(0,320,0,0,&a);
    write_int(0,320,20,0,&b);
    write_int(0,320,40,0,&c);
    write(0,320,60,0,"hello world!");

    font2 = fnt_new(0,g,CHARSET_ISO8859,16,16,0,255,1);
    write_int(font2,0,100,0,&a);
    write_int(font2,0,120,0,&b);
    write_int(font2,0,140,0,&c);
    write(font2,0,160,0,"hello world!");

    while( !key( _ESC ) && !exit_status )
        a++;
        b--;
        c*=2;
        if ( c == 0 ) c = 1; end
        frame;
    end
end

The code will take a bitmap such as this one:

And use it to first create a font in memory (that you can later save with fnt_save()) and write some text to the screeen, both in fixed-width and variable width forms:

Some text rendered with the previous font

Hope you find it useful!

PS: This new functionality still needs to be documented, would you like to do it? Go the the fnt_new() page in the wiki and add the relevant info!

Port a PSP

Escribiré un post más largo sobre todos los avances que se están dando en la comunidad y en Bennu proximamente, pero mientras tanto, dejo el siguiente vídeo (muy jugoso).

Felicidades a DCelos por su trabajo.

PSP port

I shall write a lengthy post on all the new happenings, but I’ll just leave a video, for now:

Cool, ain’t it? Congrats to DCelso for his work.

¡Feliz 2011!

¡Desde bennugd.org os deseamos un feliz 2011 lleno de proyectos BennuGD!

Happy 2011!

From the bennugd.org site, we wish you a happy new year full of BennuGD projects!