Results 1 to 3 of 3

Thread: problem on QGLWidget and QGLFramebufferObject

  1. #1
    Join Date
    Apr 2007
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem on QGLWidget and QGLFramebufferObject

    I wrote a simple code using QGLWidget and QGLFramebufferObject like this:
    Qt Code:
    1. #include <QApplication>
    2. #include <QTextDocument>
    3. #include <QPainter>
    4. #include <QGLFramebufferObject>
    5. #include <QGLWidget>
    6.  
    7. class GLWidget : public QGLWidget {
    8. public:
    9. GLWidget(QWidget *parent = 0): QGLWidget(parent), fbo(0) {}
    10. ~GLWidget() {if (fbo) delete fbo;}
    11. protected:
    12. void initializeGL() {
    13. fbo = new QGLFramebufferObject(200, 200);
    14. glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    15. doc.setHtml("<font color=red>Test text</font>");
    16. QPainter p(fbo);
    17. doc.drawContents(&p, QRect(QPoint(0, 0), fbo->size()));
    18. p.end();
    19. }
    20. void resizeGL(int w, int h) {
    21. if(h == 0) h = 1;
    22. glViewport(0, 0, w, h);
    23. glMatrixMode(GL_PROJECTION);
    24. glLoadIdentity();
    25. gluOrtho2D(0.0f, (GLfloat) w, (GLfloat) h, 0.0f);
    26. glMatrixMode(GL_MODELVIEW);
    27. glLoadIdentity();
    28. }
    29. void paintEvent(QPaintEvent *event) {
    30. QPainter painter(this);
    31. QRect r = rect();
    32. painter.fillRect(r, Qt::white);
    33. r.moveTo(100, 0); // line1
    34. painter.fillRect(r, Qt::black); // line2
    35. drawTexture(QPoint(10, 10), fbo->texture());
    36. }
    37. private:
    38. };
    39.  
    40. int main(int argc, char **argv) {
    41. QApplication app(argc, argv);
    42. GLWidget w;
    43. w.resize(200, 100);
    44. w.show();
    45. return app.exec();
    46. }
    To copy to clipboard, switch view to plain text mode 
    I expected red texts, but the result is black texts like the attached file "tow-color.png"


    I found out that the commenting out the line1 and line2 of the paintEvent() in the class changes the result like the attached file "one-color.png".


    What's going on?
    And, how can I get red texts with the original code?
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem on QGLWidget and QGLFramebufferObject

    I think, when you fillRect(...,Qt::black), you setBrush to black color.

    May be -
    Qt Code:
    1. painter.fillRect(r, Qt::black); // line2
    2. painter.setBrush(Qt::red);// ???
    3. drawTexture(QPoint(10, 10), fbo->texture());
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2007
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem on QGLWidget and QGLFramebufferObject

    Thanks for answering.

    The color of brush doesn't matter, because the texts are already rendered by QTextDocument and all informations are in fbo's texture.
    In addition to that, I tried your code actually, but nothing is changed.

Similar Threads

  1. Replies: 4
    Last Post: 7th May 2008, 00:01
  2. QGLWidget Resize Problem
    By Sandip in forum Qt Programming
    Replies: 2
    Last Post: 28th February 2008, 06:47
  3. QGLWidget resize problem.
    By anderl in forum Qt Programming
    Replies: 2
    Last Post: 22nd January 2008, 08:57
  4. why linking problem with QGLWidget???
    By Shuchi Agrawal in forum Newbie
    Replies: 17
    Last Post: 16th March 2007, 10:45
  5. Problem combining QWorkspace & QGLWidget
    By Nb2Qt in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2006, 21:45

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.