【发布时间】:2011-01-13 06:40:56
【问题描述】:
我正在尝试将图像纹理映射到单个多边形。我的图像被正确读取,但只有图像的红色平面被纹理化。
我在 QGLWidget 中这样做
我在读取图像后检查了图像,并且它的组件被正确读取 - 即,我得到了绿色和蓝色平面的有效值。
这里是代码
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;
}
然后我这样画:
有没有人看到任何会导致我的纹理被解释为 (r,0,0,1) 值的东西? (r,g,b,a)?
QT 4.7.1、Ubuntu 10.04、openGl 2.something 或其他
提前感谢您的帮助
【问题讨论】:
-
您是否在某处忘记了
glColor()电话? -
在内部,OpenGL 采用 internalFormat 参数并将所需的任何计算应用于您的数据,以获取请求的格式。就 GL 而言,其结果(如果我正确理解文档)始终是 RGBA 图像。如果出于测试目的,您在函数调用中将 internalFormat 显式设置为 GL_RGBA 而不是 GL_RGB 会发生什么?
-
没什么——完全没有区别
标签: qt opengl texture-mapping