OpenGL Mipmap 和 SOIL 标志
所以我现在加载了我的图像,但它说你可以设置一个标志 MipMap 生成。我设置了标志,据我所知 OpenGL 会这样做 在某些时候使用 MipMap 时要休息。
我这件事有错吗?如果是的话,如何让 MipMap 发挥作用?
编辑:所以这是我的初始化函数,我在其中调用 SOIL 来加载带有 MIPMAPS 标志的图像
//========================================
// init
//========================================
void init(void) {
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable (GL_BLEND); //transparency
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
timerSpeed = 1000.0/60.0;
for(int i=0; i<6; i++) {
TextureNames[i] = TextureNames[i]+".bmp";
TextureArray[i] = SOIL_load_OGL_texture((char*)TextureNames[i].c_str(),3,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO |
SOIL_FLAG_MIPMAPS);
}
}
,这就是我调用 bindtexture 和 texparam 的地方(简短地说,因为它只是另一个 函数的立方体面、popmatrix 和 end }
void drawCube(void) {
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, TextureArray[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//FRONT FACE OF CUBE
glNormal3f(0.0,0.0,1.0);
glBegin(GL_POLYGON);
glTexCoord2f(0.0,0.0); glVertex3f(-1.0,-1.0,1.0);
glTexCoord2f(1.0,0.0); glVertex3f(1.0,-1.0,1.0);
glTexCoord2f(1.0,1.0); glVertex3f(1.0,1.0,1.0);
glTexCoord2f(0.0,1.0); glVertex3f(-1.0,1.0,1.0);
glEnd();
//LEFT FACE OF CUBE
glNormal3f(-1.0,0.0,0.0);
glBegin(GL_POLYGON);
glTexCoord2f(0.0,0.0); glVertex3f(-1.0,-1.0,-1.0);
glTexCoord2f(1.0,0.0); glVertex3f(-1.0,-1.0,1.0);
glTexCoord2f(1.0,1.0); glVertex3f(-1.0,1.0,1.0);
glTexCoord2f(0.0,1.0); glVertex3f(-1.0,1.0,-1.0);
glEnd();
So i got the SOIL loading my images now, but it says you can set a flag for
the MipMap generation. I set the flag and as far as I know OpenGL does the
rest when it comes to using the MipMaps at certain times.
Am I wrong in this? and if I am, how do I get the MipMaps to work?
EDIT: So this is my init function where I call SOIL to load my image with the FLAG for MIPMAPS
//========================================
// init
//========================================
void init(void) {
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable (GL_BLEND); //transparency
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
timerSpeed = 1000.0/60.0;
for(int i=0; i<6; i++) {
TextureNames[i] = TextureNames[i]+".bmp";
TextureArray[i] = SOIL_load_OGL_texture((char*)TextureNames[i].c_str(),3,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO |
SOIL_FLAG_MIPMAPS);
}
}
And this is where I call bindtexture and texparam (cut it short because its just the other
faces of the cube, popmatrix and end } for the function
void drawCube(void) {
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, TextureArray[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//FRONT FACE OF CUBE
glNormal3f(0.0,0.0,1.0);
glBegin(GL_POLYGON);
glTexCoord2f(0.0,0.0); glVertex3f(-1.0,-1.0,1.0);
glTexCoord2f(1.0,0.0); glVertex3f(1.0,-1.0,1.0);
glTexCoord2f(1.0,1.0); glVertex3f(1.0,1.0,1.0);
glTexCoord2f(0.0,1.0); glVertex3f(-1.0,1.0,1.0);
glEnd();
//LEFT FACE OF CUBE
glNormal3f(-1.0,0.0,0.0);
glBegin(GL_POLYGON);
glTexCoord2f(0.0,0.0); glVertex3f(-1.0,-1.0,-1.0);
glTexCoord2f(1.0,0.0); glVertex3f(-1.0,-1.0,1.0);
glTexCoord2f(1.0,1.0); glVertex3f(-1.0,1.0,1.0);
glTexCoord2f(0.0,1.0); glVertex3f(-1.0,1.0,-1.0);
glEnd();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要切换纹理过滤以使用 mipmapping:
您可能还需要研究各向异性过滤模式以提高过滤质量:http://www.opengl.org/registry/specs/EXT/texture_filter_anisotropic.txt
You need to switch texture filtering to use mipmapping:
You also may want to look into anisotropic filtering modes for increased filtering quality: http://www.opengl.org/registry/specs/EXT/texture_filter_anisotropic.txt