Results 1 to 4 of 4

Thread: Capture OpenGL screen pixels

  1. #1
    Join Date
    Dec 2008
    Location
    Paris, France
    Posts
    34
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Capture OpenGL screen pixels

    The problem I face is really simple : I'd like to implement some code to capture an OpenGl display on the screen to an image file.

    It should be something like

    Qt Code:
    1. Step 1 : NbBytes = size.width() * size.height() * screen_pixel_format/8;
    2. Step 2 : uchar *pPixelData = new uchar[NbBytes];
    3. Step 3 : glReadPixels(0,0,size.width(),size.height(),GL_BGR_EXT,GL_UNSIGNED_BYTE,pPixelData);
    4. Step 4 : QImage Image(pPixelData, size.width(),size.height(), NbBytes/ size.height(), QImage::Format_RGB888);
    5. Step 5 : Image.save(FileName);
    To copy to clipboard, switch view to plain text mode 

    Step 0 would be to find out what is the screen's pixel format, and which pixel format OpenGl is using : 8, 16, or 24 bits ? Is there way to get this information in Qt ?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Capture OpenGL screen pixels

    How about simply calling QGLWidget::renderPixmap() instead?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Boston, MA
    Posts
    40
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Capture OpenGL screen pixels

    I'm using QImage QGLWidget::grabFrameBuffer(bool withAlpha = false)

    http://doc.trolltech.com/4.5/qglwidg...rabFrameBuffer

  4. #4
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Capture OpenGL screen pixels

    You can also use QPixmap::grabWindow() and set the coordinates to your QGLWidget. I use this because I only need to render part of the OpenGL scene.

Similar Threads

  1. OpenGL and Qt Question
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2009, 19:04
  2. capture screen (with Mouse) ?
    By ascii in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2008, 13:16
  3. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 08:21

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.