Jump to content

  • Log In with Google      Sign In   
  • Create Account


OpenGL textures loaded with SDL_Image display with no alpha


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Hinchy   Members   -  Reputation: 100

Like
0Likes
Like

Posted 23 October 2011 - 09:44 PM

I am making a game using OpenGL, with SDL_Image employed to load the textures. When drawn on screen, there's no alpha -- in an exact square around the opaque contents of the texture, black is drawn; outside that space, white is drawn. Here is my OpenGL init code...

    SDL_SetVideoMode(windowWidth, windowHeight, 16, SDL_HWSURFACE|SDL_GL_DOUBLEBUFFER|SDL_OPENGL);
    glClearColor(0, 0, 0, 0);
    glClearDepth(1.0f);
    glViewport(0, 0, windowWidth, windowHeight);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, windowWidth, windowHeight, 0, 1, -1);
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_TEXTURE_2D);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glLoadIdentity();


...here is my image loading function...

    SDL_Surface *loadImage (const char *filename, bool alpha = true) {
        SDL_Surface* loadedImage = NULL;
        SDL_Surface* zoomedImage = NULL;
        SDL_Surface* optimizedImage = NULL;

        loadedImage = IMG_Load(filename);

        if (loadedImage != NULL) {
            zoomedImage = zoomSurface(loadedImage,windowScaleH/4,windowScaleH/4,SMOOTHING_ON);
            SDL_FreeSurface(loadedImage);

            if (alpha) optimizedImage = SDL_DisplayFormatAlpha(zoomedImage);
            else optimizedImage = SDL_DisplayFormat(zoomedImage);
            SDL_FreeSurface(zoomedImage);
        }

        return optimizedImage;
    }


...here is the code I actually use to create the GL texture...

    GLuint thisIsMyTexture;
    glGenTextures(1, &thisIsMyTexture);
    temporarySurface = loadImage("theimagetomytexture.png");
    glBindTexture(GL_TEXTURE_2D,thisIsMyTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, 4, temporarySurface->w, temporarySurface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, temporarySurface->pixels);
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );


...and the drawing code itself.

    glBindTexture(GL_TEXTURE_2D,thisIsMyTexture);
    glBegin( GL_QUADS );
        glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 1.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f(32.0f, 0.0f, 1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f(32.0f, 32.0f, 1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 32.0f, 1.0f);
    glEnd();


That's all the relevant information I can think of. Help would be appreciated! :D

Sponsor:

#2 JTippetts   Moderators   -  Reputation: 7914

Like
1Likes
Like

Posted 23 October 2011 - 10:04 PM

Where is your call to glEnable(GL_BLEND)?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS