Ovnan
10th July 2008, 12:58
Hello!
I try to draw texture on QGraphicsScene background. QGraphicsView object has QGLWidget object as the viewport.
Reimplemented QGraphicsScene::drawBackground function is:
void OWorkspaceScene::drawBackground(QPainter *painter, const QRectF &rect)
{
GLuint texture[1];
QImage t, b;
b.load("../images/image.bmp"); // image size 256x256
t = QGLWidget::convertToGLFormat(b);
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits());
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnable(GL_TEXTURE_2D);
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(0, 255);
glVertex2f(0, 255);
glTexCoord2f(255, 255);
glVertex2f(255, 255);
glTexCoord2f(255, 0);
glVertex2f(255, 0);
glEnd();
glFinish();
}
As a result i have grey square nice image instead.
When i draw color square (without texture), it works fine.
I work using QT-4.3.1 under Visual Studio 2005.
What do i do wrong?
I try to draw texture on QGraphicsScene background. QGraphicsView object has QGLWidget object as the viewport.
Reimplemented QGraphicsScene::drawBackground function is:
void OWorkspaceScene::drawBackground(QPainter *painter, const QRectF &rect)
{
GLuint texture[1];
QImage t, b;
b.load("../images/image.bmp"); // image size 256x256
t = QGLWidget::convertToGLFormat(b);
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits());
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnable(GL_TEXTURE_2D);
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(0, 255);
glVertex2f(0, 255);
glTexCoord2f(255, 255);
glVertex2f(255, 255);
glTexCoord2f(255, 0);
glVertex2f(255, 0);
glEnd();
glFinish();
}
As a result i have grey square nice image instead.
When i draw color square (without texture), it works fine.
I work using QT-4.3.1 under Visual Studio 2005.
What do i do wrong?