Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » characters missing after al_resize_display()

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
characters missing after al_resize_display()
APrince
Member #12,698
March 2011

I would like to continue with this discussion:

https://www.allegro.cc/forums/thread/611636/972518#target

I have tried Kris Asick's suggestion but it didn't help. Using OpenGL did not solve the problem. It looks exactly the same. Even the same characters are missing.

I have attached two screenshots. First one is taken before calling al_resize_display() the second one after.

In both cases I try to print this text:

"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

Is there any other thing I could try? I run out of ideas...

Elias
Member #358
May 2000

Do you have some code which would allow others to reproduce the probem?

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I haven't been able to reproduce this, with Direct3D, or with OpenGL.

However, I did notice some inconsistencies between the DX and the OGL implementations.

In OpenGL, the screen contents bounce around as you resize the window. Don't think this is really desirable.

In DirectX, the screen is stretched during a window resize until the mouse button is let go of, and only then is al_acknowledge_resize called and the screen contents redrawn.

Here's the code I used. Just draws a couple lines of text at the top left and lets you resize the window.

#SelectExpand
1 2 3 4 5#include <stdio.h> 6#include <cmath> 7#include <allegro5/allegro.h> 8#include <allegro5/allegro_opengl.h> 9#include <allegro5/allegro_font.h> 10#include <allegro5/allegro_ttf.h> 11#include <allegro5/allegro_direct3d.h> 12 13#define SCRW 800 14#define SCRH 600 15 16 17int display_width; 18int display_height; 19 20 21int main(int argc, char **argv) 22{ 23 ALLEGRO_DISPLAY *display; 24 ALLEGRO_EVENT_QUEUE *queue; 25 ALLEGRO_TIMER *timer; 26 27 if (!al_init()) 28 { 29 fprintf(stdout,"Could not init Allegro.\n"); 30 return 1; 31 } 32 33 al_install_keyboard(); 34 al_install_mouse(); 35 al_init_font_addon(); 36 al_init_ttf_addon(); 37 38 int renderer = ALLEGRO_DIRECT3D; 39 al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE | renderer); 40 display_width = SCRW; 41 display_height = SCRH; 42 display = al_create_display(display_width, display_height); 43 if (!display) 44 { 45 fprintf(stdout,"Could not create display.\n"); 46 return 1; 47 } 48 49 timer = al_create_timer(1.0 / 60.0); 50 51 //al_set_window_position(display,320,240); 52 queue = al_create_event_queue(); 53 al_register_event_source(queue, al_get_keyboard_event_source()); 54 al_register_event_source(queue, al_get_display_event_source(display)); 55 al_register_event_source(queue, al_get_mouse_event_source()); 56 al_register_event_source(queue, al_get_timer_event_source(timer)); 57 58 ALLEGRO_COLOR black = al_map_rgb(0,0,0); 59 ALLEGRO_COLOR white = al_map_rgb(255,255,255); 60 ALLEGRO_COLOR red = al_map_rgb(255,0,0); 61 ALLEGRO_COLOR green = al_map_rgb(0,255,0); 62 ALLEGRO_COLOR blue = al_map_rgb(0,0,255); 63 64 ALLEGRO_FONT* font1 = al_load_ttf_font("verdana.ttf" , 20 , 0); 65 if (!font1) { 66 printf("Could not load font 1.\n"); 67 return 1; 68 } 69 70 bool redraw = true; 71 bool quit = false; 72 bool switch_out = false; 73 74 al_start_timer(timer); 75 76 do { 77 78 if (redraw && !switch_out) { 79 al_set_target_bitmap(al_get_backbuffer(display)); 80 al_clear_to_color(black); 81 82 //font color x y flags text 83 84 al_draw_text(font1 , white , 0 , 0 , 0 , "abcdefghijklmnopqrstuvwxyz"); 85 al_draw_text(font1 , white , 0 , 20 , 0 , "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 86 al_draw_text(font1 , white , 0 , 40 , 0 , "1234567890!@#$%^&*()"); 87 88 al_flip_display(); 89 redraw = false; 90 } 91 92 do { 93 ALLEGRO_EVENT ev; 94 al_wait_for_event(queue , &ev); 95 96 if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE) { 97 al_acknowledge_resize(display); 98 redraw = true; 99 } 100 101 102 103 if (ev.type == ALLEGRO_EVENT_DISPLAY_LOST) { 104 printf("Display Lost\n"); 105 } 106 if (ev.type == ALLEGRO_EVENT_DISPLAY_FOUND) { 107 printf("Display Found\n"); 108 } 109 if (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN) { 110 printf("Display Switch In\n"); 111 switch_out = false; 112 } 113 if (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) { 114 printf("Display Switch Out\n"); 115 switch_out = true; 116 } 117 if (ev.type == ALLEGRO_EVENT_TIMER) { 118 redraw = true; 119 } 120 if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 121 quit = true; 122 break; 123 } 124 if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { 125 if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { 126 quit = true; 127 break; 128 } 129 } 130 131 } while (!al_is_event_queue_empty(queue)); 132 133 134 135 } while (!quit); 136 137 138 return 0; 139}

I can upload some binaries later to show you what they do when I'm not on dialup.

APrince, can you try this code and see if it works for you? See if there are any missing characters when you run it.

Kris Asick
Member #1,424
July 2001

Quote:

Regardless, the safe thing to do whenever the state of your ALLEGRO_DISPLAY object changes, is to clear all contents of video memory yourself prior, then reload everything afterwards.

Did you remember to try this? When your display is resized, remove your font from memory with al_destroy_font(), reload it, and see if the problem persists.

If it does, that would be just plain weird.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

jmasterx
Member #11,410
October 2009

I always felt the screen should just be black in GL or D3D on any platform when resizing.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Quote:

Regardless, the safe thing to do whenever the state of your ALLEGRO_DISPLAY object changes, is to clear all contents of video memory yourself prior, then reload everything afterwards.

Did you remember to try this? When your display is resized, remove your font from memory with al_destroy_font(), reload it, and see if the problem persists.If it does, that would be just plain weird.

Kris, Allegro 5 does this for you if you do not set the ALLEGRO_NO_PRESERVE_TEXTURE flag when you load new fonts. OpenGL does not suffer this problem. Are you really gonna reload everything every time someone resizes the window? Seems silly.

However, your advice about destroying and reloading the font may help as a diagnostic tool to figure out what is wrong with al_acknowledge_resize for him, if anything.

Edit
APrince, did you ever call al_acknowledge_resize()?

Edit2
I'm a dummy. I was testing al_acknowledge_resize, not al_resize_display like the OP said. Regardless, I redid the test code, and al_resize_display does not corrupt my font either.

Also, when a window that has been resized closes, there are all kinds of lines shown on the screen buffer.

Updated test code :

#SelectExpand
1 2 3 4 5#include <stdio.h> 6#include <cmath> 7#include <allegro5/allegro.h> 8#include <allegro5/allegro_opengl.h> 9#include <allegro5/allegro_font.h> 10#include <allegro5/allegro_ttf.h> 11#include <allegro5/allegro_direct3d.h> 12 13#define SCRW 800 14#define SCRH 600 15 16 17int display_width; 18int display_height; 19 20 21int main(int argc, char **argv) 22{ 23 ALLEGRO_DISPLAY *display; 24 ALLEGRO_EVENT_QUEUE *queue; 25 ALLEGRO_TIMER *timer; 26 27 if (!al_init()) 28 { 29 fprintf(stdout,"Could not init Allegro.\n"); 30 return 1; 31 } 32 33 al_install_keyboard(); 34 al_install_mouse(); 35 al_init_font_addon(); 36 al_init_ttf_addon(); 37 38 int renderer = ALLEGRO_OPENGL; 39 al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE | renderer); 40 display_width = SCRW; 41 display_height = SCRH; 42 display = al_create_display(display_width, display_height); 43 if (!display) 44 { 45 fprintf(stdout,"Could not create display.\n"); 46 return 1; 47 } 48 49 timer = al_create_timer(1.0 / 60.0); 50 51 //al_set_window_position(display,320,240); 52 queue = al_create_event_queue(); 53 al_register_event_source(queue, al_get_keyboard_event_source()); 54 al_register_event_source(queue, al_get_display_event_source(display)); 55 al_register_event_source(queue, al_get_mouse_event_source()); 56 al_register_event_source(queue, al_get_timer_event_source(timer)); 57 58 ALLEGRO_COLOR black = al_map_rgb(0,0,0); 59 ALLEGRO_COLOR white = al_map_rgb(255,255,255); 60 ALLEGRO_COLOR red = al_map_rgb(255,0,0); 61 ALLEGRO_COLOR green = al_map_rgb(0,255,0); 62 ALLEGRO_COLOR blue = al_map_rgb(0,0,255); 63 64 ALLEGRO_FONT* font1 = al_load_ttf_font("verdana.ttf" , 20 , 0); 65 if (!font1) { 66 printf("Could not load font 1.\n"); 67 return 1; 68 } 69 70 bool redraw = true; 71 bool quit = false; 72 bool switch_out = false; 73 74 al_start_timer(timer); 75 76 do { 77 78 if (redraw && !switch_out) { 79 al_set_target_bitmap(al_get_backbuffer(display)); 80 al_clear_to_color(black); 81 82 //font color x y flags text 83 84 al_draw_text(font1 , white , 0 , 0 , 0 , "abcdefghijklmnopqrstuvwxyz"); 85 al_draw_text(font1 , white , 0 , 20 , 0 , "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 86 al_draw_text(font1 , white , 0 , 40 , 0 , "1234567890!@#$%^&*()"); 87 88 al_flip_display(); 89 redraw = false; 90 } 91 92 do { 93 ALLEGRO_EVENT ev; 94 al_wait_for_event(queue , &ev); 95 96 if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE) { 97 printf("Display resize event.\n"); 98 al_acknowledge_resize(display); 99 redraw = true; 100 } 101 if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { 102 if (ev.keyboard.keycode == ALLEGRO_KEY_B) { 103 al_resize_display(display , SCRW , SCRH); 104 } 105 else if (ev.keyboard.keycode == ALLEGRO_KEY_S) { 106 al_resize_display(display , SCRW/2 , SCRH/2); 107 } 108 } 109 110 111 if (ev.type == ALLEGRO_EVENT_DISPLAY_LOST) { 112 printf("Display Lost\n"); 113 } 114 if (ev.type == ALLEGRO_EVENT_DISPLAY_FOUND) { 115 printf("Display Found\n"); 116 } 117 if (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN) { 118 printf("Display Switch In\n"); 119 switch_out = false; 120 } 121 if (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) { 122 printf("Display Switch Out\n"); 123 switch_out = true; 124 } 125 if (ev.type == ALLEGRO_EVENT_TIMER) { 126 redraw = true; 127 } 128 if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 129 quit = true; 130 break; 131 } 132 if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { 133 if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { 134 quit = true; 135 break; 136 } 137 } 138 139 } while (!al_is_event_queue_empty(queue)); 140 141 142 143 } while (!quit); 144 145 146 return 0; 147}

Press b to make the window big, and s to make the window small. These call al_resize_display. Otherwise, the prog remains the same.

Edit3
Forgot to say I am on Vista using MinGW 4.5.0 and the 5.1.4 binaries.

Kris Asick
Member #1,424
July 2001

Quote:

ALLEGRO_NO_PRESERVE_TEXTURE
Normally, every effort is taken to preserve the contents of bitmaps, since Direct3D may forget them.

This comes from the A5 Manual. The words "every effort" suggest to me that on some systems this process may not work properly, so I add this flag to all of my bitmaps and take matters into my own hands. ;)

At least, I would if I was still working in Direct3D. Once I started working with fragment shaders I had to settle with using OpenGL strictly and thus it's not a problem anymore. :P

However, the fact that going with OpenGL didn't solve APrince's problem is strange and suggests something else may be going on. Allegro's font routines are clearly drawing text properly and the data for the positioning of the missing glyphs is still present in memory, which means it must also still be reading the characters properly.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Matthew Leverton
Supreme Loser
January 1999
avatar

Somebody recently complained of missing glyphs on Stack Overflow. Using memory bitmaps worked fine.

APrince
Member #12,698
March 2011

jmasterx: The problem is not with the screen contents, I need to redraw the window anyway. The problem is that some character are just not drawn anymore even if I redraw it. Then there's just a blank gap just as wide as the letter should be. Bu it is not there!

Elias: I'll try to make some.

Edgar: I'll try it out and let you know.

Kris Asick: I'll try. But it seems strange to me that only some characters would go missing. I am pretty sure that reloading the font will fix the problem but I am interested in the reason as well. I mean it is common thing for the window to get resized and I don't like the idea of loading all the fonts over and over again...

//edit: sorry, I posted the reply to the window loaded from yesterday without refreshing so I hadn't seen all the new posts. I'll try the new code.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

APrince
Member #12,698
March 2011

Well I tried the code. It works fine. No characters are missing.

APrince, did you ever call al_acknowledge_resize()?

No.

I'm on Win7 64 bit. And I don't use minGW but Visual Studio 2010 with windows binaries for Visual studio generated by Michał Cichoń. The version is 5.0.8 but with 5.0.6 it behaved exactly the same way.

And so far I was not able to generate an example for you because it seems to be dependent on many things. For example calling a method that has nothing to do with Allegro at all causes some more characters to disappear but another ones to appear again*. Normally I would consider that a memory corruption but: How would calling some more code make the character visible again? Second: If I do not call the al_resize_display nothing will disappear no matter what I do with the rest of the code. It is really REALLY strange.

*by appear I mean that the ones that were not visible before are now visible and some other that were visible are now blank.

I will try to dig up more...

//edit:
1) If I use the font right before calling al_resize_display. The characters will not disappear. What is even more strange is that only those characters that I use will not disappear. For example in my case the letter 'u' in

"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

is missing. Which means only:

"abcdefghijklmnopqrst vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

...is rendered. If I print

"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

before calling resize. 'u' will not disappear after calling resize. If I however print only:

"abcdefghijklmnopqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ('u' is missing)

then 'u' will be missing after al_resize_display as usual.

2) reloading the font fixes the problem as expected.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Uhm, I guess you could try the binaries for 5.1.4 with your project and see if it does it too. Then we can confirm it is not an allegro problem or else it is one that is persistent.
Allegro 5.1.4 binaries

I just read your edit.

I believe it is due to the fonts not being cached properly. They are cached on demand as you use them, so if you use them all then they will all be in dual memory mode and fully recoverable upon display resize.

The problem comes in where the glyphs were not cached. They can't be restored properly because they may even be uninitialized.

Have you tried a debug build? Run it through the debugger and see if it barks at you for anything.

APrince
Member #12,698
March 2011

OK, I'll try 5.1.4...

As for the debug version: I have. If it is the log you are interested in, I have attached it in the old thread referenced by my first post. I don't however remember the state it was in back there so I may need to generate another one. I'll write as soon as I learn something.

//edit: hm, I'm not able to run 5.1.4 it will not pass through al_init(). Also the log file seems not to be generated at all (probably because it crashes too early in init())

Kris Asick
Member #1,424
July 2001

This may seem like a dumb question but... what's your system specs?

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

APrince
Member #12,698
March 2011

Kris Asick: That should not be a problem: Phenom X3, 8 GB DDR3, GTX460.

Edgar: Hm, can you please explain a bit further? From which point in the code do you want the backtrace? I am a bit confused about that. And what do you mean by 'bt 1 full', that misses me entirely...

Thanks

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You said init() crashes? Did you mean al_init() crashes too? A backtrace from there. And 'bt 1 full' is just GnuDeBugger shorthand for 'backtrace 1 full' as in tell me everything in the lowest frame on the stack.

So I guess in the MSVC debugger it would be show me the stack when it crashes, and examine the lowest frame with the debugger.

APrince
Member #12,698
March 2011

OK, thanks for the explanation. I'll do that in the morning (there's 2 o'clock am local time :-) ).

//edit: Well I have realized I might not have expressed myself quite correctly: By init i meant al_init() but it does not crash, i just returns false meaning the initialization failed. There's no more info about what went wrong and there's no log generated.

//edit2: I will continue yesterday, I'm kinda busy till then.

//edit3: I will try another computer, see if there's any difference and let you know.

//edit4: OK so I made some progress. I was somehow able to run 5.1.4 (well it was probably enough just to rebuild the solution which hadn't cross my mind before). The result is... It is exactly the same as with 5.0.6 and 5.0.8.

I also tried it on another computer. It is the same, only different characters are missing...

This has to be some caching problem as you said... I just can't explain that in any other way.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Well, try what ML suggested a while ago, try loading the font as memory bitmaps. al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP). See if the font still dies when you resize.

Otherwise, the thing that bothers me is that my example code works for you but your own program does not. So I can't rule out it isn't your program yet.

IDK. Can you upload your project source files in a zip/7z file? I can look at them briefly and see if I notice anything obvious.

APrince
Member #12,698
March 2011

Well I tried setting the flag. When I do that no text is rendered at all. Above all, it messes the rest of the window content in a completely strange way. Can't even describe that (no images are rendered and primitives are... well, messed up). This happens with 5.1.4 as well as with 5.0.8. I attached the log from 5.0.8.

To be able to show you the code I will have to change it a bit, because the window resize is dependent on a certain serial port device connection. Will have to change that dependency so that the resize is called anyway. I will upload it as soon as I 'm done with that.

Thanks

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

allegro.log said:

font D ttf.c:786 al_load_ttf_font_stretch_f [ 0.29753] Font fonts/titilliumtext25l001.ttf loaded with pixel size 0 x 12.
font D ttf.c:788 al_load_ttf_font_stretch_f [ 0.29755] ascent=11.0, descent=-3.0, height=15.0
dtor D dtor.c:184 _al_register_destructor [ 0.29757] added dtor for object 02F6F970, func 0F061B63
font D ttf.c:786 al_load_ttf_font_stretch_f [ 0.30116] Font fonts/titilliumtext25l001.ttf loaded with pixel size 0 x 13.
font D ttf.c:788 al_load_ttf_font_stretch_f [ 0.30118] ascent=12.0, descent=-3.0, height=16.0
dtor D dtor.c:184 _al_register_destructor [ 0.30119] added dtor for object 02F818B8, func 0F061B63
font D ttf.c:786 al_load_ttf_font_stretch_f [ 0.30834] Font fonts/titilliumtext25l002.ttf loaded with pixel size 0 x 13.
font D ttf.c:788 al_load_ttf_font_stretch_f [ 0.30836] ascent=12.0, descent=-3.0, height=16.0
dtor D dtor.c:184 _al_register_destructor [ 0.30837] added dtor for object 02FF3CC0, func 0F061B63
font D ttf.c:786 al_load_ttf_font_stretch_f [ 0.36182] Font fonts/tahoma.ttf loaded with pixel size 0 x 12.
font D ttf.c:788 al_load_ttf_font_stretch_f [ 0.36184] ascent=12.0, descent=-2.0, height=14.0
dtor D dtor.c:184 _al_register_destructor [ 0.36186] added dtor for object 03026F90, func 0F061B63
font D ttf.c:786 al_load_ttf_font_stretch_f [ 0.40540] Font fonts/tahoma.ttf loaded with pixel size 0 x 13.
font D ttf.c:788 al_load_ttf_font_stretch_f [ 0.40542] ascent=13.0, descent=-3.0, height=16.0
dtor D dtor.c:184 _al_register_destructor [ 0.40544] added dtor for object 030094B0, func 0F061B63
font D ttf.c:786 al_load_ttf_font_stretch_f [ 0.45055] Font fonts/tahoma.ttf loaded with pixel size 0 x 15.
font D ttf.c:788 al_load_ttf_font_stretch_f [ 0.45057] ascent=15.0, descent=-3.0, height=18.0
dtor D dtor.c:184 _al_register_destructor [ 0.45059] added dtor for object 0305AA88, func 0F061B63
font D ttf.c:786 al_load_ttf_font_stretch_f [ 0.45431] Font fonts/titilliumtext25l002.ttf loaded with pixel size 0 x 10.
font D ttf.c:788 al_load_ttf_font_stretch_f [ 0.45432] ascent=9.0, descent=-2.0, height=12.0
dtor D dtor.c:184 _al_register_destructor [ 0.45434] added dtor for object 0306EBC8, func 0F061B63
font D ttf.c:786 al_load_ttf_font_stretch_f [ 0.45796] Font fonts/titilliumtext25l002.ttf loaded with pixel size 0 x 9.
font D ttf.c:788 al_load_ttf_font_stretch_f [ 0.45798] ascent=8.0, descent=-2.0, height=11.0
dtor D dtor.c:184 _al_register_destructor [ 0.45799] added dtor for object 0309B5E8, func 0F061B63
font D ttf.c:786 al_load_ttf_font_stretch_f [ 0.46155] Font fonts/titilliumtext25l002.ttf loaded with pixel size 0 x 20.
font D ttf.c:788 al_load_ttf_font_stretch_f [ 0.46156] ascent=19.0, descent=-5.0, height=24.0
dtor D dtor.c:184 _al_register_destructor [ 0.46158] added dtor for object 030AB230, func 0F061B63

The "loaded with pixel size 0 x #" entries seem suspicious. But you aren't loading your fonts with a width of zero are you? That would be silly.

I don't see what is wrong though, as alloc_glyph_region calls seem right later in the log....

APrince
Member #12,698
March 2011

The "loaded with pixel size 0 x #" entries seem suspicious. But you aren't loading your fonts with a width of zero are you? That would be silly.

But how would I do that? The prototype of the function looks like this:

ALLEGRO_TTF_FUNC(ALLEGRO_FONT *, al_load_ttf_font, (char const *filename, int size, int flags));

there's just the size parameter that allows me to specify the size. There's no width or height.

I will try to exchange the font for another one and see if the problem persists. I know, it seems silly but I guess we have tried all the probable possibilities. I will also try 5.0.1 or something like that, before the version of the library that generates the font (forgot the name) was switched. Maybe I should mention that I use the ALLEGRO_TTF_NO_AUTOHINT flag when creating the font. That has probably nothing to do with the problem since it only affects the size of the resulting glyphs but maybe it also relates to the "zero width" mentioned by you.

About the source code, I'm kinda busy today but will try to get to it. If not, I will do it tomorrow.

Thanks a lot

//edit:

OK, I've tried 5.0.1. That means I had to disable the above mentioned ALLEGRO_TTF_NO_AUTOHINT flag. But it is the same... Characters still missing. I attach the log from 5.0.1. There may be an interesting line:

Quote:

font D ttf.c:591 al_load_ttf_font_f [ 0.08597] fonts/titilliumtext25l002.ttf: Preparing cache for 400 glyphs.

...but don't really know.

//edit2:

I am now leaving for 4 days and unfortunately couldn't make it to create a version that you could run and that would demonstrate the problem. I will post it Thursday.

Thanks for everything.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I have an idea. It may be that your font is not associated with the drawing context of the window you are trying to draw to. I played around with this idea a little bit, and for me it resulted in very slow drawing, and missing glyphs during a resize that went away briefly after that. Try the code below and see what I mean. The font was loaded while the first (left) display was current, so it should be associated with that one. That means you may have problems with the right display showing the text properly.

Someone else has to explain about how video bitmaps are attached to a display.

#SelectExpand
1#include <stdio.h> 2#include <cmath> 3#include <allegro5/allegro.h> 4#include <allegro5/allegro_opengl.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_ttf.h> 7#include <allegro5/allegro_direct3d.h> 8 9#define SCRW 400 10#define SCRH 300 11 12 13int display_width; 14int display_height; 15ALLEGRO_FONT* font1; 16 17void Draw(ALLEGRO_DISPLAY* d) { 18 ALLEGRO_COLOR black = al_map_rgb(0,0,0); 19 ALLEGRO_COLOR white = al_map_rgb(255,255,255); 20 21 al_set_target_bitmap(al_get_backbuffer(d)); 22 al_clear_to_color(black); 23 24 //font color x y flags text 25 26 al_draw_text(font1 , white , 0 , 0 , 0 , "abcdefghijklmnopqrstuvwxyz"); 27 al_draw_text(font1 , white , 0 , 20 , 0 , "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 28 al_draw_text(font1 , white , 0 , 40 , 0 , "1234567890!@#$%^&*()"); 29 30 al_flip_display(); 31} 32 33 34int main(int argc, char **argv) 35{ 36 ALLEGRO_DISPLAY *display1; 37 ALLEGRO_DISPLAY *display2; 38 ALLEGRO_DISPLAY *current_display; 39 ALLEGRO_EVENT_QUEUE *queue; 40 ALLEGRO_TIMER *timer; 41 42 if (!al_init()) 43 { 44 fprintf(stdout,"Could not init Allegro.\n"); 45 return 1; 46 } 47 48 al_install_keyboard(); 49 al_install_mouse(); 50 al_init_font_addon(); 51 al_init_ttf_addon(); 52 53 int renderer = ALLEGRO_OPENGL; 54 al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE | renderer); 55 display_width = SCRW; 56 display_height = SCRH; 57 58 al_set_new_window_position(640 - 400 , 234); 59 display1 = al_create_display(display_width, display_height); 60 if (!display1) 61 { 62 fprintf(stdout,"Could not create display1.\n"); 63 return 1; 64 } 65 66 al_set_new_window_position(640 , 234); 67 display2 = al_create_display(display_width, display_height); 68 if (!display2) 69 { 70 fprintf(stdout,"Could not create display2.\n"); 71 return 1; 72 } 73 74 current_display = display2; 75 76// al_resize_display(display , display_width/2 , display_height/2); 77 78 timer = al_create_timer(1.0 / 60.0); 79 80 //al_set_window_position(display,320,240); 81 queue = al_create_event_queue(); 82 al_register_event_source(queue, al_get_keyboard_event_source()); 83 al_register_event_source(queue, al_get_display_event_source(display1)); 84 al_register_event_source(queue, al_get_display_event_source(display2)); 85 al_register_event_source(queue, al_get_mouse_event_source()); 86 al_register_event_source(queue, al_get_timer_event_source(timer)); 87 88 ALLEGRO_COLOR red = al_map_rgb(255,0,0); 89 ALLEGRO_COLOR green = al_map_rgb(0,255,0); 90 ALLEGRO_COLOR blue = al_map_rgb(0,0,255); 91 92 al_set_target_bitmap(al_get_backbuffer(display1)); 93 font1 = al_load_ttf_font("verdana.ttf" , 20 , 0); 94 if (!font1) { 95 printf("Could not load font 1.\n"); 96 return 1; 97 } 98 99 bool redraw1 = true; 100 bool redraw2 = true; 101 bool quit = false; 102 bool switch_out = false; 103 104 al_start_timer(timer); 105 106 do { 107 108 if (redraw1 && !switch_out) { 109 Draw(display1); 110 redraw1 = false; 111 } 112 if (redraw2 && !switch_out) { 113 Draw(display2); 114 redraw2 = false; 115 } 116 117 do { 118 ALLEGRO_EVENT ev; 119 al_wait_for_event(queue , &ev); 120 121 if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE) { 122 printf("Display resize event.\n"); 123 ALLEGRO_DISPLAY* d = ev.display.source; 124 al_acknowledge_resize(d); 125 if (d == display1) { 126 redraw1 = true; 127 } 128 if (d == display2) { 129 redraw2 = true; 130 } 131 } 132 133 if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { 134 if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { 135 quit = true; 136 break; 137 } 138/* 139 if (ev.keyboard.keycode == ALLEGRO_KEY_B) { 140 al_resize_display(display1 , SCRW , SCRH); 141 al_resize_display(display2 , SCRW , SCRH); 142 } 143 else if (ev.keyboard.keycode == ALLEGRO_KEY_S) { 144 al_resize_display(display1 , SCRW/2 , SCRH/2); 145 al_resize_display(display2 , SCRW/2 , SCRH/2); 146 } 147*/ 148 } 149 150 151 if (ev.type == ALLEGRO_EVENT_DISPLAY_LOST) { 152 printf("Display Lost\n"); 153 } 154 if (ev.type == ALLEGRO_EVENT_DISPLAY_FOUND) { 155 printf("Display Found\n"); 156 } 157 if (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN) { 158 printf("Display Switch In\n"); 159 switch_out = false; 160 } 161 if (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) { 162 printf("Display Switch Out\n"); 163 switch_out = true; 164 } 165 if (ev.type == ALLEGRO_EVENT_TIMER) { 166// redraw = true; 167 } 168 if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 169 quit = true; 170 break; 171 } 172 if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { 173 if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { 174 quit = true; 175 break; 176 } 177 } 178 179 } while (!al_is_event_queue_empty(queue)); 180 181 182 183 } while (!quit); 184 185 186 return 0; 187}

The reason I thought this might be your problem is that you mentioned you have a second window. Any video bitmaps that were loaded on the first window will be attached to that one, so you have to load any resources you need for the second window as well.

Haven't had a chance to look at your code, 21 MB would take two hours to download here at home, so I haven't done it yet. If you upload your source code separately I can take a look at that now, but I won't be able to download the resources until later today maybe I don't know.

APrince
Member #12,698
March 2011

When did I say I use 2 displays? Well I don't. There's only one display.

Anyway it is really hard to explain the behavior of the code you posted. First of all it often does not get redrawn when being resized. When it does not I can minimize the window and show it again. The the it is redrawn when being resized but in a really strange way. Just as if the backbuffers would get flipped before drawing all of the text. And moreover just as if the text would be drawn from the back to the front. But in the end (When I let go of the mouse button) it is drawn properly. No characters missing.

Can the problem relate to the number of the fonts I have currently loaded? Because I have 9 fonts loaded at the same time (well actually only 2 types, but in different sizes). And only two of them has have the problem with missing characters.

//edit: OK, I made some progress simplifying the code and... I found this once more related to the calling of the al_get_text_width function. Here is the quotation from the previous thread:

Quote:

I don't have a clue of what's this about because it seems so random. I also noticed that it seems to be related with the text aligned to the center and thus to calling al_get_text_width. Well I checked the result of this function and it always seems to return the correct width, the only problem is that the consequential text drawing (like x - text_width/2) will fail to print some letters, although their positions are correct. If I replace all the al_get_text_width calls the constants they return it seems* to work fine.

Well I kinda forgot about this but now I am back at this again. Somewhere deep in my code I use string wrapping for which I need to know the width of the the text in order to slice it into the correctly sized lines. Now here is the significant statement for which I stand: "If I do not call al_get_text_width() with some particular font, NO characters of this font will EVER get missing."

Now do you know how could calling this method "damage" the font? This is strange because a function like this should be essentially read-only. Anyway calling this method is not enough. You also need to resize the window. This leads me to the opinion, that it somehow caches out some info which may than get lost when resizing the window.

As soon as I'm done with making a simple example that would demonstrate this problem, I will post it. But I will probably not make it till monday (I'm doing dance show at a ball and I'm kinda short on time :-D).

//edit2: Finally! So, to make the example for you. Just take the first code you posted - the one from the beginning of the thread - and place these lines before the do-while loop:

al_get_text_width(font1, "abcdefghijklmnopqrstuvwxyz");
al_resize_display(display, SCRW, SCRH + 20);

For me it results in lowercase 'y' and 'z' missing. If I replace those letters for uppercase, then 'UVWXYZ' will be missing, but no lowercase letters. The connection is obvious. Only those letter used with al_get_text_width may get missing, as I stated before.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

 1   2   3 


Go to: