Re: [AD] shaders + ttf

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 03/07/2013 03:10 AM, Jon Rafkind wrote:
There seems to be an issue using the programmable pipeline and the ttf addon. Fonts sometimes don't draw, specifically when they are drawn to FBO's. Adding the following line to ttf.c:172 makes it work again, but I am unsure why. One possible reason is the upload of the page bitmap requires a shader, but Siegelord seems to suggest that isn't the case.

push_new_page:
    ...
    page = al_create_bitmap(256, 256);
+ page->shader = al_get_target_bitmap()->shader;

I'll try to make a test case showing the broken behavior.

Here's a testcase:

#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>

int main()
{
   al_init();
   al_init_primitives_addon();
   al_init_image_addon();
   al_init_font_addon();
   al_init_ttf_addon();
   al_set_new_display_flags(ALLEGRO_USE_PROGRAMMABLE_PIPELINE);

   ALLEGRO_DISPLAY* display = al_create_display(800, 600);
   ALLEGRO_FONT* font = al_load_font("DejaVuSans.ttf", 30, 0);

   ALLEGRO_SHADER* shader = al_create_shader(ALLEGRO_SHADER_AUTO);
al_attach_shader_source(shader, ALLEGRO_PIXEL_SHADER, al_get_default_pixel_shader(ALLEGRO_SHADER_AUTO)); al_attach_shader_source(shader, ALLEGRO_VERTEX_SHADER, al_get_default_vertex_shader(ALLEGRO_SHADER_AUTO));
   al_link_shader(shader);
   al_use_shader(shader);

   ALLEGRO_BITMAP* bmp = al_create_bitmap(800, 600);
   al_set_target_bitmap(bmp);

   al_set_target_bitmap(al_get_backbuffer(display));
   al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY);
   al_put_pixel(200, 200, al_map_rgb_f(1, 1, 1)); // This shows up
   al_unlock_bitmap(bmp);

   al_use_shader(shader);
al_draw_text(font, al_map_rgb_f(1, 1, 1), 100, 100, 0, "Testing"); // This doesn't

   al_set_target_bitmap(al_get_backbuffer(display));
   al_draw_bitmap(bmp, 0, 0, 0);
   al_flip_display();
   al_rest(5.0);
}

It draws the pixel via that locking code (note how it functions without the shader), but the actual text doesn't draw. Jon's change makes the text draw but it's not clear why.

-SL




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/