0

使用 SOIL 库,我尝试在绘制的网格下方加载图像;这是此功能的代码:

void ModelGL:: LoadTexture()
{
        texture[0] = SOIL_load_OGL_texture("images/GolSa.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);

        //if(texture[0] == 0)
        //exit(1);


    // Typical Texture Generation Using Data From The Bitmap
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glBegin(GL_QUADS);
    //Bottom Face (true)
    glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f( -1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f( -1.0f, -1.0f,  1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f,  1.0f);
    glEnd();

    glDisable(GL_TEXTURE_2D);

}

但在输出中我看不到图片;

4

1 回答 1

1

glBindTexture(...)尝试之前或之后glActiveTexture(GL_TEXTURE0)

编辑:
由于您正在使用它们,因此在使用它们之前glTexCoords*(...)必须先启用glEnable(GL_TEXTURE_2D)它们。

以下是纹理立方体的示例:
http
://www.gamasutra.com/view/feature/131768/understanding_and_using_opengl_.php?print=1 阅读该部分A First Try at Texturing

于 2013-10-29T13:20:24.173 回答