///////////////////////////////
// Render the scene into a png
///////////////////////////////
void GlView::renderOffScreen()
{
// We need to have a valid openGL context
makeCurrent();
// 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;
}
///////////////////////////////
// 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 copy to clipboard, switch view to plain text mode
Bookmarks