Porting OpenGL GLUT example use QOpenGLWidget Issues
-
I have an example which leverages a rendering engine to produce an image which then it is displayed. This works great when using glut directly but when switching to using QOpenGLWidget I am constantly running into issues and not sure why. I am assuming that it may be related to difference in how Qt initializes OpenGL versus Glut/Glew. Is there a way to initialize Qt so it is initially setup the same way Glut/Glew would be? Below I have outlined some differences and an issue that is not resolved.
Glut/Glew Display Callback
if (g_display) { glXMakeCurrent(g_display, g_drawable, g_context); } auto camera = g_cameras[g_cameraIndex]; camera->SetImageHeight(imgh); camera->SetImageWidth(imgw); camera->SetAspectRatio(static_cast<double>(imgw) / static_cast<double>(imgh)); ir::Image image = camera->CreateImage(); g_image = std::make_shared<ir::Image>(image); camera->Capture(*g_image); auto *data = g_image->Data<unsigned char>(); handleMouse(); glXMakeCurrent(g_glutDisplay, g_glutDrawable, g_glutContext); glClearColor(0.5, 0.5, 0.5, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelZoom(1, -1); glRasterPos2f(-1, 1); glDrawPixels(imgw, imgh, GL_RGB, GL_UNSIGNED_BYTE, data); glutSwapBuffers();
The first issue was the matrix for each of the MatrixModes were not identity which they were in Glut on initialization so I had to add the following. Is there a way to configure thing in the initializeGL() method so this is not needed?
glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity();
The current issue I am running into is if I add an object to the render engine that has an alpha not equal to 1.0 when drawing the image it behaves oddly. If I pan over the object the whole screen goes to a solid color of the color with an alpha not equal to 1.0. If I pan the object out of screen everything goes back to normal. Any ideas why this would be happening? I tried to upload the image but getting a server error. I will try again.
Note: All of this works using the glut displayCB but when porting to QOpenGLWidget things breakdown and not sure why.
-
Here is the image. You see it has the coordinate system marker in the middle which is causing the issue. If this is added with an alpha of 1 it loads the image fine, but anything else I get one of the three colors(red, green or blue) taking up the entire screen. If I pan it off the screen everything goes back to normal and I see a portion of the grid.
I have also tired saving the image the loading it with QImage and drawing the image using the same glDrawPixels command but get the same behavior.