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 :)
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 :)