Hi Kids
Hope you’re all having a lush summer!
Right… um… I’m making SDL Surfaces and turning them in to OpenGL
textures… but all my SDL Surfaces has alpha set on them. So when I’m
drawing on my created surfaces they are always see through… I wish them to
be solid. My code for creating the surface is the usual example stuff (see
all code below).
Any help…?
Steve
SDL_Surface *Graphics::createSurface(int width, int height)
{
SDL_Surface *surface;
Uint32 rmask, gmask, bmask, amask;
/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask,
gmask, bmask, amask);
if (surface == NULL)
{
showErrorAndExit("CreateRGBSurface failed: %s\n", SDL_GetError());
}
SDL_SetAlpha(surface, SDL_SRCALPHA, 255);
return surface;
}
// OpenGL texture generation code (w and h are surface width and height)
SDL_Surface *tmp = createSurface(w, h);
SDL_BlitSurface(surface, NULL, tmp, NULL);
GLuint glTexture;
glGenTextures(1, &glTexture);
glBindTexture(GL_TEXTURE_2D, glTexture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE,
tmp->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);