Results 1 to 2 of 2

Thread: QPainter and Shader

  1. #1
    Join Date
    Apr 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QPainter and Shader

    Hello

    I'm using OpenGL in a QGraphicScene with drawBackground(

    I create a simple shader that just change the pixel's color of a Qpainter rect
    The shader works only the second time I use it


    Qt Code:
    1. void drawBackground( QPainter *pPainter, const QRectF &pRect )
    2. {
    3. glClearColor( mBackGroundColor.redF(), mBackGroundColor.greenF(), mBackGroundColor.blueF(), 1.0f );
    4.  
    5. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    6. glClearDepth(1.0f);
    7.  
    8. glMatrixMode( GL_PROJECTION );
    9. glPushMatrix();
    10. glLoadIdentity();
    11.  
    12. lViewAngle = lViewAngle * 360.0 / M_PI;
    13. gluPerspective( lViewAngle, width() / height(), 0.1, 200 );
    14.  
    15. glMatrixMode( GL_MODELVIEW );
    16.  
    17. //OPENGL STUFF
    18.  
    19. glPopMatrix();
    20. glMatrixMode( GL_PROJECTION );
    21. pPainter->endNativePainting();
    22.  
    23. //shader doesn't work
    24. shader.bind();
    25. pPainter->fillRect(0, 0, 128, 128, Qt::black);
    26. shader.release();
    27.  
    28. //shader work
    29. shader.bind();
    30. pPainter->fillRect(100, 100, 128, 128, Qt::black);
    31. shader.release();
    32. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for your help

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPainter and Shader

    what happens if you switch the order - first use the 100,100 one, then the 0,0?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Geometry shader with QT4.7
    By saraksh in forum General Programming
    Replies: 3
    Last Post: 28th March 2011, 16:40
  2. Replies: 2
    Last Post: 7th February 2011, 16:19
  3. Replies: 1
    Last Post: 24th December 2010, 00:15
  4. Fragment shader with 2d
    By krzat in forum Newbie
    Replies: 1
    Last Post: 20th December 2010, 21:37
  5. Node Shader Editor
    By AMDx64BT in forum Newbie
    Replies: 1
    Last Post: 6th December 2009, 22:30

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.