Search code examples
openglopengl-compat

OpenGL behaves differently in ubuntu and windows


I am using wxGLContext and wxGLCanvas for 3D visualization. I initialized opengl like this

SetCurrent(*canvas);
glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);

and draw the objects

glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-w, w, -h, h, -10.0f, 10.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
quad = gluNewQuadric();
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
//draw the objects
gluDeleteQuadric(quad);
glFlush();

The problem is that this code works fine in windows, but in ubuntu the objects clipped by the objects which are located in back. The glFrontFace is correct for all objects, but clipping is wrong.


Solution

  • As HolyBlackCat mentioned in the comments, the problem was depth buffer for the wxGLContext. It works by using WX_GL_DEPTH_SIZE 8 and 16, but not 32.

    Although, I still do not know, how windows can handle it without error, I corrected some lines as follows

    int AttribList[] = {WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, 0};
    wxGLCanvas* glc = new wxGLCanvas(parent, wxID_ANY, AttribList,
                                     wxDefaultPosition, wxDefaultSize,
                                     wxFULL_REPAINT_ON_RESIZE);
    

    and now it works for both OSs.