Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Menu doesn't show in linux - Allegro 5

This thread is locked; no one can reply to it. rss feed Print
Menu doesn't show in linux - Allegro 5
Lucas Dalmasso
Member #20,839
August 2021

Hi, i don't know why, but the dialog interface of Allegro 5 isn't showing the menu in linux. I tried fedora and ubuntu. It shows up in Windows but not linuxes.

Any idea?

amarillion
Member #940
January 2001
avatar

Could you give a bit more context? What function are you calling? Do you have some sample code? What do you expect to happen exactly?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Lucas Dalmasso
Member #20,839
August 2021

Im creating a simple menu using allegro DIALOG functions. Since "OpenFileDialog()" in win32 worked in Windows through Allegro, i mean it showed fine the dialog in linux. So when i created the allegro window menu i tought that in the VM or Real Machine would show the menu in my window, but it doesn't.

Maybe im compiling with different versions of Allegro?? i don't know im not to savy to linux,

The program compiles fine under linux using g++ and allegro libs, but could it be a version problem?

I have 2 VM of linux: one for Fedora 34 and the other one for Ubuntu 12.04. I have a real dual booting installation of Win 10 and Ubuntu.

My code basically creates a menu and appends other menus to it (no bitmap, no special things). I think code isn't needed since it's too basic.

Thanks in advance

amarillion
Member #940
January 2001
avatar

Hey Lucas,

  • DIALOG is a Allegro 4 thing, not Allegro 5. Can you confirm your Allegro version? Is it allegro 4 or 5?

  • In Allegro 5, you would show a file dialog using al_show_native_file_dialog() and co, not with OpenFileDialog().

I'm still not very clear on what the problem is exactly. If you can show some of your code, then perhaps we can help you better.

Lucas Dalmasso
Member #20,839
August 2021

I didn't know that "Dialog" was allegro 4 thing.
Im not using win32 "OpenFileDialog()". I just only said that the allegro lib should could this API.

Im using Allegro 5 in Visual C++ ver 142 runtime. The one that came with Nuget packages.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Lucas Dalmasso
Member #20,839
August 2021

I know, i know that about that link.
I did something i installed code:blocks in ubutu and migrated the project to linux. Looking further i discoverd that the error was in al_set_display_menu(), it returns with an error. I read the docs in allegro ubuntu info, but it isn't clear why fails.
I don't know why it does fail in ubuntu (and im compiling with the latest dev/libs version of allegro 5.

My code is very simple:

-------------------------------------------------
#pragma once
#include <allegro5/allegro5.h>
#include <allegro5/allegro_native_dialog.h>
enum {
FILE_ID = 1,
FILE_LOADROM_ID,
FILE_CLOSEROM_ID,
FILE_EXIT_ID,
EMULTOR_RESET_ID,
EMULTOR_MUTE_ID,
WINDOW_1X,
WINDOW_2X,
WINDOW_3X,
WINDOW_4X
};
ALLEGRO_MENU_INFO main_menu_info[] = {
ALLEGRO_START_OF_MENU("File", FILE_ID),
{ "Load Rom", FILE_LOADROM_ID, 0, NULL },
{ "Close Rom", FILE_CLOSEROM_ID, 0, NULL },
*ALLEGRO_MENU_SEPARATOR,*
{ "Exit", FILE_EXIT_ID, 0, NULL },
ALLEGRO_END_OF_MENU,

ALLEGRO_START_OF_MENU("Emulator", 0),
{ "Reset", EMULTOR_RESET_ID, 0, NULL },
*ALLEGRO_MENU_SEPARATOR,*
{ "Mute audio", EMULTOR_MUTE_ID, 0, NULL },
ALLEGRO_END_OF_MENU,

ALLEGRO_START_OF_MENU("&Window", 0),
{ "1X", WINDOW_1X, 0, NULL },
{ "2X", WINDOW_2X, 0, NULL },
{ "3X", WINDOW_3X, 0, NULL },
{ "4X", WINDOW_4X, 0, NULL },
ALLEGRO_END_OF_MENU,

ALLEGRO_END_OF_MENU
};
class Menu
{

public:
bool Init(ALLEGRO_DISPLAY* allegro_display, ALLEGRO_EVENT_QUEUE * queue)
{
bool ret = al_init_native_dialog_addon();
if (ret == false)
{
std::cout << "Could not create ALLEGRO menu interface" << std::endl;
return ret;
}
ALLEGRO_MENU* menu = nullptr;
menu = al_build_menu(main_menu_info);
if (menu == nullptr)
{
std::cout << "Could not BUILD MENU" << std::endl;
return false;
}
al_set_display_menu(allegro_display, NULL);
ret = al_set_display_menu(allegro_display, menu);
if (ret == false)
{
std::cout << "Could not display menu" << std::endl;
return ret;
}
al_register_event_source(queue, al_get_default_menu_event_source());
return true;
}
};
-------------------------------------------------

Anyway it prints to the terminal "Could not display menu" however in Windows dosn't drop this error.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

amarillion
Member #940
January 2001
avatar

I've used your code and managed to reproduce the problem. I ran it on linux and the menu wouldn't appear. I stepped through the debugger and noticed that the GTK context would not be created. I did manage to fix it with the following tweaks:

1. Make sure you set the ALLEGRO_GTK_TOPLEVEL flag before calling al_create_display(). You can use this snippet from ex_menu.c:

#ifdef ALLEGRO_GTK_TOPLEVEL
   /* ALLEGRO_GTK_TOPLEVEL is necessary for menus with GTK. */
   al_set_new_display_flags(ALLEGRO_RESIZABLE | ALLEGRO_GTK_TOPLEVEL);
#else
   al_set_new_display_flags(ALLEGRO_RESIZABLE);
#endif
   display = al_create_display(640, 480);

2. Make sure you call al_init_native_dialog_addon() before you call al_create_display(). If not, the appropriate GTK context is not set up properly. I noticed that your menu init function initializes the addon and creates the menu, but at that time the display is already created. This is probably what's going wrong on linux.

If you try these two things, does it work for you then?

The fact that the call to al_init_native_dialog_addon() succeeds even though the GTK context is not set up, could be considered a bug in allegro. Or at the very least it could generate a more helpful warning here.

P.S. Seeing your code was essential to solving the problem, and it would still have been easier if you had also shared your display setup code. So here is your takeaway: If you share your code, you will get answers more quickly. 8-)

Go to: