opengl displaying white box instead of texture

929 views Asked by At

I have a texture which I am displaying using the following:

    glEnable (GL_BLEND);
glEnable(GL_TEXTURE_2D);
        glBlendFunc (GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
        glGenTextures(1, tex);
    glBindTexture (GL_TEXTURE_2D, *tex);
        glBegin (GL_QUADS);
        glTexCoord2f (tx, ty);
        glVertex2f (sx, sy);
        glTexCoord2f (tw, ty);
        glVertex2f (sx + sxmax, sy);
        glTexCoord2f (tw, th);
         glVertex2f (sx + sxmax, sy + symax);
        glTexCoord2f (tx, th);
       glVertex2f (sx, sy + symax);
        glEnd();
        glDisable (GL_TEXTURE_2D);
        glDisable (GL_BLEND);

I am loading the texture 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;
        }
    }

and passing it by reference to a class

When I run a check to see if the texture loaded properly:

if(tex==0)

it is. Additionally whenever i run glColor3f(); with some values nothing is displayed ont the screen. what have I done wrong?

I am using glfw and SOIL to load/display the textures.

1

There are 1 answers

0
genpfault On
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
glGenTextures(1, tex);
^^^^^^^^^^^^^^^^^^^^^ I hope tex didn't have anything important in it...
glBindTexture (GL_TEXTURE_2D, *tex);
glBegin (GL_QUADS);
....

You're generating an entirely new empty texture every frame. Which also happens to be incomplete.

Generate a texture once and use that.