C++ C++;OpenGL/SDL 2.0加载纹理失败
如果尝试加载纹理,则会出现以下错误:C++ C++;OpenGL/SDL 2.0加载纹理失败,c++,opengl,textures,loading,sdl-2,C++,Opengl,Textures,Loading,Sdl 2,如果尝试加载纹理,则会出现以下错误: Access violation reading location. Unhandled exception at 0x651B5A17 (nvcuda.dll) in nsighttest.exe: 0xC0000005: Access violation reading location 0x00000010. 图片: 调试映像: unsigned int loadTexture(const char*filename,texProperties
Access violation reading location.
Unhandled exception at 0x651B5A17 (nvcuda.dll) in nsighttest.exe: 0xC0000005: Access violation reading location 0x00000010.
图片:
调试映像:
unsigned int loadTexture(const char*filename,texProperties)
{
闪烁数=0;
盂型;
SDL_表面*img=img_载荷(文件名);
cout查看glTexImage2D()函数,看起来您正在使用
img->w
两次,而不是第二次使用img->h
试着打电话
glTexImage2D(GL_TEXTURE_2D, 0 , numberofcolors=4?GL_RGBA:GL_RGB, img->w, /*Use height as second parameter, rather than width!*/img->h, 0, format, GL_UNSIGNED_BYTE, img->pixels);
相反。你为什么不检查SDL\u LoadBMP()
的返回值,或者验证你要返回的SDL\u曲面实际上是GL\u UNSIGNED\u SHORT\u 5\u 6\u 5
?我已经检查了返回值,但我得到了一些数字,并尝试使用“GL\u UNSIGNED\u SHORT\u 5\u 6\u 5”同样的结果也会让人猜测,与99%的图像问题一样,它没有加载,因为它位于错误的位置或其他地方。您需要检查SDL\u Surface*img
是否为有效的内存位置,即在使用带三个通道的24位BMP之后,不为空。
glTexImage2D(GL_TEXTURE_2D, 0 , numberofcolors=4?GL_RGBA:GL_RGB, img->w, /*Use height as second parameter, rather than width!*/img->h, 0, format, GL_UNSIGNED_BYTE, img->pixels);