2 Attachment(s)
problem on QGLWidget and QGLFramebufferObject
I wrote a simple code using QGLWidget and QGLFramebufferObject like this:
Code:
#include <QApplication>
#include <QTextDocument>
#include <QPainter>
#include <QGLFramebufferObject>
#include <QGLWidget>
public:
~GLWidget() {if (fbo) delete fbo;}
protected:
void initializeGL() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
doc.setHtml("<font color=red>Test text</font>");
doc.
drawContents(&p,
QRect(QPoint(0,
0), fbo
->size
()));
p.end();
}
void resizeGL(int w, int h) {
if(h == 0) h = 1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, (GLfloat) w, (GLfloat) h, 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
painter.fillRect(r, Qt::white);
r.moveTo(100, 0); // line1
painter.fillRect(r, Qt::black); // line2
drawTexture
(QPoint(10,
10), fbo
->texture
());
}
private:
};
int main(int argc, char **argv) {
GLWidget w;
w.resize(200, 100);
w.show();
return app.exec();
}
I expected red texts, but the result is black texts like the attached file "tow-color.png"
http://www.qtcentre.org/forum/attach...1&d=1229158073
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".
http://www.qtcentre.org/forum/attach...1&d=1229158073
What's going on?
And, how can I get red texts with the original code?
Re: problem on QGLWidget and QGLFramebufferObject
I think, when you fillRect(...,Qt::black), you setBrush to black color.
May be -
Code:
painter.fillRect(r, Qt::black); // line2
painter.setBrush(Qt::red);// ???
drawTexture
(QPoint(10,
10), fbo
->texture
());
:)
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.