0

我有以下用于渲染纹理的代码:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable( GL_BLEND );
    glClearColor(0.0,0.0,0.0,0.0);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, *tex);
    glBegin (GL_QUADS);
    glTexCoord2f (0.0, 0.0);
    glVertex2f (sx, sy);
    glTexCoord2f (1.0, 0.1);
    glVertex2f (sx + sxmax, sy);
    glTexCoord2f (1.0, 1.0);
    glVertex2f (sx + sxmax, sy + symax);
    glTexCoord2f (0.0, 1.0);
    glVertex2f (sx, sy + symax);
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glDisable( GL_BLEND );
    glClearColor(0.5,0.5,0.5,0.0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glPopAttrib();

在运行该代码之前,我执行以下操作: glGenTextures (1, tex); 然而,它只是在屏幕上生成一个白框。tex 是 GLuint 类型,使用以下命令创建:

GLuint GetTexture (string Filename) {
    GLuint tex_ID;
    tex_ID = SOIL_load_OGL_texture (
                 Filename.c_str(),
                 SOIL_LOAD_AUTO,
                 SOIL_CREATE_NEW_ID,
                 SOIL_FLAG_POWER_OF_TWO
                 | SOIL_FLAG_MIPMAPS
                 | SOIL_FLAG_MULTIPLY_ALPHA
                 | SOIL_FLAG_COMPRESS_TO_DXT
                 | SOIL_FLAG_DDS_LOAD_DIRECT
                 | SOIL_FLAG_INVERT_Y
             );

    if ( tex_ID > 0 ) {
        glEnable ( GL_TEXTURE_2D );
        glBindTexture ( GL_TEXTURE_2D, tex_ID );
        return tex_ID;
    } else {
        cout << "Texture failed to load" << SOIL_last_result() << Filename << endl;
        return 0;
    }
}

我正在使用土壤来生成纹理并使用 GLFW 来显示它,这都是在 C++ 中的。我做错了什么?

运行 glgeterror 返回错误代码 1281

4

0 回答 0