Results 1 to 2 of 2

Thread: Fragment shader with 2d

  1. #1
    Join Date
    Dec 2010
    Posts
    1
    Qt products
    Qt4

    Default Fragment shader with 2d

    What should I do to make this simple shader work (everything should be blue I guess)?
    Qt Code:
    1. class GLWidget : public QGLWidget {
    2. public:
    3. GLWidget(QWidget *parent = 0): QGLWidget(parent) {}
    4. protected:
    5. void initializeGL()
    6. {
    7. this->setFixedSize(200,200);
    8. fbo = new QGLFramebufferObject(200, 200);
    9. QPainter p(fbo);
    10. p.fillRect(10,10,30,30,Qt::yellow);
    11.  
    12. QGLShaderProgram shader(this);
    13. if(shader.addShaderFromSourceCode(QGLShader::Fragment,
    14. "void main(void) {gl_FragColor = vec4(0, 0, 1, 1.0);}"))
    15. qDebug("Shader prepared.");
    16. shader.link();
    17. shader.bind();
    18. }
    19. void paintEvent(QPaintEvent *event)
    20. {
    21. QPainter painter(this);
    22. //painter.fillRect(0,0,200,100, Qt::gray); // line2
    23. painter.fillRect(60,20,30,30, Qt::gray);
    24. drawTexture(QPoint(10, 10), fbo->texture());
    25.  
    26. }
    27. private:
    28. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Fragment shader with 2d

    Qt Code:
    1. QGLShaderProgram shader(this);
    To copy to clipboard, switch view to plain text mode 
    Try to create shader object on the heap:
    Qt Code:
    1. QGLShaderProgram * shader = new QGlShaderProgram(this);
    To copy to clipboard, switch view to plain text mode 
    In your code "shader" goes out of scope, this probably unloads it from the rendering pipeline.

Similar Threads

  1. Geometry shader with QT4.7
    By saraksh in forum General Programming
    Replies: 3
    Last Post: 28th March 2011, 16:40
  2. Node Shader Editor
    By AMDx64BT in forum Newbie
    Replies: 1
    Last Post: 6th December 2009, 22:30
  3. Extracting xml fragment from QXmlStreamReader
    By Gopala Krishna in forum Qt Programming
    Replies: 5
    Last Post: 1st December 2007, 09:14
  4. GLSL shaders - keeping a value per fragment iteration
    By high_flyer in forum General Programming
    Replies: 3
    Last Post: 22nd June 2007, 15:22
  5. Failed to create fragment programs.
    By jeeman in forum Qt Programming
    Replies: 5
    Last Post: 19th June 2007, 00:03

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.