1

My first question here. In my program depth testing works properly on some computers, but it doesn't work on others, objects that are located farther away cover those which are located closer. I called glEnable(GL_DEPTH_TEST); and tried to call glDepthFunc(GL_LESS); and as I said, everything works properly on some computers, but the same program doesn't work properly on other computers. How can it be fixed?

Edit: Problem solved. Added these lines before calling al_create_display(); and everything works

  al_set_new_display_option(  ALLEGRO_COLOR_SIZE,  32,  ALLEGRO_REQUIRE);
  al_set_new_display_option(  ALLEGRO_DEPTH_SIZE,  24,  ALLEGRO_REQUIRE);
  al_set_new_display_option(  ALLEGRO_STENCIL_SIZE,  8,  ALLEGRO_REQUIRE);
  al_set_new_display_option(  ALLEGRO_AUX_BUFFERS,  0,  ALLEGRO_REQUIRE);  
  al_set_new_display_option(  ALLEGRO_SAMPLES,  4,  ALLEGRO_SUGGEST);
intereins
  • 21
  • 5
  • 2
    You have to ensure that the default framebuffer has a depth buffer. The default framebuffer is created when the OpenGL window and context is initialized. – Rabbid76 Sep 11 '20 at 07:23
  • @Rabbid76 How can I do this if I'm using immediate mode? – intereins Sep 11 '20 at 08:09
  • @Rabbid76 I'm using Allegro 5, should I call al_set_new_display_option(), or set a display flag? – intereins Sep 11 '20 at 08:31
  • Sorry, but I'm not familiar with Allegro 5. Probably you have to set [`al_set_new_display_option(ALLEGRO_DEPTH_SIZE, ..., ...)`](https://www.allegro.cc/manual/5/al_set_new_display_option) – Rabbid76 Sep 11 '20 at 08:35

1 Answers1

3

In addition to activating the Depth Test (glEnable(GL_DEPTH_TEST)), it is important that the current framebuffer has a depth buffer.
The default framebuffer is created at the time the OpenGL Context is constructed. The creation of the OpenGL context depends on the OS and windowing library (e.g. GLFW, SDL, SFML). Whether a depth buffer is created by default often depends on the system. In general, window libraries provide additional options for explicitly specifying a depth buffer when generating the OpenGL window:

For instance:

Rabbid76
  • 202,892
  • 27
  • 131
  • 174