【发布时间】:2018-05-06 02:17:17
【问题描述】:
我已经使用自己的迷你管道(使用 mipmaps)成功地在几何图形上显示纹理,但我决定不使用 mip-maps,因为我的软件实际上不需要任何细节级别的更改。它是 2d 并使用像素艺术。细节不应该改变。 我要补充一点,我正在尝试在纹理图集中循环纹理并禁用 mip 映射可能有助于避免问题。
但是,不调用 glGenerateMipmap 会产生空白屏幕。调用它会产生正确的纹理。
我必须调用另一个函数吗?
以下是我的纹理生成函数(我传递了一个指向已经创建的纹理 id 的指针。)
GLboolean GL_texture_load(Texture* texture_id, const char* const path, const GLboolean alpha, const GLint param_edge)
{
// load image
SDL_Surface* img = nullptr;
if (!(img = IMG_Load(path))) {
fprintf(stderr, "SDL_image could not be loaded %s, SDL_image Error: %s\n",
path, IMG_GetError());
return GL_FALSE;
}
glBindTexture(GL_TEXTURE_2D, *texture_id);
// image assignment
GLuint format = (alpha) ? GL_RGBA : GL_RGB;
glTexImage2D(GL_TEXTURE_2D, 0, format, img->w, img->h, 0, format, GL_UNSIGNED_BYTE, img->pixels);
glGenerateMipmap(GL_TEXTURE_2D); // commenting this out yields a blank screen
// wrapping behavior
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, param_edge);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, param_edge);
// texture filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // I won't want these because the texture should have constant detail / resolution
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
// free the surface
SDL_FreeSurface(img);
return GL_TRUE;
}
我将 SDL2_Image 用于 png 文件,并且纹理大小不一定是二次方。 (我还没有对此进行优化。)
我可能缺少什么?我应该设置哪些参数来渲染未过滤的纹理?我怀疑 mipmapping 是必需的。是否有可能没有 mipmapping 我不能像往常一样使用 sampler2D 或 texture() ?那会很奇怪。
提前谢谢你。
编辑:BDL 的回答有所帮助。供参考,以下是我修改后的代码:
GLboolean GL_texture_load(Texture* texture_id, const char* const path, const GLboolean alpha, const GLint param_edge_x, const GLint param_edge_y)
{
// load image
SDL_Surface* img = nullptr;
if (!(img = IMG_Load(path))) {
fprintf(stderr, "SDL_image could not be loaded %s, SDL_image Error: %s\n",
path, IMG_GetError());
return GL_FALSE;
}
glBindTexture(GL_TEXTURE_2D, *texture_id);
// image assignment
GLuint format = (alpha) ? GL_RGBA : GL_RGB;
glTexImage2D(GL_TEXTURE_2D, 0, format, img->w, img->h, 0, format, GL_UNSIGNED_BYTE, img->pixels);
// wrapping behavior
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, param_edge_x);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, param_edge_y);
// texture filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
// free the surface
SDL_FreeSurface(img);
return GL_TRUE;
}
【问题讨论】:
标签: opengl glsl textures opengl-3 mipmaps