Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Porting OpenGL GLUT example use QOpenGLWidget Issues
Forum Updated to NodeBB v4.3 + New Features

Porting OpenGL GLUT example use QOpenGLWidget Issues

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 258 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Levi
    wrote on 8 Apr 2022, 15:49 last edited by Levi 4 Aug 2022, 15:50
    #1

    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.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Levi
      wrote on 8 Apr 2022, 16:39 last edited by Levi 4 Aug 2022, 16:39
      #2

      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.

      ign_image.png

      1 Reply Last reply
      0

      1/2

      8 Apr 2022, 15:49

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved