Display Sample 6 in a Qt Widget

What is the best way to display sample 6 of the OptiX SDK in a Qt widget? Should I change GLUTDisplay to render into the widget?

Is there a way to use the vertex buffer object from GLUTDisplay and render it into a QWindow or QGLWidget?

I would recommend you to use QGLWidget. It does have several GLUT equivalent functions already inbuilt in it.

I created a new widget based on the graphicsview. There I have a function “drawBuffer” which reads a buffer, creates the colors and writes them to an image:

// map buffer
float3* mapped_buffer = reinterpret_cast<float3*>( m_buffer->get()->map() );

// create pixmap
m_image = new QImage(width, height, QImage::Format_RGB888);

// convert data to values between 0 and 255 and put it into image object
for (unsigned int x = 0; x < width; ++x) {
    for(unsigned int y = 0; y < height; ++y) {
        int i_w = y*width + x;
        QRgb color = qRgb((int)(mapped_buffer[i_w].x*255),
                     (int)(mapped_buffer[i_w].y*255),
                     (int)(mapped_buffer[i_w].z*255));
        m_image->setPixel(x, y, color);
    }
}

// unmap buffer
m_buffer->get()->unmap();

The last step is to add the image to a scene which could be set to the graphicsview.

Yes, the above posts are correct: QGLWidget is what you’re searching for.

You can subclass this and override

  • paintGL() - this is the function where the openGL scene is rendered and where most of the widget’s code resides
  • resizeGL() - called whenever the widget is resized
  • initializeGL() - sets up an openGL rendering context, called once before paintGL or resizeGL

An example Qt app with a QGLWidget

I am using Qt5 and it seems to me that QGLWidget should not be used for new code. Is this correct? I have read ( OpenGL in Qt 5.1 - Part 1 - KDAB ) that it is better to use a QOpenGLContext and QWindow with Qt5.

Looking to my post from yesterday, you see that there is no GL needed:

My code shows the equivalent for the “paintGL()”. It easy to replace the “resizeGL()” by using the QGraphicsView signals, too.

It depends on what you need to do, QGLWidget is fairly simple and takes care of the window if you don’t have one (http://qt-project.org/doc/qt-5.0/qtopengl/qglwidget.html#details), otherwise you can use QOpenGLContext to just use a native openGL context/reuse a context (i.e. you do the window handling by yourself) (http://qt-project.org/doc/qt-5.0/qtgui/qopenglcontext.html#details)

I am having issues to display sample6 in a QGLWidget. All I need to do take the outputbuffer from the Meshviewer and create an image, right?
When I use the method RoboMod uses most of the coordinates dont get the right value and if I save the QImage the picture looks weird, but if I use the function from sutil to save the picture in a .ppm file, the image seems to be right.

So can somebody give me a hint of to construct the paintGL() in order to render the scene?

Constructing the QImage directly with its constructor I get the right image

uchar* data = (uchar *)m_outputBuffer->map();
QImage img(data, m_width, m_height, QImage::Format_ARGB32);
// or maybe Format_RGBA8888 would work for you.. you have to check docs 
m_outputBuffer->unmap();
img.save("optixSampleSix.png","PNG");