Qt5 opengl无法将bmp图像文件作为纹理加载到立方体 [英] Qt5 opengl cannot load bmp image file as texture to cube
问题描述
我发现这个基于NEHE Tutorial的示例项目但是在我的Qt版本5上没有用,尝试编辑一些代码,但是这个文件无法加载。并且还有警告
I found this sample project based on NEHE Tutorial but doesn't work on my Qt version 5, tried editing some code but this the file cannot be loaded. And warning exists also
<pre lang="c++">
警告:C4005:'CALLBACK' :宏重新定义
此行给出宏警告,文件为minwindef.h:
warning: C4005: 'CALLBACK': macro redefinition
this line gives the macro warning and the file is minwindef.h:
#define CALLBACK __stdcall
代码:
The codes:
void loadGLTextures()
{
QImage t;
QImage b;
if ( !b.load( ":/images/nehe.bmp" ) )
{
//b = QImage( 16, 16, 32 ); //original
//b.fill( Qt::green.rgb() ); //original
QMessageBox::information(this, "Error", "Could not load file");
QImage b(16, 16, QImage::Format_RGB32); //*******
b.fill(Qt::green); //*************
}
t = QGLWidget::convertToGLFormat( b );
if(t.isNull())
{
QMessageBox::information(this, "Error", "IMAGE IS NULL");
}
glGenTextures( 1, texture );// Create The Texture
glBindTexture( GL_TEXTURE_2D, texture[0] ); //assign a texture name to texture data.
glTexImage2D( GL_TEXTURE_2D, 0, 3, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
//Linear Filtering
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
运行代码后,QMessage弹出无法加载文件 ,我不确定是不是错了。
我尝试了什么:
尝试更改一些原始代码,但仍然无法加载错误bmp文件
After running the code, QMessage pops saying 'Could not load file', I am not sure if what's wrong.
What I have tried:
tried changing some original code but still error bmp file cannot be loaded
推荐答案
这对我来说看起来不像是一个有效的文件名:
That doesn't look like a valid file name to me :
if ( !b.load( ":/images/nehe.bmp" ) )
您需要删除冒号或插入驱动器号。
You need to either remove the colon or insert a drive letter.
这篇关于Qt5 opengl无法将bmp图像文件作为纹理加载到立方体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!