opengl generating a white box instead of a texture

1k views Asked by At

I have the following code which I am using to render a texture:

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();

Before that code is run I do the following: glGenTextures (1, tex); However it simply generates a white box on the screen. tex is of type GLuint and is created using the following:

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;
    }
}

I am using soil to generate the texture and GLFW to display it, this is all in C++. What have I done wrong?

running glgeterror returns error code 1281

0

There are 0 answers