I am trying to texture map an image to a single polygon. My image is being read correctly, but only the red plane of the image is being textured.
I am doing this within a QGLWidget
I have checked the image after it is read, and it's components are being read correctly--ie, I get valid values for the green and blue planes.
Here is the code
QImageReader *theReader = new QImageReader();
theReader->setFileName(imageFileName);
QImage theImageRead = theReader->read();
if(theImageRead.isNull())
{
validTile = NOT_VALID_IMAGE_FILE;
return;
}
else
{
int newW = 1;
int newH = 1;
while(newW < theImageRead.width())
{
newW *= 2;
}
while(newH < theImageRead.height())
{
newH *= 2;
}
theImageRead = theImageRead.scaled(newW, newH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
// values checked in theImageRead are OK here
glGenTextures(1,&textureObject);
theTextureImage = QGLWidget::convertToGLFormat(theImageRead);
// values checked in theTextureImage are OK here
glBindTexture(GL_TEXTURE_2D, textureObject);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,newW, newH, 0, GL_RGBA, GL_UNSIGNED_BYTE,theTextureImage.bits() );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glFlush();
validTile = VALID_TEXTURE;
return;
}
then I draw like this:
{ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,textureTiles[tN]->getTextureObject() ); glBegin(GL_QUADS); glTexCoord2f(0.0,0.0); glVertex2f(textureTiles[tN]->lowerLeft.x(), textureTiles[tN]->lowerLeft.y()); glTexCoord2f(1.0,0.0); glVertex2f(textureTiles[tN]->lowerRight.x(), textureTiles[tN]->lowerRight.y()); glTexCoord2f(1.0,1.0); glVertex2f(textureTiles[tN]->upperRight.x(), textureTiles[tN]->upperRight.y()); glTexCoord2f(0.0,1.0); glVertex2f(textureTiles[tN]->upperLeft.x(), textureTiles[tN]->upperLeft.y()); glEnd(); glDisable(GL_TEXTURE_2D); }
Does anybody see anything that would cause my texture to be interpreded as if it is values of (r,0,0,1)? (r,g,b,a)?
QT 4.7.1, Ubuntu 10.04, openGl 2.something or other
thanks in advance for any help
glColor()
call somewhere that you forgot about? – genpfault