OpenGL depth test doesn't work on some computers

559 Views Asked by At

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);
1

There are 1 best solutions below

0
On BEST ANSWER

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: