OpenGL Mipmap 和 SOIL 标志

发布于 2024-11-02 20:09:47 字数 2118 浏览 5 评论 0原文

所以我现在加载了我的图像,但它说你可以设置一个标志 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合约呢 2024-11-09 20:09:47

您需要切换纹理过滤以使用 mipmapping:

glBindTexture(GL_TEXTURE_2D, theTextureID);
glTexParamteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

您可能还需要研究各向异性过滤模式以提高过滤质量:http://www.opengl.org/registry/specs/EXT/texture_filter_anisotropic.txt

You need to switch texture filtering to use mipmapping:

glBindTexture(GL_TEXTURE_2D, theTextureID);
glTexParamteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文