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

Thanks, I'll wait.

Kris Asick
Member #1,424
July 2001

Have you tried your code on other computers yet, APrince?

Also, just a thought: What happens if you draw your text, resize the display, draw text again to see which characters are missing, then resize the display AGAIN, and draw the text again to see if the exact same or different characters are missing?

Also, you say you're using VC2010. So do I, and a problem I ran into when I released the previous public alpha of my game was that the energy bar was going extremely wonky. Turned out there was absolutely nothing wrong with the code, it just needed to be rebuilt entirely. IE: Using VC2010's "Rebuild All" function as opposed to just clicking "Build".

There may also be optimization problems. Have you tried compiling with zero code optimizations from your project properties?

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

APrince
Member #12,698
March 2011

Have you tried your code on other computers yet, APrince?

APrince said:

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

Also, just a thought: What happens if you draw your text, resize the display, draw text again to see which characters are missing, then resize the display AGAIN, and draw the text again to see if the exact same or different characters are missing?

I will try that but I guess that the same characters will be missing. The point is that if I change anything (doesn't have to be anything related to text drawing) and build the project again, different characters are usually missing. Not always though it depends on how "big" the change is. Well i explain this to myself by different cache usage of the two builds. Anyway the key is the al_get_text_width() method. I'm sure. When it is not called, no characters will ever get missing.

Quote:

Also, you say you're using VC2010. So do I, and a problem I ran into when I released the previous public alpha of my game was that the energy bar was going extremely wonky. Turned out there was absolutely nothing wrong with the code, it just needed to be rebuilt entirely. IE: Using VC2010's "Rebuild All" function as opposed to just clicking "Build".

I know, I run into this problem from time to time as well. But this is not the case as could be deduced from the fact, that I also had to create the example that I posted and that is another solution and thus a different build.

Quote:

There may also be optimization problems. Have you tried compiling with zero code optimizations from your project properties?

In the debug build, optimizations are disabled by default in VS and I haven't changed it. Well I have also checked that now for you, and yes, they are disabled.

Peter Wang
Member #23
April 2000

Can you try to debug, since you can reproduce it? I would first change the last parameter of the cache_glyph calls from true to false, in ttf_text_length and ttf_get_text_dimensions. See if it changes anything.

Elias
Member #358
May 2000

Mostly off topic but just in case some bigger changes will be needed to the ttf addon and someone is going to hack it up - please fix the issue where no glyph can be bigger than 256x256 pixels and also make it waste less video memory - currently it uses a lot more than necessary :)

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

Kris Asick
Member #1,424
July 2001

Hey yeah, that's a good question. APrince, do you still have this character-missing problem with bitmapped fonts or only with Truetype fonts?

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

APrince
Member #12,698
March 2011

Can you try to debug, since you can reproduce it? I would first change the last parameter of the cache_glyph calls from true to false, in ttf_text_length and ttf_get_text_dimensions. See if it changes anything.

And am I able to debug? I would have to build the allegro, or wouldn't I? I use windows binaries downloaded from the release thread. Either way, you would have to elaborate more on what do you want me to do cause I don't know anything about glyph cache or whatever...

APrince, do you still have this character-missing problem with bitmapped fonts or only with Truetype fonts?

I have never used bitmapped fonts. I may try it but no sooner than tomorrow since I'm not at home and cannot access my computer...

Peter Wang
Member #23
April 2000

Debugging means digging into the code and finding out the actual cause of the issue, if not actually fixing it. It's hard for people who can't reproduce a bug to fix it just by reading the code and guessing. Obviously you will have to be able to modify and build Allegro.

The code is in ttf.c. You don't always need a complete understanding of the code. It's how everyone gets started.

APrince
Member #12,698
March 2011

Yes, I actually didn't need the explanation of what the debugging is but what to debug. The point is that I don't think I can debug the dll supplied in Windows binaries release, but You answered that anyway. The problem is that to build allegro there are lot of libraries required. I already tried that but I just couldn't make all the libraries to work together. But I will try again...

Anyway has anyone tried to reproduce the problem? I think it should be possible since I can do it on 2 computers... Just take this code:

#SelectExpand
1 2#include <stdio.h> 3#include <cmath> 4#include <allegro5/allegro.h> 5#include <allegro5/allegro_opengl.h> 6#include <allegro5/allegro_font.h> 7#include <allegro5/allegro_ttf.h> 8#include <allegro5/allegro_direct3d.h> 9 10#define SCRW 800 11#define SCRH 600 12 13 14int display_width; 15int display_height; 16 17 18int main(int argc, char **argv) 19{ 20 ALLEGRO_DISPLAY *display; 21 ALLEGRO_EVENT_QUEUE *queue; 22 ALLEGRO_TIMER *timer; 23 24 if (!al_init()) 25 { 26 fprintf(stdout,"Could not init Allegro.\n"); 27 return 1; 28 } 29 30 al_install_keyboard(); 31 al_install_mouse(); 32 al_init_font_addon(); 33 al_init_ttf_addon(); 34 35 int renderer = ALLEGRO_DIRECT3D; 36 al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE | renderer); 37 display_width = SCRW; 38 display_height = SCRH; 39 display = al_create_display(display_width, display_height); 40 if (!display) 41 { 42 fprintf(stdout,"Could not create display.\n"); 43 return 1; 44 } 45 46 timer = al_create_timer(1.0 / 60.0); 47 48 //al_set_window_position(display,320,240); 49 queue = al_create_event_queue(); 50 al_register_event_source(queue, al_get_keyboard_event_source()); 51 al_register_event_source(queue, al_get_display_event_source(display)); 52 al_register_event_source(queue, al_get_mouse_event_source()); 53 al_register_event_source(queue, al_get_timer_event_source(timer)); 54 55 ALLEGRO_COLOR black = al_map_rgb(0,0,0); 56 ALLEGRO_COLOR white = al_map_rgb(255,255,255); 57 ALLEGRO_COLOR red = al_map_rgb(255,0,0); 58 ALLEGRO_COLOR green = al_map_rgb(0,255,0); 59 ALLEGRO_COLOR blue = al_map_rgb(0,0,255); 60 61 ALLEGRO_FONT* font1 = al_load_ttf_font("titilliumtext25l002.ttf" , 20 , 0); 62 if (!font1) { 63 printf("Could not load font 1.\n"); 64 return 1; 65 } 66 67 bool redraw = true; 68 bool quit = false; 69 bool switch_out = false; 70 71 al_start_timer(timer); 72 73 al_get_text_width(font1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 74 al_resize_display(display, SCRW, SCRH + 20); 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}

The problem is there for all the Allegro version I have tried (5.0.1, 5.0.6, 5.0.8, 5.1.4)

//edit: I have been trying to test it with allegro bitmap font as proposed by Kris Asick, but I just cannot find out how it works. There's no line in the documentation or tutorials (or at least in those I was able to come). What format should the bitmap have?

Kris Asick
Member #1,424
July 2001

https://d1cxvcw9gjxu2x.cloudfront.net/attachments/607221

Here's a bitmapped font I made for a game I'm likely never going to make, properly formatted for A5 usage. (IE: Has a completely transparent background.) It only covers glyphs 32 through 127. If you want to make your own, just use this one as an example and follow this approach:

  • Arrange all glyphs on a grid.

  • The pixel at coordinates 0,0 represents what pixels to ignore.

  • All other pixels will represent glyphs, formed in boxes, including white-space between each glyph.

Information on how to make bitmapped fonts for Allegro can also be found in the A4 documentation. (But yeah, the info really should be added to A5 eventually.)

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

Thomas Fjellstrom
Member #476
June 2000
avatar

APrince said:

The problem is that to build allegro there are lot of libraries required. I already tried that but I just couldn't make all the libraries to work together. But I will try again...

I think someone has all the dependencies already build which should make it a whole lot easier.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Peter Wang
Member #23
April 2000

APrince said:

Anyway has anyone tried to reproduce the problem? I think it should be possible since I can do it on 2 computers... Just take this code:

Thanks, I can finally reproduce it with Direct3D.

Trent, how does this look?

#SelectExpand
1diff --git a/src/win/d3d_disp.cpp b/src/win/d3d_disp.cpp 2index f30a405..6002895 100644 3--- a/src/win/d3d_disp.cpp 4+++ b/src/win/d3d_disp.cpp 5@@ -2300,11 +2300,14 @@ static bool d3d_resize_helper(ALLEGRO_DISPLAY *d, int width, int height) 6 7 static bool d3d_resize_display(ALLEGRO_DISPLAY *d, int width, int height) 8 { 9+ ALLEGRO_DISPLAY_D3D *d3d_display = (ALLEGRO_DISPLAY_D3D *)d; 10 ALLEGRO_DISPLAY_WIN *win_display = (ALLEGRO_DISPLAY_WIN *)d; 11 int orig_w = d->w; 12 int orig_h = d->h; 13 bool ret; 14 15+ _al_d3d_prepare_bitmaps_for_reset(d3d_display); 16+ 17 win_display->ignore_resize = true; 18 19 if (!d3d_resize_helper(d, width, height)) {

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

APrince
Member #12,698
March 2011

Good, I've been getting paranoid about this. But isn't it strange that this bug lasts from the first Allegro 5 and nobody has noticed since then? It's like nobody ever used those two functions together... Which is improbable, I'd say.

Thomas Fjellstrom
Member #476
June 2000
avatar

It's probably just one of those problems that only happens under certain circumstances, and you were lucky enough to have a machine that fulfilled all the prerequisites.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Trent Gamblin
Member #261
April 2000
avatar

Can someone who can reproduce the problem please try Peter's patch?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Sorry, but I can't get al_init() to even run with the latest git for A5.1. It just keeps failing, and even though I linked to debugging versions and defined DEBUG, there is no allegro.log file. I don't get it, A5.1.4 works fine for me, there can't be that much different? Maybe it is a binary incompatibility, but I made sure to copy the new dll's into the folder where the exe is. So I don't know what's wrong. I would test it if I could.

Trent Gamblin
Member #261
April 2000
avatar

Edgar, you've likely got old headers kicking around somewhere so the version check fails.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Okay, that was it Trent, searching the wrong dir for includes and the system include directory has old a5 headers. Oopsie. Anyway, the patch seems to have fixed the problem. I don't get any missing characters now like I did before with 5.1.4.

Trent Gamblin
Member #261
April 2000
avatar

There you go Peter. Should be ok to apply.

Peter Wang
Member #23
April 2000

Ok, will do later. Thanks.

Trent Gamblin
Member #261
April 2000
avatar

Oh and thanks Edgar. :)

APrince
Member #12,698
March 2011

Thanks. I suppose the patch will be applied to a new Allegro release... Right?

And... thanks again.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

APrince
Member #12,698
March 2011

Sorry for the late answer I have been ill for some time now. OK, I will try. If I do not write anything it either means I had no problem with that (unlikely) or I died trying (or possibly left to see, became a sailor and have no desire in programming anything ever after :-D ).

 1   2   3 


Go to: