在 C++ 中使用 DevIL 和 OpenGL 加载图像
正如标题所示,我尝试使用 DevIL 加载图像,然后将其传递给 OpenGL。我使用这段代码作为错误控制
const char* filename = "back.bmp";
if (!ilLoadImage(filename))
{
throw runtime_error(std::string("Unable to load image") +filename);
}
,对于 if 语句,返回错误
error C2664: 'ilLoadImage' : cannot convert parameter 1 from 'const char *' to 'const wchar_t *'
如果我将 filename
定义为 const wchar_t* filename
,我会得到错误
error C2664: 'ilLoadImage' : cannot convert parameter 1 from 'const char *' to 'const wchar_t *'
所以对于现在我不会因为好奇为什么 [filename].bmp 文件是 wchar_t* 类型,或者 wchar_t 是什么(谷歌让我困惑)而感到厌倦,我只会问我必须做什么才能使它工作:为什么是它不起作用?我错过了什么?我确信一定有一个非常简短的解决方案。它看起来就像是那种错误。
谢谢。
As the title suggests, I am trying to load an image using DevIL, before passing it to OpenGL. I am using this piece of code as error control
const char* filename = "back.bmp";
if (!ilLoadImage(filename))
{
throw runtime_error(std::string("Unable to load image") +filename);
}
which, for the if statement, returns the error
error C2664: 'ilLoadImage' : cannot convert parameter 1 from 'const char *' to 'const wchar_t *'
If I define filename
as const wchar_t* filename
, I get the error
error C2664: 'ilLoadImage' : cannot convert parameter 1 from 'const char *' to 'const wchar_t *'
So for now I will not tire you with my curiosity of why a [filename].bmp file is of type wchar_t*, or what wchar_t is, which Google confused me over, and I will only ask what I must to make it work: Why is it not working? What have I missed? There must be a very short solution for this, I am sure. It just looks like that kind of error.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 Unicode 函数,则必须使用 Unicode 文本。具体来说,
L
将返回静态文本的宽字符表示形式:如果您正在为 ANSI 和宽字符串编译代码,请改用
_T()
,这会返回正确的结果字符串类型:如果您属于后一种情况,并且不知道编译时需要什么类型的
char
,请使用TCHAR
,它是CHAR
或WCHAR
取决于是否定义了UNICODE
。If you use Unicode functions, you have to use Unicode text. Specifically,
L
will return the wide char representation of static text:If you're compiling code for both ANSI and wide strings, use
_T()
instead, which returns the correct type of string:If you're in the latter case and don't know what types of
char
s you'll need at compile time, useTCHAR
, which is either aCHAR
or aWCHAR
depending on whetherUNICODE
is defined.如果您使用的是 Visual Studio,请尝试更改项目以使用多字节字符集。
If you're using Visual Studio, try changing the project to use Multi byte charset.