Results 1 to 5 of 5

Thread: QGraphicsScene OpenGL rendering

  1. #1
    Join Date
    Apr 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsScene OpenGL rendering

    Hi forum,

    I'm currently making a pong game, I heard that using openGL rendering can reduce the load on the CPU and direct it to the GPU. Im using the QGraphicsScene as my 2D gameworld. Does anyone know how to let QGraphicsScene use OpenGL while rendering the graphics?

    Thanks in advance,

    Niels

  2. #2
    Join Date
    Sep 2010
    Location
    Russia, Moscow
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene OpenGL rendering

    something like this:
    Qt Code:
    1. ui->mapView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers | QGL::DirectRendering)));
    2. ui->mapView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
    3. ui->mapView->update();
    To copy to clipboard, switch view to plain text mode 

    rtfm =)

  3. #3
    Join Date
    Apr 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsScene OpenGL rendering

    I'd like a normal response, and it isn't in the manual

  4. #4

    Default Re: QGraphicsScene OpenGL rendering


  5. #5
    Join Date
    Oct 2011
    Location
    Venice, Italy
    Posts
    20
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene OpenGL rendering

    You can add a QGLWidget as viewport of your graphic view. Example:

    Qt Code:
    1. myGraphicsView->setViewport(new QGLWidget());
    To copy to clipboard, switch view to plain text mode 

    This enable the GL acceleration while drawing your scene.

    You can also specify what kind of options must be enabled, and you can do this through QGLFormat parameter, as said dkoryagin:

    Qt Code:
    1. myGraphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers | QGL::DirectRendering)));
    To copy to clipboard, switch view to plain text mode 

    You'll find all the available Format options (that at the moment I don't remember) here. Warning, is the manual :P :

    http://doc.qt.nokia.com/stable/qgl.h...matOption-enum


    Ciao,
    Marco

Similar Threads

  1. Replies: 8
    Last Post: 7th November 2012, 20:20
  2. Cosmetic pen with opengl rendering
    By spepegiuqt in forum Newbie
    Replies: 1
    Last Post: 14th June 2010, 21:37
  3. 2D OpenGL text rendering with existing app
    By bytebucket in forum Newbie
    Replies: 7
    Last Post: 11th March 2010, 21:28
  4. OpenGL rendering and threads
    By brcain in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2008, 10:45
  5. OpenGL rendering problem
    By spud in forum Qt Programming
    Replies: 5
    Last Post: 27th February 2007, 20:44

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.