texturing problems

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 :frowning: .

I’m beginning to suspect Qt might be to blame for my troubles. My texturing code seems to work fine on any images I load in.

-D.

Are you relying on a particular value for the environment color? I don’t see that you’re setting that when you set your GL_BLEND texture environment mode. :slight_smile:

Am I seeing things or is that glColour (glColor), glTranslate (glTranslate(f|d))?
Is this real code or are there function names I don’t know about :smiley:

Ooops. Good spotting Veg. It would appear that in the process of distilling my code down to the bits giving me greif, I have inadvertently made some spelling mistakes. glColour should infact be glColor (damned american spelling…) and glTranslate should read glTranslatef.

As far as the environment colour goes, it’s set elsewhere in the code. But, you have just brought it to my attention that I don’t fully understand how glTexEnvf works. I shall go and do some more reading.

However, my original problem seems to be being caused by the QImage not functioning correctly.

Cheers,
-D.

I thought it was a spelling thing :smiley:

It occured to me that you’re stetting a RGB internal format in you texture. That could have some bearing on your results with alpha as well, particularly with a subsequent combiner stage that deals with alpha, or blending with framebuffer dest alpha. Hard to tell without the big picture, but I thought I’d mention it just in case :slight_smile:

If it saves you some shoe leather, the texture environment tables can be found on page 185 of the spec.

Best regards. :slight_smile: