Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Drawing Issue

This thread is locked; no one can reply to it. rss feed Print
Drawing Issue
Morshock
Member #16,875
July 2018

Hello,
I'm new to Allegro and I'm having an issue while drawing bitmap or primitives.
It seems like the drawing at the bottom of the display is not full drawn unless i use "al_flip_display () ;" 2 times.
While reading al_flip_display() I wasn't under the impression that this is how it's supposed to work and I've not found anything on the forums.
I don't know it this will be useful however: I'm running this program on VM with Ubuntu 16.04, have the 5.2.4 version of Allegro and using g++ to compile the code.
I've also uploaded the image which is 512x512 pixel to fit the dimension of the display I've created.
I don't really know if this is how it's supposed to work or I've messed up something.
Thank you for your time.

Regards.

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_image.h> 3 4using namespace std ; 5 6const char ChessBoardPath [] = "./Media/Images/ChessBoard.png" ; 7const int Dimensions = 512 ; 8 9int main () 10{ 11 al_init () ; 12 al_init_image_addon () ; 13 14 ALLEGRO_MONITOR_INFO Monitor ; 15 al_get_monitor_info (0, &Monitor) ; 16 al_set_new_window_title ("Test") ; 17 al_set_new_window_position (Monitor.x2 / 2 - Dimensions / 2, Monitor.y2 / 2 - Dimensions / 2) ; 18 19 20 ALLEGRO_DISPLAY * Display = al_create_display (Dimensions, Dimensions) ; 21 22 ALLEGRO_BITMAP * Frame = al_load_bitmap (ChessBoardPath) ; 23 24 al_draw_bitmap (Frame, 0, 0, 0) ; 25 al_flip_display() ; 26 27 sleep (10.0) ; 28 29 al_clear_to_color (al_map_rgb (255, 255, 255)) ; 30 al_flip_display () ; 31 32 sleep (10.0) ; 33 34 al_draw_bitmap (Frame, 0, 0, 0) ; 35 al_flip_display() ; 36 al_flip_display() ; 37 38 sleep (10.0) ; 39 40 al_clear_to_color (al_map_rgb (255, 255, 255)) ; 41 al_flip_display () ; 42 al_flip_display () ; 43 44 sleep (10.0) ; 45 46 al_destroy_bitmap (Frame) ; 47 al_destroy_display (Display) ; 48 49 return 0 ; 50}

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I think it's a bug in Allegro. I seem to recall encountering this before. It takes two flips to render the first image. It may have something to do with the buffering method in use by the allegro linux driver. All subsequent flips should work properly.

However, if you have to flip twice every time you draw something, that's a more serious bug.

Morshock
Member #16,875
July 2018

Hello,
thank you for the answer.
As now for me it seems that whenever I want to draw anything or even just use the al_clear_to_color() function, since I think it counts as "drawing", I've to use 2 flips to fully show what was drawn.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Peter Hull
Member #1,136
March 2001

It would be good if you could file a bug for this:
https://github.com/liballeg/allegro5/issues

I tried your program on macos; I saw the image for 10s and then 30s of white. So, the double flip isn't a solution for all platforms.

Also you would be better to use al_rest rather than sleep

Pete

Morshock
Member #16,875
July 2018

@Edgar Reynaldo
Respectively VirtualBox and Windows10.

@Peter Hull
Was the first image displayed correctly?
Also if in a day or two there is indication that this bug is not only affecting me and I will file the report.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Morshock
Member #16,875
July 2018

64 bit version download from Ubuntu.com
However I just noticed that I was running 17.10, now upgrading to 18.04 to see if there are any changes. I downloaded the base version of 16.04 LTS from Ubuntu site than upgraded to later version trough the Software Updater while running Ubuntu in the VM.

Update : Even in the 18.04 version the problem seems to persist.

Niunio
Member #1,975
March 2002
avatar

I never had problems with al_flip_display(), using Xubuntu 16.04. I must say that I'm using the Allegro that is in the Ubuntu repository, not compiled by myself, and that I use Object Pascal instead of C++. ::)

-----------------
Current projects: Allegro.pas | MinGRo

dthompson
Member #5,749
April 2005
avatar

If you're running Ubuntu from VirtualBox, it might be worth checking your VM's graphics settings. Most aren't initialised with too much video memory and with 3D acceleration turned off:

{"name":"611648","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/a\/0a4a47aa38b9a88125f8ba87b363147a.png","w":713,"h":436,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/a\/0a4a47aa38b9a88125f8ba87b363147a"}611648

In any case, I'm running Allegro on Ubuntu 18.04 (but on bare metal) without this issue. :)

______________________________________________________
Website. It was freakdesign.bafsoft.net.
This isn't a game!

Morshock
Member #16,875
July 2018

@dthompson
I'm actually using 128MB of Video Memory and I've 3D acceleration enabled. So that doesn't seem to be the reason. Thanks anyway for the heads-up.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Peter Hull
Member #1,136
March 2001

I tried it on VirtualBox 5.2.12, macos host, running 64-bit Lubuntu 18.04 and the allegro that I got from 'apt install'

I saw image-white-image-white i.e. single or double flip updated the screen.

For my previous test on macos, I saw image-white-white-white. The single flips updated the screen, the double did something else (not sure what!)

Edgar: you can load the downloaded .iso straight into VB without making a DVD (apologies if you know this already)

Pete

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Edgar: you can load the downloaded .iso straight into VB without making a DVD (apologies if you know this already)

Actually, I don't know how to do that. I figured it out easy enough.

Who knows how long it will take to install though...

EDIT
Suprisingly, not long! Now I just have to freaking install allegro and all of its dependencies.... :P

EDIT2
EDIT3
What does this mean?

Quote:

marc@VBOXUBUNTU:~$ sudo apt-get install allegro5
[sudo] password for marc: 
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
marc@VBOXUBUNTU:~$ sudo apt-get install allegro5
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package allegro5
marc@VBOXUBUNTU:~$ sudo apt-get install allegro
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package allegro
marc@VBOXUBUNTU:~$

EDIT4
Guess you can't do that. Hrmph. >:(

https://wiki.allegro.cc/index.php?title=Ubuntu_and_Allegro_5

Peter Hull
Member #1,136
March 2001

What does this mean?

In my experience this happens when it's checking for updates (which it does in the background on a schedule)
Just wait a bit and retry.

Also: I often find it says something about the updates not being valid - this happens if you save the VM state and restore it later. It takes a while for the system clock to catch up and during this time, the updates appear to be 'from the future' and are therefore not accepted.

edit: it's liballegro5-dev
Do apt list|grep allegro

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

edit: it's liballegro5-dev
Do apt list|grep allegro

OMG THAT WAS WAY TOO EASY!!!!11111 R0F1MA0 101

VBOXUBUNTU said:

marc@VBOXUBUNTU:>sudo apt-get install liballegro5-dev
...
...
...
...
...
10 minutes later
...
Allegro is installed!!!!

EDIT
Whether a single or double flip doesn't seem to matter with this simple code :

#SelectExpand
1 2#include "allegro5/allegro.h" 3 4 5enum COL { 6 R = 0, 7 G = 1, 8 B = 2 9}; 10 11void Clear(COL c) { 12 static const ALLEGRO_COLOR cols[3] = { 13 al_map_rgb(255,0,0), 14 al_map_rgb(0,255,0), 15 al_map_rgb(0,0,255) 16 }; 17 al_clear_to_color(cols[c]); 18} 19 20COL color = B; 21 22void SingleFlip() { 23 Clear(color = (COL)((int)((color + 1))%3)); 24 al_flip_display(); 25} 26 27void DoubleFlip() { 28 Clear(color = (COL)((int)((color + 1))%3)); 29 al_flip_display(); 30 al_flip_display(); 31} 32 33int main(int argc , char** argv) { 34 35 36 if (!al_init()) {return 1;} 37 38 ALLEGRO_DISPLAY* d = al_create_display(800,600); 39 40 SingleFlip(); 41 al_rest(3.0); 42 43 SingleFlip(); 44 al_rest(3.0); 45 46 SingleFlip(); 47 al_rest(3.0); 48 49 DoubleFlip(); 50 al_rest(3.0); 51 52 DoubleFlip(); 53 al_rest(3.0); 54 55 DoubleFlip(); 56 al_rest(3.0); 57 58 return 0; 59}

It shows red, green, blue, red, green, blue for me. Perhaps it's different for images but I don't know. It would seem allegro is using a double buffer. That can be queried from allegro.

EDIT2
It works with an image as well.

{"name":"611655","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/6\/3648e51c667ebe7e3111e431aedd822c.png","w":799,"h":621,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/6\/3648e51c667ebe7e3111e431aedd822c"}611655

Peter Hull
Member #1,136
March 2001

It works with an image as well.

My brother!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

We really need to make Elias's GIF addon to allegro an offical addon. So that way I could make a program that played a video of your gif blinking. Your avatar reminds me of oh what is it, Scream?

{"name":"%22The_scream%22._Wellcome_L0011212.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/2\/02c6cfbe1acfa6dce84c0a0cfc44f68c.jpg","w":1164,"h":1666,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/2\/02c6cfbe1acfa6dce84c0a0cfc44f68c"}%22The_scream%22._Wellcome_L0011212.jpg

Go to: