Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » [Allegro 5.1] Possible bug on al_set_new_window_position

This thread is locked; no one can reply to it. rss feed Print
[Allegro 5.1] Possible bug on al_set_new_window_position
kenmasters1976
Member #8,794
July 2007

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
Member #261
April 2000
avatar

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.

AMCerasoli
Member #11,955
May 2010
avatar

Yep, I have the same problem...

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

Trent Gamblin
Member #261
April 2000
avatar

Can someone test this patch before I commit it?

AMCerasoli
Member #11,955
May 2010
avatar

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.

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

Trent Gamblin
Member #261
April 2000
avatar

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.

AMCerasoli
Member #11,955
May 2010
avatar

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
Member #261
April 2000
avatar

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.

kenmasters1976
Member #8,794
July 2007

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
Member #261
April 2000
avatar

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

kenmasters1976
Member #8,794
July 2007

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
Member #261
April 2000
avatar

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

kenmasters1976
Member #8,794
July 2007

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:
{"name":"winposbogl.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/8\/a8e06f8a29b4276d9155d19452433f04.png","w":486,"h":672,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/8\/a8e06f8a29b4276d9155d19452433f04"}winposbogl.png

Using D3D:
{"name":"winposbd3d.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/2\/9202ad1883ef9116de80cb04d1d22498.png","w":486,"h":672,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/2\/9202ad1883ef9116de80cb04d1d22498"}winposbd3d.png

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
Member #261
April 2000
avatar

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

kenmasters1976
Member #8,794
July 2007

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()).

#SelectExpand
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
Member #261
April 2000
avatar

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).

kenmasters1976
Member #8,794
July 2007

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.

Thanks.

Trent Gamblin
Member #261
April 2000
avatar

Thanks for your help.

AMCerasoli
Member #11,955
May 2010
avatar

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.

Go to: