[Allegro 5.1] Possible bug on al_set_new_window_position

I guess I mentioned this before, but it's still present on r15031.

Using al_set_new_window_position() seems to place the window slightly off on my machine. It's easier to see when you use al_set_new_window_position(0, 0). It happens with both Direct3D and OpenGL in windowed mode. Something similar happens with OpenGL when using ALLEGRO_FULLSCREEN_WINDOW even if al_set_new_window_position() is not present.

Can someone confirm this? or perhaps it only happens on my machine?. I'm using Windows XP and I have an old integrated Intel graphics card.

Trent Gamblin

I'm looking at it now and there's definitely a bug. I've found the source I think, unless there are multiple issues. I'll look into a fix.


Yep, I have the same problem...

Off-topic: Have you notice that Allegro 5.2 will have a video addon? sweeeeeet!.

Trent Gamblin

Can someone test this patch before I commit it?


Well, I tried with WinMerge but it doesn't work, only compares files with files or folders with folder, which software are you using to generate/treat that .diff file?, I have never seen something like that before.

I guess isn't to big, I could do it manually.

... I changed my mind, it's more complicated than I thought. :o

Trent Gamblin

You need GNU patch to apply that diff. From your Allegro directory, simply

patch -p0 < winpos.diff

But Windows can have issues with programs named patch.exe (no clue why) so I rename it p.exe or something.


I put it on the main folder and I got this:

C:\Users\Armando>cd c:/a5.1

c:\a5.1>pa -p0 < winpos.diff
patching file src/win/wwindow.c
Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Then I put the files (pa.exe and winpos.diff) inside win and I got this:

C:\Users\Armando>cd c:/a5.1/src/win

c:\a5.1\src\win>pa -p0 < winpos.diff
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
|Index: src/win/wwindow.c
|--- src/win/wwindow.c  (revision 15027)
|+++ src/win/wwindow.c  (working copy)
File to patch: wwindow.c <-- Here I typed the file to see what happens but nothing.
patching file wwindow.c
missing header for unified diff at line 18 of patch
can't find file to patch at input line 18
Perhaps you used the wrong -p or --strip option?
File to patch:

Trent Gamblin

Dangit, I probably didn't svn up before making the patch. I'll upload a new one. Make sure to svn revert any changes the failed attempts made.

[edit] Attached.


Tested on Windows XP. It fixes the ALLEGRO_FULLSCREEN_WINDOW issue but for normal windowed mode it seems to position the display at the right position but it doesn't take into account the title bar, so for al_set_new_window_position(0, 0) the whole title bar is left out of the screen.

Trent Gamblin

Ok good, because that's the documented behavior :). There needs to be a way to get border sizes though I think.


Oh, in that case it's OK; although, by the name of the function, one could expect it to set the whole window position, but as long as it's clearly stated in the documentation I guess it's not so bad.

One more thing though, I just checked and it seems like ALLEGRO_NOFRAME also presents this issue (with and without the patch). Actually, there's a difference with the patch and without it, but both result in a misplaced window.

Trent Gamblin

Here's a patch which should fix that issue too (it incorporates all of the previous changes too). Would appreciate a quick test! Thanks.


The new patch fixes the ALLEGRO_NOFRAME issue on Direct3D but not on OpenGL.

In fact, it's weird; the window size is the same with both OpenGL and Direct3D but while the OpenGL window position is correct, the position for drawing bitmaps is wrong. With Direct3D, on the other hand, looks like bitmaps are automatically scaled.

In both of the following screenshots, the bitmap is drawn at (0, 0). The actual bitmap size is 248x324, so apparently OpenGL is the one drawing it with the right size.

Using OpenGL:

Using D3D:

If someone could confirm this on recent hardware, it would be great as it may only affect ancient hardware like mine.

[OFF-TOPIC:] AMCerasoli, you should try the patch.exe included in MSYS, if you have it installed, that is.

Trent Gamblin

Can you post your example above so I can fix it? Thanks.


This is the code I used. I added some primitives and changed the window size. Basically, all operations when using Direct3D are correct except for the automatic scaling (haven't checked what it does if I explicitly call al_draw_scaled_bitmap()).

1#include <allegro5/allegro.h> 2#include <allegro5/allegro_opengl.h> 3#include <allegro5/allegro_primitives.h> 4 5ALLEGRO_DISPLAY *display = NULL; 6ALLEGRO_EVENT_QUEUE *events = NULL; 7ALLEGRO_BITMAP *bmp = NULL; 8 9int main() { 10 uint32_t v; 11 12 al_init(); 13 al_install_keyboard(); 14 al_set_new_display_flags(ALLEGRO_NOFRAME | ALLEGRO_OPENGL); 15 al_set_new_window_position(0, 0); 16 display = al_create_display(640, 480); 17 al_init_primitives_addon(); 18 al_init_image_addon(); 19 20 v = al_get_allegro_version(); 21 printf("Allegro version: %d.%d.%d[%d]\n", v >> 24, (v >> 16) & 255, (v >> 8) & 255, v & 255); 22 23 events = al_create_event_queue(); 24 assert(events); 25 al_register_event_source(events, al_get_keyboard_event_source()); 26 27 bmp = al_load_bitmap("ken.jpg"); 28 assert(bmp); 29 30 while (al_is_event_queue_empty(events)) { 31 al_clear_to_color(al_map_rgb(0, 128, 128)); 32 al_draw_bitmap(bmp, 0, 0, 0); 33 al_draw_rectangle(0.5, 0.5, 640, 480, al_map_rgb(255, 255, 255), 1); 34 al_draw_rectangle(0.5, 0.5, 248, 324, al_map_rgb(0, 0, 255), 1); 35 al_flip_display(); 36 al_rest(0.015); 37 } 38}

Trent Gamblin

Here's another patch. Hope everything's right now.

Edit: Just so you know, if you want to draw the rectangle on the last pixel of the display, you should use "-0.5". So it's your example that has the bug of not displaying the right and bottom pixels of the rectangle. Allegro is doing it right from my tests (adding -0.5 to those numbers).


Everything seems to be fine now.

Just so you know, if you want to draw the rectangle on the last pixel of the display, you should use "-0.5".

Oh, yeah. I'm aware of that.


Trent Gamblin

Thanks for your help.


Yhea I have also downloaded the two files and checked and it works fine.

[OFF-TOPIC:] AMCerasoli, you should try the patch.exe included in MSYS, if you have it installed, that is.

Thanks man!, I didn't know that was there... I used the files uploaded by Trent because it was simpler.

Thread #608603. Printed from Allegro.cc