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.
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.
Um OpenLayer initializes allegro for you. Why don't you just init openlayer and use your allegro commands like normal?
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.
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...
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.
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...
If you just do the normal OpenLayer setup and don't initialise Allegro or an allegro screen, what happens?
Like I said, the file window doesn't appear. I just get a black screen.
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.
Well, is there a way to "shut down" OpenLayer then, so I can use just allegro at the end of the program?
I believe AllegroGL (which OpenLayer uses) has methods that allow you to use allegro GUIs.
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(...)
(...)
It crashes at the third line: file_select_ex(...);
EDIT:
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.
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.
Like I said, it supports some GUI functions but not file_select_ex()
I made small example that works:
| 1 | #include <OpenLayer.hpp> |
| 2 | |
| 3 | int 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 | } |
| 30 | END_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.
Thank you! That did the trick