OpenGL texture on QGraphicsScene background
Hello!
I try to draw texture on QGraphicsScene background. QGraphicsView object has QGLWidget object as the viewport.
Reimplemented QGraphicsScene::drawBackground function is:
Code:
void OWorkspaceScene
::drawBackground(QPainter *painter,
const QRectF &rect
) {
GLuint texture[1];
b.load("../images/image.bmp"); // image size 256x256
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?
Re: OpenGL texture on QGraphicsScene background
Have you checked that the path to the image is correct and that the image gets loaded?
BTW. Using Qt methods for binding the texture might be a bit less error prone, i.e.
Code:
bindTexture
(QPixmap(":/images/side.png"), GL_TEXTURE_2D
);
Re: OpenGL texture on QGraphicsScene background
Quote:
Originally Posted by
wysota
Have you checked that the path to the image is correct and that the image gets loaded?
BTW. Using Qt methods for binding the texture might be a bit less error prone, i.e.
Code:
bindTexture
(QPixmap(":/images/side.png"), GL_TEXTURE_2D
);
Yes. The path to the image is correct and that the image gets loaded.
Same code works fine with QGLWidget in QGLWidget::paintGL().
Re: OpenGL texture on QGraphicsScene background
Re: OpenGL texture on QGraphicsScene background
Quote:
Originally Posted by
wysota
Unfortunately, i use QT-4.3.1. In addition, i want solve problem with method presented above.
Re: OpenGL texture on QGraphicsScene background
The version doesn't matter. I gave you the link because there is OpenGL used to implement drawBackground() for a graphics scene. Maybe you need to do something special for GL to work there and maybe you'll find it in the source code of the article.