【发布时间】:2014-08-22 21:49:57
【问题描述】:
如果我尝试加载纹理,我会收到此错误:
Access violation reading location.
Unhandled exception at 0x651B5A17 (nvcuda.dll) in nsighttest.exe: 0xC0000005: Access violation reading location 0x00000010.
图片: http://img5.fotos-hochladen.net/uploads/error1wlbsuf0iv.png
调试图像: http://img5.fotos-hochladen.net/uploads/debugatc1xerob5.png
unsigned int loadTexture(const char* filename, texProperties properties)
{
GLint numberofcolors = 0;
GLenum format;
SDL_Surface * img = IMG_Load(filename);
cout << "Image height: " << img->h << endl;
cout << "Image width: " << img->w << endl;
cout << "Images Pixels: " << img->pixels << endl;
cout << "Images BitsPerPixel: " << img->format->BitsPerPixel << endl;
cout << "Images Rmask: " << img->format->Rmask << endl;
cout << "Images Surface: " << img << endl;
if(!(&img)) { std::cout << "Fehler beim laden des bildes: " << filename; std::cout << std::endl; }
if(img->format->BitsPerPixel == 4) {
if(img->format->Rmask == 0x000000ff) { format = GL_RGBA; }
else { format = GL_BGRA; }
numberofcolors = 4;
} else {
if(img->format->Rmask == 0x000000ff) { format = GL_RGB; }
else { format = GL_BGR; }
numberofcolors = 3;
}
unsigned int id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, properties.getMagFilter());
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, properties.getMinFilter());
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, properties.getTextureWrap());
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, properties.getTextureWrap());
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, properties.getAnisotropy());
glTexImage2D(GL_TEXTURE_2D, 0 , numberofcolors=4?GL_RGBA:GL_RGB, img->w, img->w, 0, format, GL_UNSIGNED_BYTE, img->pixels);
SDL_FreeSurface(img);
return id;
}
错误来自“glTexImage2D(...)”。
【问题讨论】:
-
你为什么不检查
SDL_LoadBMP()的返回值?或者验证您返回的SDL_Surface实际上是GL_UNSIGNED_SHORT_5_6_5? -
我已经检查了退货,但我得到了一些号码,我也尝试使用“GL_UNSIGNED_SHORT_5_6_5”但结果相同
-
我会冒险猜测,与 99% 的图像问题一样,它没有加载,因为它位于错误的位置或其他地方。您需要检查
SDL_Surface* img是否是有效的内存位置,即在您执行SDL_LoadBMP之后不为 NULL -
使用 24 位 BMP 和三个通道。
标签: c++ opengl textures loading sdl-2