PDA

View Full Version : Rendering offscreen with QGLWidget



jcox23
12th January 2011, 21:47
Hey,

I am wondering what is the proper way to implement offscreen "offline" rendering with QGLWidget. By "offline", I mean without displaying any GUI. The "online" mode works well,here is the code of the offscreen render method:



///////////////////////////////
// Render the scene into a png
///////////////////////////////
void GlView::renderOffScreen()
{

// We need to have a valid openGL context
makeCurrent();

QGLFramebufferObject * fb = new QGLFramebufferObject(8000,1000, GL_TEXTURE_2D);

// bind it and let's start drawing on it....
fb->bind();

glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);

// this must be the same size as the FrameBuffer....
glViewport(0, 0, 8000, 1000);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluOrtho2D(camera->left(),
camera->right(),
camera->bottom(),
camera->top());

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// renderData........
renderData();

fb->release();

// reset the viewport to its normal self :)
glViewport(0, 0, viewport[2], viewport[3]);

// get the fb into a QImage
QImage tempImage = fb->toImage();

// Delete the FB
delete fb;

// Save the image
if ( !tempImage.save( "hello.png", "PNG") )
return;

}


To have the "offline" version, I simply deleted the call to show on the main widget...
It works on Linux (even though you clearly the something is created then deleted), but not on win32.... so I wonder if there is a more proper solution to this.....

Thanks :)

George Neil
21st February 2011, 10:10
Hey,

I am wondering what is the proper way to implement offscreen "offline" rendering with QGLWidget. By "offline", I mean without displaying any GUI. The "online" mode works well,here is the code of the offscreen render method:



///////////////////////////////
// Render the scene into a png
///////////////////////////////
void GlView::renderOffScreen()
{

// We need to have a valid openGL context
makeCurrent();

QGLFramebufferObject * fb = new QGLFramebufferObject(8000,1000, GL_TEXTURE_2D);

// bind it and let's start drawing on it....
fb->bind();

glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);

// this must be the same size as the FrameBuffer....
glViewport(0, 0, 8000, 1000);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluOrtho2D(camera->left(),
camera->right(),
camera->bottom(),
camera->top());

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// renderData........
renderData();

fb->release();

// reset the viewport to its normal self :)
glViewport(0, 0, viewport[2], viewport[3]);

// get the fb into a QImage
QImage tempImage = fb->toImage();

// Delete the FB
delete fb;

// Save the image
if ( !tempImage.save( "hello.png", "PNG") )
return;

}


To have the "offline" version, I simply deleted the call to show on the main widget...
It works on Linux (even though you clearly the something is created then deleted), but not on win32.... so I wonder if there is a more proper solution to this.....

Thanks :)

Does anyone succeed in overcoming this issue ?

caglarkavak
14th July 2011, 14:18
does anyone find a solution?

Dong Back Kim
5th August 2011, 03:33
does anyone find a solution?

I was able to store rendering result into files in Windows 7. In the image file, I could see part of my rendering which means somehow there was some sort of modelview or projection corruption... I will keep testing and post more details.

Regards,
Dong Back Kim

fAX
29th January 2013, 14:37
Hi,

Did you manage to overcome that? I need to do a similar thing. Thanks!