Hi everyone,
I’m doing some fairly basic code that takes a 2D texture and applies it to a quad. The problem is the texturing works on some machines and not others. The code is not that complex and i’m pretty sure it’s right but I’ve included it below. Does anyone have any ideas as to why it works on some computers and not others? I’m using Qt for my windowing environment but I don’t think that it is causing the problem.
// some of the initialisation code
void VtButton::init() {
// this just grabs the texture from a QtWidget. Is working correctly
QPixmap tmpPixmap = QPixmap::grabWidget(button, 0, 0, -1, -1);
QImage tempImage = tmpPixmap.convertToImage();
texture = new QImage(QGLWidget::convertToGLFormat(tmpImage));
...
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glTexImage2D(GL_TEXTURE_2D, 0, 3,
texture->width(), texture->height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, texture->bits());
}
// this is what draws & textures my quad
void VtButton::drawTerminal() {
glPushMatrix();
glLoadIdentity();
glTranslate(pos.x, pos.y, pos.z);
glColour4f(colour.r, colour.g, colour.b, colour.a);
// this just grabs the texture from a QtWidget. Is working correctly
QPixmap tmpPixmap = QPixmap::grabWidget(button, 0, 0, -1, -1);
QImage tempImage = tmpPixmap.convertToImage();
delete texture;
texture = new QImage(QGLWidget::convertToGLFormat(tmpImage));
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glBindTexture(GL_TEXTURE_2D, texName);
glTexImage2D(GL_TEXTURE_2D, 0, 3,
texture->width(), texture->height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, texture->bits());
glBegin(GL_QUADS);
glTexCoord2f(1.0, 1.0); glVertex(vertex0.x, vertex0.y, vertex0.z);
glTexCoord2f(0.0, 1.0); glVertex(vertex1.x, vertex1.y, vertex1.z);
glTexCoord2f(0.0, 0.0); glVertex(vertex2.x, vertex2.y, vertex2.z);
glTexCoord2f(1.0, 0.0); glVertex(vertex3.x, vertex3.y, vertex3.z);
glEnd();
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}
The result when it all works is a semi transparent quad of colour ‘colour.rgba’ blended with the texture caputred from the QtWidget. When it doesn’t work (ie. when run on some other computers) the result is just the semi transparent quad of colour ‘colour.rgba’.
Any ideas or suggestions as to what’s going wrong and how to fix it would be greatly appreciated.
Thanks .