#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();
}
#include <QApplication>
#include <QTextDocument>
#include <QPainter>
#include <QGLFramebufferObject>
#include <QGLWidget>
class GLWidget : public QGLWidget {
public:
GLWidget(QWidget *parent = 0): QGLWidget(parent), fbo(0) {}
~GLWidget() {if (fbo) delete fbo;}
protected:
void initializeGL() {
fbo = new QGLFramebufferObject(200, 200);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
QTextDocument doc;
doc.setHtml("<font color=red>Test text</font>");
QPainter p(fbo);
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();
}
void paintEvent(QPaintEvent *event) {
QPainter painter(this);
QRect r = rect();
painter.fillRect(r, Qt::white);
r.moveTo(100, 0); // line1
painter.fillRect(r, Qt::black); // line2
drawTexture(QPoint(10, 10), fbo->texture());
}
private:
QGLFramebufferObject *fbo;
};
int main(int argc, char **argv) {
QApplication app(argc, argv);
GLWidget w;
w.resize(200, 100);
w.show();
return app.exec();
}
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"
Bookmarks