I have the following code to load in a texture and display it in opengl.
I want all the pixels in the PNG with value 85,85,85 to be transparent (i want to see through these pixels). Using SDL_SetColorKey stops OpenGL colouring the pixels but i cannot get the transparent effect desired : ie glColor3f(0,255,0) does not affect the pixels with values 85,85,85.
Can anybody help me please
Thankyou in advance
----- create the texture
SDL_Surface *sfc = IMG_Load(“image.png”);
SDL_SetColorKey(sfc, SDL_SRCCOLORKEY ,SDL_MapRGB(sfc->format, 85, 85, 85));
SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, 256, 256, 24,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
0x00ff0000, 0x0000ff00, 0x000000ff, 0);
#else
0x000000ff, 0x0000ff00, 0x00ff0000, 0)
#endif
SDL_BlitSurface(sfc, NULL, tmp, NULL);
SDL_FreeSurface(sfc);
glGenTextures(1, &texture);glBindTexture(GL_TEXTURE_2D, texture);
glPixelStorei(GL_UNPACK_ROW_LENGTH, tmp->pitch /tmp->format->BytesPerPixel);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, tmp->w, tmp->h, 0, GL_RGB, GL_UNSIGNED_BYTE, tmp->pixels);
glFlush();
SDL_FreeSurface(tmp);
– and when i draw
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Title_texture);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
glColor4ub(255, 255, 255, 255);
glTexCoord2f(0, 0); glVertex2f(-1, 1);
glTexCoord2f(1, 0); glVertex2f(1, 1);
glTexCoord2f(1, 1); glVertex2f(1, -1);
glTexCoord2f(0, 1); glVertex2f(-1, -1);
glEnd();