Allegro 5 OpenGL depth test problem
DQBO1998

I've been working on my first OpenGL project, I decided to implement it through Allegro 5.0.1 for the compiler MinGW 4.7.0. Currently I'm using TDM-GCC 4.7.1.
Well, the project consists on a simple 3D drawing library that is more like a wrapper for OpenGL.

The code I use to initialize OpenGL is.

flags = ALLEGRO_WINDOWED | ALLEGRO_OPENGL_3_0 | ALLEGRO_OPENGL; //allegro flags

Then to setup the projection matrix.

#SelectExpand
1 glMatrixMode(GL_PROJECTION); 2 glLoadIdentity(); 3 L3D_perspective(FOV, (GLfloat)screen_width/(GLfloat)screen_height, 1.0f, 100.0f);

And the last one is for renderin, right now it's called every time after or before drawing.

#SelectExpand
1 glMatrixMode(GL_MODELVIEW); 2 glLoadIdentity();

I created a function for testing, it shows a textured quad on the given position and also can handle some rotation.

#SelectExpand
1void L3D_test_panel(GLfloat x, GLfloat y, GLfloat z, GLfloat x_angle, GLfloat y_angle, GLfloat z_angle, ALLEGRO_BITMAP *texture){ 2 3 glPushMatrix(); 4 5 glTranslatef(x, y, z); 6 glRotatef(x_angle, 1, 0, 0); 7 glRotatef(y_angle, 0, 1, 0); 8 glRotatef(z_angle, 0, 0, 1); 9 glBindTexture(GL_TEXTURE_2D, al_get_opengl_texture(texture)); 10 glEnable(GL_TEXTURE_2D); 11 12 /* glClearDepth(1.0f); 13 glDepthFunc(GL_LESS); 14 glEnable(GL_DEPTH_TEST);*/ 15 16 glBegin(GL_QUADS); 17 18 glTexCoord2f(0, 0); glVertex3f(-1, -1, -0); 19 glTexCoord2f(1, 0); glVertex3f(+1, -1, -0); 20 glTexCoord2f(1, 1); glVertex3f(+1, +1, -0); 21 glTexCoord2f(0, 1); glVertex3f(-1, +1, -0); 22 23 glEnd(); 24 25 glPopMatrix(); 26 27}

The problem is that when I try to apply depth testing the polygons still overlap. I could you tell me the right way to set it?

Elias

The depth buffer has to be requested before creating a display. Simply put this before al_create_display:

al_set_new_display_option(ALLEGRO_DEPTH_SIZE, 16, ALLEGRO_SUGGEST);

DQBO1998

Thanks Elias, could you tell me when is it right to call glEnable(GL_DEPTH_TEST)? Because I want to know the "right" way.

Elias

Just once in the beginning. Unless you need to draw some things without depth test, then you will have to call glEnable/glDisable every time you need it enabled/disabled for drawing.

Thread #616355. Printed from Allegro.cc