每次加载第四个纹理时,我都会遇到分段错误- 什么类型的纹理,我的意思是文件名,并不重要。我检查了 value原来是10所以远远超过4,不是吗?GL_TEXTURES_STACK_SIZE
这是代码片段:
从png加载纹理的功能
static GLuint gl_loadTexture(const char filename[]) {
static int iTexNum = 1;
GLuint texture = 0;
img_s *img = NULL;
img = img_loadPNG(filename);
if (img) {
glGenTextures(iTexNum++, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, img->iGlFormat, img->uiWidth, img->uiHeight, 0, img->iGlFormat, GL_UNSIGNED_BYTE, img->p_ubaData);
img_free(img); //it may cause errors on windows
} else printf("Error: loading texture '%s' failed!\n", filename);
return texture;
}
实际加载
static GLuint textures[4];
static void gl_init() {
(...) //setting up OpenGL
/* loading textures */
textures[0] = gl_loadTexture("images/background.png");
textures[1] = gl_loadTexture("images/spaceship.png");
textures[2] = gl_loadTexture("images/asteroid.png");
textures[3] = gl_loadTexture("images/asteroid2.png"); //this is causing SegFault no matter which file I load!
}
有任何想法吗?