Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Depth bug (Allegro 5 + Opengl)

This thread is locked; no one can reply to it. rss feed Print
Depth bug (Allegro 5 + Opengl)
Space cpp
Member #16,322
May 2016

Hello people.
I made a simple 3D sokoban game combining Allegro and Opengl. It runs fine on Windows, but either on Mac OSX or iOS it produces a wierd rendering bug.
It seens that objects draws last are always over other things as if the depth buffer was not working.
I'm attaching a screenshot to ilustrate the problem (Left is Windows, right is iOS simulator)

----------
My games

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You have to enable the depth buffer before it will work.

https://liballeg.org/a5docs/trunk/display.html#al_set_new_display_option

al_set_new_display_option(ALLEGRO_DEPTH_SIZE , 32 , ALLEGRO_SUGGEST);
al_set_new_display_option(ALLEGRO_FLOAT_DEPTH , 1 , ALLEGRO_SUGGEST);

The second is optional, but the first is necessary to enable the depth buffer. You must call these before creating your display.

Space cpp
Member #16,322
May 2016

This actually worked.. in an older version that does use the fixed pipeline, which is not compatible with iOS.
The current version still produces the bug.

I guess I have to show some code
My initialization routine looks like this:

#SelectExpand
1if (!al_init() ) { printf("al_init Failed!\n"); return false; } 2 if (!al_install_mouse() ) { fprintf(stderr, "failed to initialize the mouse!\n"); return false; } 3 al_init_font_addon(); 4 if (!al_init_ttf_addon() ) { fprintf(stderr, "failed to initialize the ttf addon!\n"); return false; } 5 if (!al_install_audio() ) { fprintf(stderr, "failed to initialize audio!\n"); return false; } 6 if (!al_init_acodec_addon() ) { fprintf(stderr, "failed to initialize audio codecs!\n"); return false; } 7 if (!al_reserve_samples(8) ) { fprintf(stderr, "failed to reserve samples!\n"); return false; } 8 if (!al_install_keyboard() ) { fprintf(stderr, "failed to initialize the keyboard!\n"); return false; } 9 timer = al_create_timer(1.0 / FPS); if (!timer) { fprintf(stderr, "failed to create timer!\n"); return false; } 10 if (!al_init_image_addon() ) { al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_image_addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR); return false; } 11 if (!al_init_primitives_addon() ) { printf("al_init_primitives_addon Failed!\n"); return false; } 12 if (!al_install_touch_input() ) { printf("Could not init touch input.\n"); return false; } 13 14 15 16 if (!use_vsync) 17 al_set_new_display_option(ALLEGRO_VSYNC, 2, ALLEGRO_REQUIRE); // force off vsync to avoid high cpu usage 18 19 al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_OPENGL_ES_PROFILE | ALLEGRO_PROGRAMMABLE_PIPELINE); 20 21 al_set_new_display_option(ALLEGRO_DEPTH_SIZE, 32, ALLEGRO_SUGGEST); 22 al_set_new_display_option(ALLEGRO_FLOAT_DEPTH, 1, ALLEGRO_SUGGEST); 23 24 25 display = al_create_display(800, 600); 26 if (!display) 27 { 28 al_show_native_message_box(display, "Error", "", "al_create_display Failed!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 29 return false; 30 }

At the beginning of the draw routine:

#SelectExpand
1glViewport(0, 0, al_get_display_width(display), al_get_display_height(display)); 2 3 glClearColor(0.5f, 0.5f, 0.5f, 1.0f); 4 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 5 glEnable(GL_DEPTH_TEST); 6 glEnable(GL_CULL_FACE);

For every object to be drawn I store the vertices on a std::vector then use glVertexAttribPointer, glEnableVertexAttribArray and glDrawArrays.

----------
My games

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Well, since you know how to set the new display options, you should know how to get them after they've been set to see what they are.

https://liballeg.org/a5docs/trunk/display.html#al_get_display_option

See what they return for ALLEGRO_DEPTH_SIZE and ALLEGRO_FLOAT_DEPTH.

Space cpp
Member #16,322
May 2016

On iOS simulator it returns 0 and 0.
On Windows 24 and 0.

Edit:
Just tested on my iPad and the results are exactly the same, so it's not a simulator issue.

----------
My games

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Well, then that means the depth buffer is either not available, or didn't score well in allegro's display testing phase.

Run a debug build and check allegro.log. There will be a 'depth' entry for every display configuration scored. See if there are even any available.

You can also set ALLEGRO_DEPTH_SIZE to ALLEGRO_REQUIRE and test several values. If the driver comes back null, it's just not available.

Space cpp
Member #16,322
May 2016

By debug build you mean I have to recompile the allegro static library with some different configuration?

Now that I thought about it just saw the following on README_iphone.txt:

"Can use either OpenGL ES 1 or 2 for graphics, by default OpenGL ES 1 is
used."
I was wondering a while ago why glGetString(GL_SHADING_LANGUAGE_VERSION) always gives me "OpenGL ES GLSL ES 1.00". ::)

I`m guessing the problem is not the code but how the library file was compiled.
How do I set up these options?

Before I forget: using ALLEGRO_REQUIRE does not seen to be doing any difference, the display is still created, with depth size 0.

----------
My games

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Space cpp said:

By debug build you mean I have to recompile the allegro static library with some different configuration?

Generally, yes. But you can enable the allegro.log in release mode as well. (Don't ask me how I can never remember)...

Space cpp said:

"Can use either OpenGL ES 1 or 2 for graphics, by default OpenGL ES 1 is
used."

The manual for al_set_new_display_flags says this :

ALLEGRO_OPENGL_ES_PROFILE
Used together with ALLEGRO_OPENGL, requests that the OpenGL context uses the OpenGL ES profile. A specific version can be requested with al_set_new_display_option. Note: Currently this is only supported by the X11/GLX driver. Since: 5.1.13

I'm guessing you enable GL ES 2 by requesting the major opengl version to be 2. I don't know for sure. Try this :
al_set_new_display_option(ALLEGRO_OPENGL_MAJOR_VERSION , 2 , ALLEGRO_REQUIRE);

The manual entry for al_set_new_display_option doesn't explain much about this part of things.

Space cpp said:

Before I forget: using ALLEGRO_REQUIRE does not seen to be doing any difference, the display is still created, with depth size 0.

If you use ALLEGRO_REQUIRE and a non zero depth size, creating the display should fail if it can't find a display mode with the requested depth. Check your code, and if it's okay, then that's a bug in allegro.

But first, enable the log and check the display scores.

Space cpp
Member #16,322
May 2016

I'm stuck at the log part.

----------
My games

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Okay, first did you download binaries? Or build allegro yourself?

If you're building allegro yourself, all you have to do is set the CMAKE_BUILD_TYPE to 'Debug' or 'RelWithDebInfo' and then rebuild.

A quick google search reveals how SiegeLord enables the log :

Call that line before you call al_init() and the log should be enabled if support was compiled in.

Space cpp
Member #16,322
May 2016

Okay, first did you download binaries? Or build allegro yourself?

Since I'm compilling for iOS now I used the included pre-built xcode project to build the static library.

al_set_config_value(al_get_system_config(), "trace", "level", "debug");

To make sure I wasn't doing anything wrong I tested this on windows first and it worked. On iOS by other hand, the filesystem seems to be a bit different, I couldn't find the allegro.log file inside the app file / folder.

Maybe, is there a way to dump the log contents on console instead?

----------
My games

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Space cpp
Member #16,322
May 2016

Uh oh, it seems my build was compiled without support for it.

So, I'm going to rebuild it and report here later.

----------
My games

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Space cpp
Member #16,322
May 2016

My apologies for taking long to respond.
I tried rebuilding allegro with either RelWithDebInfo / Debug but still no success generating the log.

----------
My games

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

The log is there somewhere. You just have to find it.

There are different directories allegro uses on OSX. See al_get_standard_path for an idea of where to search.

SiegeLord or anyone else - if you're listening, where do you guys store allegro.log on OSX?

Go to: