[SDL] Re: SDL Surfaces and OpenGL
rws_list at girr.org
Sat Jul 16 16:55:46 PDT 2005
If you can set up an SDL_Surface to use 24 bit pixels (ie, no alpha
data), you can change the glTexImage2D Image format argument from
GL_RGBA to GL_RGB.
On Jul 15, 2005, at 2:12 AM, Chris E. wrote:
> Stephen Sweeney wrote:
>> 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
>> 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..?
>> 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;
>> rmask = 0x000000ff;
>> gmask = 0x0000ff00;
>> bmask = 0x00ff0000;
>> amask = 0xff000000;
>> surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
>> 32, rmask,
>> gmask, bmask, amask);
> Because you are passing a mask for alpha, SDL is thinking that you
> want to use it.
> To get rid of the alpha, pass 0 to SDL_CreateRGBSurface in place of
> You can also get rid of the declaration of amask, and the lines
> that assign it a value.
> I'm not sure how OpenGL would handle that - it might still
> interpret the "missing" bits
> as alpha, and use transparency. A safer solution, given that
> possibility, since OpenGL
> might well require the alpha channel to be there, would be to make
> sure that you set
> the alpha value to opaque (255 I think) for every pixel (not just
> the surface alpha
> value), as the transparency might just be because of the bits
> defaulting to 0, which is
> completely transparent.
> Chris E.
> SDL mailing list
> SDL at libsdl.org
More information about the SDL