I need to see more of the relevant code. The image itself has a correct alpha channel so the problem is not there at least. How do you draw the sprites? Using SDL, or using OpenGL as a texture, or something else? How do you load the images and/or textures?
I'm importing the graphic as an SDL_Surface, then rendering it as an openGL texture. I've got a GLShapes class which has all my drawing code, although it's a quite messy because of all the experimentation I've been doing over the past few days:
#include "Main.h"
using namespace std;
class GLshapes {
public:
void DrawBox(float X,float Y,int width,int height, float angle,string FilePath,float Z){
glDisable(GL_DEPTH_TEST);
glDepthFunc(GL_NEVER); //Remvoes depth sorting
// glEnable (GL_DEPTH_TEST); //Adds depth sorting
// Set the OpenGL state after creating the context with SDL_SetVideoMod
glEnable( GL_TEXTURE_2D ); // Need this to display a texture
////
if(Z == 1){
glEnable(GL_ALPHA_TEST) ;
glAlphaFunc(GL_GREATER, 0.1f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
//////
glLoadIdentity();
// Load the OpenGL texture
GLuint texture; // Texture object handle
SDL_Surface *surface; // Gives us the information to make the texture
if ( (surface = IMG_Load(FilePath.c_str()) )) {
// Check that the image's width is a power of 2
if ( (surface->w & (surface->w - 1)) != 0 ) {
// printf("warning: image.bmp's width is not a power of 2\n");
}
// Also check if the height is a power of 2
if ( (surface->h & (surface->h - 1)) != 0 ) {
//printf("warning: image.bmp's height is not a power of 2\n");
}
//surface = SDL_DisplayFormat(surface);
// Have OpenGL generate a texture object handle for us
SDL_SetAlpha(surface,SDL_SRCALPHA,0);
/*SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );*/
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glGenTextures( 1, &texture );
// Bind the texture object
glBindTexture( GL_TEXTURE_2D, texture );
// Set the texture's stretching properties
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// Edit the texture object's image data using the information SDL_Surface gives us
glTexImage2D( GL_TEXTURE_2D, 0, 3, (surface->w), surface->h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );
}
// Free the SDL_Surface only if it was successfully created
if ( surface ) {
SDL_FreeSurface( surface );
}
// Clear the screen before drawing
// Bind the texture to which subsequent calls refer to
//glBindTexture( GL_TEXTURE_2D, texture );
glColor4f(1,1,1,1);
glTranslatef(X,Y,0);
glRotatef(angle,0,0,1.0);
glScalef(1.0, -1.0, 1.0);
glBegin( GL_QUADS );
// Top-left vertex (corner)
glTexCoord2i( 0.0, 0.0 );
glVertex3f( -width/2, -height/2, 0 );
// Bottom-left vertex (corner)
glTexCoord2i( 1.0, 0.0 );
glVertex3f( -width/2, height/2, 0 );
// Bottom-right vertex (corner)
glTexCoord2i( 1.0, 1.0 );
glVertex3f( width/2, height/2, 0 );
// Top-right vertex (corner)
glTexCoord2i( 0.0, 1.0 );
glVertex3f( width/2, -height/2, 0 );
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDeleteTextures( 1, &texture );
glDisable(GL_ALPHA_TEST);
}
};
Note: if you're wondering, "Z" is just an integer which I was using to toggle the alpha code there for testing.