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();
}
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();
}
To copy to clipboard, switch view to plain text mode
As a result i have grey square nice image instead.
Bookmarks