【发布时间】:2011-12-18 01:25:25
【问题描述】:
我正在尝试使用可可应用加载文件,但该应用无法找到该文件
我用的是SDL_image,代码是:
SDL_Surface* 表面 = IMG_Load(file);
文件是:“/Resources/cursor.png”
我尝试在 Objective-C 中使用一些代码,但应用程序无法运行,因为它是用 c++ 编写的
谢谢, 丹尼尔
更新:
纹理加载代码:
GLuint CGLTexture::load_texture(const char* file, bool wrap)
{
SDL_Surface* surface = IMG_Load(file);
if (!surface) {
printf("Error, probably the file isn't there :S");
return 0;
}
GLuint texture;
glPixelStorei(GL_UNPACK_ALIGNMENT,4);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
SDL_PixelFormat *format = surface->format;
// select modulate to mix texture with color for shading
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// when texture area is small, bilinear filter the closest mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST );
// when texture area is large, bilinear filter the first mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// if wrap is true, the texture wraps over at the edges (repeat)
// ... false, the texture ends at the edges (clamp)
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
wrap ? GL_REPEAT : GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
wrap ? GL_REPEAT : GL_CLAMP );
if (format->Amask)
{
gluBuild2DMipmaps(GL_TEXTURE_2D, 4,
surface->w, surface->h, GL_RGBA,GL_UNSIGNED_BYTE, surface->pixels);
}
else
{
gluBuild2DMipmaps(GL_TEXTURE_2D, 3,
surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
}
SDL_FreeSurface(surface);
return texture;
}
我这样称呼这个函数:
cursorTexture = CGLTexture::load_texture("/Resources/cursor.png",false);
该文件永远找不到,我认为这是应用程序包中的某个位置,但是,我如何使用 c++ 访问它?
【问题讨论】:
-
相关代码和错误信息?
-
嘿,我已经更新了问题,提供了有关问题的更多信息,谢谢^^