我正在使用此答案将我的图片嵌入.exe:
Embedding resources in executable using GCC
以下是我的代码的相关部分:
GLuint grass_DTexture;
extern char binary_grass_D_bmp_start[];
extern char binary_grass_D_bmp_size[];
short loadTexture(char *imageData[], GLuint *texture) {
*texture = SOIL_load_OGL_texture_from_memory(imageData, sizeof(*imageData), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
return 1;
}
loadTexture(&binary_grass_D_bmp_start, &grass_DTexture);
然而,纹理没有加载,我只是得到一个白色的灰色表面。
编辑:我知道这不是我原来的问题,但是我在使用mipmap时遇到了困难。我将loadTexture函数修改为: short loadTexture(char * imageData [],GLuint * texture,int width,int height){ glEnable(GL_TEXTURE_2D); glGenTextures(1,texture); glBindTexture(GL_TEXTURE_2D,* texture); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
*texture = SOIL_load_OGL_texture_from_memory(imageData, sizeof(*imageData), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_MIPMAPS);
//gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, imageData);
//glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, width, height);
//glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, imageData);
//glGenerateMipmap(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_2D);
return 1;
}
这次,exe一旦运行就会崩溃。我也受到以下警告的欢迎,这可能是造成这种情况的原因(可能缺少一个*或一个&某处):
init.c:76:2: warning: passing argument 1 of 'loadTexture' from incompatible poin
ter type [enabled by default]
loadTexture.h:1:7: note: expected 'char **' but argument is of type 'char (*)[]'
我已设法将崩溃范围缩小到SOIL_load_OGL_texture_from_memory调用。
答案 0 :(得分:2)
GL_TEXTURE_MIN_FILTER
默认为GL_NEAREST_MIPMAP_LINEAR
。