xylosper
11th March 2011, 03:33
I wrote some code for test:
#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include <QtOpenGL/QGLFramebufferObject>
class GLWidget : public QGLWidget {
public:
GLWidget() {
m_big = font();
m_big.setPixelSize(100);
makeCurrent();
m_fbo = new QGLFramebufferObject(500, 150);
m_fbo->bind();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QPainter painter(m_fbo);
painter.setFont(m_big);
painter.drawText(QRect(0, 0, 500, 150), "Test Text");
m_fbo->release();
}
~GLWidget() {
delete m_fbo;
}
private:
void paintEvent(QPaintEvent *) {
QPainter painter(this);
painter.setFont(m_big);
painter.drawText(QRect(0, 0, 500, 150), "Test Text");
drawTexture(QPointF(0.0, 150.0), m_fbo->texture());
}
QFont m_big;
QGLFramebufferObject *m_fbo;
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
GLWidget w;
w.show();
return app.exec();
}
The above codes do drawing two lines of "Test Text" on QGLWidget.
Upper one is done by directly onto QGLWidget with QPainter, and the lower one is done by drawTexture whose texture is drawn in QGLFramebufferObject.
The result is attached.
6070
Both of them have problems.
Upper one(drawn by QGLWidget with QPainter) is not anti-aliased.
Lower one(drawn by QGLFramebufferObject) just shows black box.
Also, when I tried with multi-sampled QGLWidget(with like QGLFormat::setSamples(4)), Upper one looks as same as lower one, that is, only black box.
If you try with small font size, both of them display the texts normally.
Is this a bug? or Did I mistake something?
#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include <QtOpenGL/QGLFramebufferObject>
class GLWidget : public QGLWidget {
public:
GLWidget() {
m_big = font();
m_big.setPixelSize(100);
makeCurrent();
m_fbo = new QGLFramebufferObject(500, 150);
m_fbo->bind();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QPainter painter(m_fbo);
painter.setFont(m_big);
painter.drawText(QRect(0, 0, 500, 150), "Test Text");
m_fbo->release();
}
~GLWidget() {
delete m_fbo;
}
private:
void paintEvent(QPaintEvent *) {
QPainter painter(this);
painter.setFont(m_big);
painter.drawText(QRect(0, 0, 500, 150), "Test Text");
drawTexture(QPointF(0.0, 150.0), m_fbo->texture());
}
QFont m_big;
QGLFramebufferObject *m_fbo;
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
GLWidget w;
w.show();
return app.exec();
}
The above codes do drawing two lines of "Test Text" on QGLWidget.
Upper one is done by directly onto QGLWidget with QPainter, and the lower one is done by drawTexture whose texture is drawn in QGLFramebufferObject.
The result is attached.
6070
Both of them have problems.
Upper one(drawn by QGLWidget with QPainter) is not anti-aliased.
Lower one(drawn by QGLFramebufferObject) just shows black box.
Also, when I tried with multi-sampled QGLWidget(with like QGLFormat::setSamples(4)), Upper one looks as same as lower one, that is, only black box.
If you try with small font size, both of them display the texts normally.
Is this a bug? or Did I mistake something?