Results 1 to 5 of 5

Thread: Rendering offscreen with QGLWidget

  1. #1
    Join Date
    Dec 2009
    Posts
    24
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Rendering offscreen with QGLWidget

    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:

    Qt Code:
    1. ///////////////////////////////
    2. // Render the scene into a png
    3. ///////////////////////////////
    4. void GlView::renderOffScreen()
    5. {
    6.  
    7. // We need to have a valid openGL context
    8. makeCurrent();
    9.  
    10. QGLFramebufferObject * fb = new QGLFramebufferObject(8000,1000, GL_TEXTURE_2D);
    11.  
    12. // bind it and let's start drawing on it....
    13. fb->bind();
    14.  
    15. glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
    16.  
    17. // this must be the same size as the FrameBuffer....
    18. glViewport(0, 0, 8000, 1000);
    19.  
    20. glMatrixMode(GL_PROJECTION);
    21. glLoadIdentity();
    22.  
    23. gluOrtho2D(camera->left(),
    24. camera->right(),
    25. camera->bottom(),
    26. camera->top());
    27.  
    28. glMatrixMode(GL_MODELVIEW);
    29. glLoadIdentity();
    30.  
    31. // renderData........
    32. renderData();
    33.  
    34. fb->release();
    35.  
    36. // reset the viewport to its normal self :)
    37. glViewport(0, 0, viewport[2], viewport[3]);
    38.  
    39. // get the fb into a QImage
    40. QImage tempImage = fb->toImage();
    41.  
    42. // Delete the FB
    43. delete fb;
    44.  
    45. // Save the image
    46. if ( !tempImage.save( "hello.png", "PNG") )
    47. return;
    48.  
    49. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jun 2008
    Posts
    25
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default Re: Rendering offscreen with QGLWidget

    Quote Originally Posted by jcox23 View Post
    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:

    Qt Code:
    1. ///////////////////////////////
    2. // Render the scene into a png
    3. ///////////////////////////////
    4. void GlView::renderOffScreen()
    5. {
    6.  
    7. // We need to have a valid openGL context
    8. makeCurrent();
    9.  
    10. QGLFramebufferObject * fb = new QGLFramebufferObject(8000,1000, GL_TEXTURE_2D);
    11.  
    12. // bind it and let's start drawing on it....
    13. fb->bind();
    14.  
    15. glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
    16.  
    17. // this must be the same size as the FrameBuffer....
    18. glViewport(0, 0, 8000, 1000);
    19.  
    20. glMatrixMode(GL_PROJECTION);
    21. glLoadIdentity();
    22.  
    23. gluOrtho2D(camera->left(),
    24. camera->right(),
    25. camera->bottom(),
    26. camera->top());
    27.  
    28. glMatrixMode(GL_MODELVIEW);
    29. glLoadIdentity();
    30.  
    31. // renderData........
    32. renderData();
    33.  
    34. fb->release();
    35.  
    36. // reset the viewport to its normal self :)
    37. glViewport(0, 0, viewport[2], viewport[3]);
    38.  
    39. // get the fb into a QImage
    40. QImage tempImage = fb->toImage();
    41.  
    42. // Delete the FB
    43. delete fb;
    44.  
    45. // Save the image
    46. if ( !tempImage.save( "hello.png", "PNG") )
    47. return;
    48.  
    49. }
    To copy to clipboard, switch view to plain text mode 

    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 ?

  3. #3

    Default Re: Rendering offscreen with QGLWidget

    does anyone find a solution?

  4. #4
    Join Date
    Aug 2011
    Location
    Seoul, Korea
    Posts
    46
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rendering offscreen with QGLWidget

    Quote Originally Posted by caglarkavak View Post
    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

  5. #5
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Rendering offscreen with QGLWidget

    Hi,

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

Similar Threads

  1. Replies: 0
    Last Post: 6th April 2010, 03:53
  2. Drawing to an offscreen buffer
    By Dutch112 in forum Qt Programming
    Replies: 5
    Last Post: 6th May 2009, 16:49
  3. 3D rendering on Ubuntu using QGLWidget
    By sanjayshelke in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2009, 12:05
  4. Tile rendering with QGLWidget
    By h123 in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2008, 22:27
  5. Replies: 0
    Last Post: 7th April 2008, 14:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.