Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Changing from pure allegro to OpenLayer in one program

Credits go to Hrvoje Ban, juvinious, Richard Phipps, Steve Terry, and Thomas Fjellstrom for helping out!
This thread is locked; no one can reply to it. rss feed Print
Changing from pure allegro to OpenLayer in one program
Vasco Freitas
Member #6,904
February 2006
avatar

I want to use file_select_ex() (for selecting a file) at the very beggining of my program, then use OpenLayer for the main program, and call file_select_ex() again at the end. Before using file_select_ex() I have to call allegro_init(), install_keyboard() and set_gfx_mode(), but if I do that OpenLayer doesn't work. Is there a way to do this? I basically just want an easy way to have a simple file browser at the beginning and end of my program.

Hrvoje Ban
Member #4,537
April 2004
avatar

Quote:

but if I do that OpenLayer doesn't work

How, did SetupProgram / SetupScreen failed or something else? Anyway you could try adding allegro_exit before OpenLayer initialization.

juvinious
Member #5,145
October 2004
avatar

Um OpenLayer initializes allegro for you. Why don't you just init openlayer and use your allegro commands like normal?

__________________________________________
Paintown

Richard Phipps
Member #1,632
November 2001
avatar

Setting up OpenLayer (which sets up allegro too) first is probably what you want to do.

It's possible (although unlikely) that file_select_ex draws to the normal Allegro 'screen' and OpenLayer only sets up a basic OpenGL screen. You'll probably need to do a few AllegroGL calls if OpenLayer doesn't do them to let you use the 'screen' in this case.

Vasco Freitas
Member #6,904
February 2006
avatar

Hrvoje Ban said:

How, did SetupProgram / SetupScreen failed or something else? Anyway you could try adding allegro_exit before OpenLayer initialization.

It crashes at Setup::SetupScreen(). Adding allegro_exit() before OpenLayer initialization worked :) Now I just need a way to "exit" OpenLayer before the end of the program...

juvinious said:

Um OpenLayer initializes allegro for you. Why don't you just init openlayer and use your allegro commands like normal?

The allegro file window doesn't appear.

Richard Phipps said:

It's possible (although unlikely) that file_select_ex draws to the normal Allegro 'screen' and OpenLayer only sets up a basic OpenGL screen.

This is probably what happens...

Richard Phipps
Member #1,632
November 2001
avatar

If you just do the normal OpenLayer setup and don't initialise Allegro or an allegro screen, what happens?

Vasco Freitas
Member #6,904
February 2006
avatar

Like I said, the file window doesn't appear. I just get a black screen.

Steve Terry
Member #1,989
March 2002
avatar

Quote:

Like I said, the file window doesn't appear. I just get a black screen.

That's normal, OpenLayer uses an OpenGL surface, not an allegro one, unless you do some other steps to get the file selection to show on an opengl surface you will never see it. OpenGL needs to flip the buffer anyway if you want to see anything.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Vasco Freitas
Member #6,904
February 2006
avatar

Well, is there a way to "shut down" OpenLayer then, so I can use just allegro at the end of the program?

Thomas Fjellstrom
Member #476
June 2000
avatar

I believe AllegroGL (which OpenLayer uses) has methods that allow you to use allegro GUIs.

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

Hrvoje Ban
Member #4,537
April 2004
avatar

Try this:

ol::Setup::SetupProgram();
set_gfx_mode(GFX_AUTODETECT_*, ...);
file_select_ex(...);

set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); // Remove graphic mode
ol::Setup::SetupScreen(...);           

/* ... */

set_gfx_mode(GFX_TEXT, 0, 0, 0, );
set_gfx_mode(GFX_AUTODETECT_*, ...);
file_select_ex(...)

Vasco Freitas
Member #6,904
February 2006
avatar

Hrvoje Ban said:

(...)

It crashes at the third line: file_select_ex(...);

EDIT:

Thomas Fjellstrom said:

I believe AllegroGL (which OpenLayer uses) has methods that allow you to use allegro GUIs.

It has some methods that correspond to allegro GUI functions, but file_select_ex() isn't one of them. I also tried remove_allegro_gl(), allegro_gl_set_allegro_mode() and allegro_gl_unset_allegro_mode without success.

Isn't there a function that just "undoes" OpenLayer initializations? That would be enough.

juvinious
Member #5,145
October 2004
avatar

Quote:

The allegro file window doesn't appear.

Ah I didn't know you were using gui functions. :|
afaik as tomasu says, agl can use allegro gui functions.

__________________________________________
Paintown

Vasco Freitas
Member #6,904
February 2006
avatar

Like I said, it supports some GUI functions but not file_select_ex()

Hrvoje Ban
Member #4,537
April 2004
avatar

I made small example that works:

1#include <OpenLayer.hpp>
2 
3int main()
4{
5 if (!ol::Setup::SetupProgram())
6 return 1;
7 
8 remove_allegro_gl();
9 if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0)
10 return 1;
11 
12 char buffer[1024] = "C:\\";
13 file_select_ex("Hello!", buffer, NULL, 1024, 0, 0);
14 
15 if (install_allegro_gl() != 0 || !ol::Setup::SetupScreen(640, 480, false))
16 return 1;
17 
18 ol::Canvas::Fill(ol::Rgba(1.0f, 0.5f, 0.0f));
19 ol::Canvas::Refresh();
20 readkey();
21 
22 remove_allegro_gl();
23 if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0)
24 return 1;
25 
26 file_select_ex("Hello!", buffer, NULL, 1024, 0, 0);
27 
28 return 0;
29}
30END_OF_MAIN()

You need to remove AllegroGL so set_gfx_mode can succeed and re-install it again before setting up OpenLayer screen. Hackish, but it's best I could come up unless AllegroGL has some way to render Allegro GUI.

Vasco Freitas
Member #6,904
February 2006
avatar

Thank you! That did the trick :D

Go to: