qtopenglnvidiaoptix

Display OptiX sample6 in QGLWidget


I want to display sample6 of the OptixSDK in a QGLWidget.

I've read the topic in the Nvidia OptiX Forum but I do not get ahead, because unfortunalety I have no idea how I shall override the paintGL() method.

At first I simply tried to read the outputbuffer of sample6 and saved it in a QImage

QImage img(m_width,m_height,QImage::Format_RGB32);
QColor color;
int idx;
void* data = m_outputBuffer->map();
typedef struct { float r; float g; float b; float a;} rgb;
rgb* rgb_data = (rgb*)data;

for(unsigned int i=0; i<m_width*m_height; ++i){
    std::cout<<rgb_data[i].r<<","<<rgb_data[i].g<<","<<rgb_data[i].b<<std::endl;
    float red = rgb_data[i].r; if(red>1.0) red=1.0;
    float green = rgb_data[i].g; if(green>1.0) green=1.0;
    float blue = rgb_data[i].b; if(blue>1.0) blue=1.0;
    float alpha = rgb_data[i].a; if(alpha>1.0) alpha=1.0;
    color.setRgbF(red,green,blue,alpha);
    idx = floor((float)i/m_height);

    img.setPixel(i-(idx*m_height), idx, color.rgb());

}
m_outputBuffer->unmap();
img.save("optixSampleSix.png","PNG");

and the method mentioned bei RoboMod in the Nvidia OptiX Forum, but in both I get a black picture of nonsense. Nevertheless if I use the functions by provided sutil to save the output in a .ppm file, everything seems right.

So my question is how to get from the OptiX output buffer to the rendered openGL scene properly.


Solution

  • What about constructing QImage directly?

    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");