32 bpp results in no alpha support (only works with 8, 16 or 24)

Hello all,

For some reason I cannot get alpha support for 32 bpp video modes. If I use 8,
16 or 24 then the alpha value is used.

I’m not sure what has changed other than I am using KDE 4.2 with composite
turned on. I have tried the program below on 3 different machines (MacBook Pro

  • radeonhd, Dell + radeonhd, custom built + nvidia). All machines give the
    same thing: All primitives are drawn opaque.

I’m an not using openGL. I’m simply using SDL to give me a surface and I do
scribble on the surface.

Below is a test program I wrote. When I set the DEFAULT_DEPTH to 32, the three
overlapping rectangles are drawn opaque. If I set it to 8, 16, or 24, I get
transparency.

I have a print statement inside the test program that spits out some of the
video info details. This is what I get on one of my machines:

Desktop Details
Window Manager present: YES

Video Details
Driver: x11
Video Memory: 0 KB
Dimensions: 640 x 480
Pixel Format
bpp: 32
Bpp: 4

Acceleration Details
Hardware surface: NO
Hardware-to-hardware blitting: NO
Hardware-to-hardware colourkey blits: NO
Hardware-to-hardware alpha blits: NO
Software-to-hardware blits: NO
Software-to-hardware colorkey blits: NO
Software-to-hardware alpha blits: NO
Accelerated colour fills: NO

Surface Details
Must Lock: NO
Flags: SDL_SWSURFACE

Anyone know what I am doing wrong? In past I have used 32 bpp and received
full alpha support. My main development computer specs are:

openSUSE 11.1
KDE 4.2 with composite (kwin)
X.Org X Server 1.5.2
SDL 1.2.13-107.1 (openSUSE OSS repo)

Any guidance would be greatly appreciated.

Thank you,

Alvin

-----------8<--------------------
// SDL Alpha Support test program
// Compile (Next 2 lines should be 1 line in the console):
// g++ -g3 -O0 -o sdlalphatest sdlalphatest.cpp $(sdl-config --cflags)
// $(sdl-config --libs) -lSDL_gfx

#include <SDL.h>
#include <SDL_gfxPrimitives.h>

/******************************************************************************/
// locals

static const int DEFAULT_DEPTH = 32; // <-- Alpha only works with 8, 16 or 24

static void alpha_test(SDL_Surface *s);
static void print_surface_details(SDL_Surface *s);

/******************************************************************************/

int main(int argc, char *argv[])
{

if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
	printf("Failed to init SDL video:\nReason: %s\n", SDL_GetError());
	return EXIT_FAILURE;
}

SDL_Surface *s = SDL_SetVideoMode(640, 480, DEFAULT_DEPTH, 
					SDL_HWSURFACE|SDL_DOUBLEBUF);

if(!s)
{
	printf("Failed to create SDL surface: %s", SDL_GetError());
	SDL_Quit();
	return EXIT_FAILURE;
}

print_surface_details(s);

// draw overlapping rectangles
alpha_test(s);

// Wait for events
bool done = false;
SDL_Event evt;

while(!done && SDL_WaitEvent(&evt))
{
	if(evt.type == SDL_QUIT)
	{
		done = true;
		continue;
	}

	if(evt.type != SDL_KEYUP)
		continue;

	SDL_KeyboardEvent &key = evt.key;

	switch(key.keysym.sym)
	{
		case SDLK_ESCAPE:
			done = true;
			break;

		case SDLK_F5:
			//SDL_UpdateRect(s, 0,0,0,0);
			SDL_Flip(s);
			break;

		default:
			;					// do nothing
	}
}

SDL_Quit();

return EXIT_SUCCESS;

}

/******************************************************************************/

static void alpha_test(SDL_Surface *s)
{
SDL_LockSurface(s);

const Uint32 WHITE = SDL_MapRGBA(s->format, 255, 255, 255, 255);

// White background
SDL_FillRect(s, 0, WHITE);

rectangleRGBA(s, 100, 100, 200, 200, 255, 0, 0, 255);
boxRGBA(s, 100, 100, 200, 200, 255, 0, 0, 100);

rectangleRGBA(s, 150, 150, 250, 250, 0, 0, 255, 255);
boxRGBA(s, 150, 150, 250, 250, 0, 0, 255, 100);

rectangleRGBA(s, 125, 125, 175, 300, 0, 255, 0, 255);
boxRGBA(s, 125, 125, 175, 300, 0, 255, 0, 100);

//SDL_UpdateRect(s, 0,0,0,0);
SDL_Flip(s);

SDL_UnlockSurface(s);

}

/******************************************************************************/

static void print_surface_details(SDL_Surface *s)
{
char buf[32];

const SDL_VideoInfo *vinfo = SDL_GetVideoInfo();

printf(

" \n
Desktop Details \n
Window Manager present: %s \n
\n
Video Details \n
Driver: %s \n
Video Memory: %d KB \n
Dimensions: %d x %d \n
Pixel Format \n
bpp: %d \n
Bpp: %d \n
\n
Acceleration Details \n
Hardware surface: %s \n
Hardware-to-hardware blitting: %s \n
Hardware-to-hardware colourkey blits: %s \n
Hardware-to-hardware alpha blits: %s \n
Software-to-hardware blits: %s \n
Software-to-hardware colorkey blits: %s \n
Software-to-hardware alpha blits: %s \n
Accelerated colour fills: %s \n
\n
Surface Details \n
Must Lock: %s \n
",
(vinfo->wm_available ? “YES” : “NO”),
SDL_VideoDriverName(buf, 32),
vinfo->video_mem,
vinfo->current_w, vinfo->current_h,
vinfo->vfmt->BitsPerPixel,
vinfo->vfmt->BytesPerPixel,
(vinfo->hw_available ? “YES” : “NO”),
(vinfo->blit_hw ? “YES” : “NO”),
(vinfo->blit_hw_CC ? “YES” : “NO”),
(vinfo->blit_hw_A ? “YES” : “NO”),
(vinfo->blit_sw ? “YES” : “NO”),
(vinfo->blit_sw_CC ? “YES” : “NO”),
(vinfo->blit_sw_A ? “YES” : “NO”),
(vinfo->blit_fill ? “YES” : “NO”),
(SDL_MUSTLOCK(s) ? “YES” : “NO”)
);

printf("\tFlags:                                ");

if(s->flags & SDL_ANYFORMAT)
	printf("SDL_ANYFORMAT ");

if(s->flags & SDL_ASYNCBLIT)
	printf("SDL_ASYNCBLIT ");

if(s->flags & SDL_DOUBLEBUF)
	printf("SDL_DOUBLEBUF ");

if(s->flags & SDL_HWACCEL)
	printf("SDL_HWACCEL ");

if(s->flags & SDL_HWPALETTE)
	printf("SDL_HWPALETTE ");

if(s->flags & SDL_HWSURFACE)
	printf("SDL_HWSURFACE ");
else
	printf("SDL_SWSURFACE ");

if(s->flags & SDL_FULLSCREEN)
	printf("SDL_FULLSCREEN ");

if(s->flags & SDL_OPENGL)
	printf("SDL_OPENGL ");

if(s->flags & SDL_OPENGLBLIT)
	printf("SDL_OPENGLBLIT ");

if(s->flags & SDL_RESIZABLE)
	printf("SDL_RESIZABLE ");

if(s->flags & SDL_RLEACCEL)
	printf("SDL_RLEACCEL ");

if(s->flags & SDL_SRCALPHA)
	printf("SDL_SRCALPHA ");

if(s->flags & SDL_SRCCOLORKEY)
	printf("SDL_SRCCOLORKEY ");

if(s->flags & SDL_PREALLOC)
	printf("SDL_PREALLOC ");

printf("\n");

}

/******************************************************************************/

Hello all,

I fear my original email may has been lost so I will attempt to restate the
question more concisely.

Anyone know why I can only get Alpha support, RGBA, to work with video modes
with 8, 16 or 24 bpp? It appears that the A in RGBA is being ignored with 32
bpp.

Any guidance/suggestions would be greatly appreciated.

Thanks,

AlvinOn May 19, 2009 09:14:48 am Alvin Beach wrote:

Hello all,

For some reason I cannot get alpha support for 32 bpp video modes. If I use
8, 16 or 24 then the alpha value is used.

I’m not sure what has changed other than I am using KDE 4.2 with composite
turned on. I have tried the program below on 3 different machines (MacBook
Pro + radeonhd, Dell + radeonhd, custom built + nvidia). All machines give
the same thing: All primitives are drawn opaque.

I’m an not using openGL. I’m simply using SDL to give me a surface and I do
scribble on the surface.

Below is a test program I wrote. When I set the DEFAULT_DEPTH to 32, the
three overlapping rectangles are drawn opaque. If I set it to 8, 16, or 24,
I get transparency.

I have a print statement inside the test program that spits out some of the
video info details. This is what I get on one of my machines:

Desktop Details
Window Manager present: YES

Video Details
Driver: x11
Video Memory: 0 KB
Dimensions: 640 x 480
Pixel Format
bpp: 32
Bpp: 4

Acceleration Details
Hardware surface: NO
Hardware-to-hardware blitting: NO
Hardware-to-hardware colourkey blits: NO
Hardware-to-hardware alpha blits: NO
Software-to-hardware blits: NO
Software-to-hardware colorkey blits: NO
Software-to-hardware alpha blits: NO
Accelerated colour fills: NO

Surface Details
Must Lock: NO
Flags: SDL_SWSURFACE

Anyone know what I am doing wrong? In past I have used 32 bpp and received
full alpha support. My main development computer specs are:

openSUSE 11.1
KDE 4.2 with composite (kwin)
X.Org X Server 1.5.2
SDL 1.2.13-107.1 (openSUSE OSS repo)

Any guidance would be greatly appreciated.

Thank you,

Alvin

-----------8<--------------------
// SDL Alpha Support test program
// Compile (Next 2 lines should be 1 line in the console):
// g++ -g3 -O0 -o sdlalphatest sdlalphatest.cpp $(sdl-config --cflags)
// $(sdl-config --libs) -lSDL_gfx

#include <SDL.h>
#include <SDL_gfxPrimitives.h>

/**************************************************************************
****/ // locals

static const int DEFAULT_DEPTH = 32; // <-- Alpha only works with 8, 16 or
24

static void alpha_test(SDL_Surface *s);
static void print_surface_details(SDL_Surface *s);

/**************************************************************************
****/

int main(int argc, char *argv[])
{

if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf(“Failed to init SDL video:\nReason: %s\n”, SDL_GetError());
return EXIT_FAILURE;
}

SDL_Surface *s = SDL_SetVideoMode(640, 480, DEFAULT_DEPTH,
SDL_HWSURFACE|SDL_DOUBLEBUF);

if(!s)
{
printf(“Failed to create SDL surface: %s”, SDL_GetError());
SDL_Quit();
return EXIT_FAILURE;
}

print_surface_details(s);

// draw overlapping rectangles
alpha_test(s);

// Wait for events
bool done = false;
SDL_Event evt;

while(!done && SDL_WaitEvent(&evt))
{
if(evt.type == SDL_QUIT)
{
done = true;
continue;
}

  if(evt.type != SDL_KEYUP)
  	continue;

  SDL_KeyboardEvent &key = evt.key;

  switch(key.keysym.sym)
  {
  	case SDLK_ESCAPE:
  		done = true;
  		break;

  	case SDLK_F5:
  		//SDL_UpdateRect(s, 0,0,0,0);
  		SDL_Flip(s);
  		break;

  	default:
  		;					// do nothing
  }

}

SDL_Quit();

return EXIT_SUCCESS;
}

/**************************************************************************
****/

static void alpha_test(SDL_Surface *s)
{
SDL_LockSurface(s);

const Uint32 WHITE = SDL_MapRGBA(s->format, 255, 255, 255, 255);

// White background
SDL_FillRect(s, 0, WHITE);

rectangleRGBA(s, 100, 100, 200, 200, 255, 0, 0, 255);
boxRGBA(s, 100, 100, 200, 200, 255, 0, 0, 100);

rectangleRGBA(s, 150, 150, 250, 250, 0, 0, 255, 255);
boxRGBA(s, 150, 150, 250, 250, 0, 0, 255, 100);

rectangleRGBA(s, 125, 125, 175, 300, 0, 255, 0, 255);
boxRGBA(s, 125, 125, 175, 300, 0, 255, 0, 100);

//SDL_UpdateRect(s, 0,0,0,0);
SDL_Flip(s);

SDL_UnlockSurface(s);
}

/**************************************************************************
****/

static void print_surface_details(SDL_Surface *s)
{
char buf[32];

const SDL_VideoInfo *vinfo = SDL_GetVideoInfo();

printf(
" \n
Desktop Details \n
Window Manager present: %s \n
\n
Video Details \n
Driver: %s \n
Video Memory: %d KB \n
Dimensions: %d x %d \n
Pixel Format \n
bpp: %d \n
Bpp: %d \n
\n
Acceleration Details \n
Hardware surface: %s \n
Hardware-to-hardware blitting: %s \n
Hardware-to-hardware colourkey blits: %s \n
Hardware-to-hardware alpha blits: %s \n
Software-to-hardware blits: %s \n
Software-to-hardware colorkey blits: %s \n
Software-to-hardware alpha blits: %s \n
Accelerated colour fills: %s \n
\n
Surface Details \n
Must Lock: %s \n
",
(vinfo->wm_available ? “YES” : “NO”),
SDL_VideoDriverName(buf, 32),
vinfo->video_mem,
vinfo->current_w, vinfo->current_h,
vinfo->vfmt->BitsPerPixel,
vinfo->vfmt->BytesPerPixel,
(vinfo->hw_available ? “YES” : “NO”),
(vinfo->blit_hw ? “YES” : “NO”),
(vinfo->blit_hw_CC ? “YES” : “NO”),
(vinfo->blit_hw_A ? “YES” : “NO”),
(vinfo->blit_sw ? “YES” : “NO”),
(vinfo->blit_sw_CC ? “YES” : “NO”),
(vinfo->blit_sw_A ? “YES” : “NO”),
(vinfo->blit_fill ? “YES” : “NO”),
(SDL_MUSTLOCK(s) ? “YES” : “NO”)
);

printf("\tFlags: ");

if(s->flags & SDL_ANYFORMAT)
printf("SDL_ANYFORMAT ");

if(s->flags & SDL_ASYNCBLIT)
printf("SDL_ASYNCBLIT ");

if(s->flags & SDL_DOUBLEBUF)
printf("SDL_DOUBLEBUF ");

if(s->flags & SDL_HWACCEL)
printf("SDL_HWACCEL ");

if(s->flags & SDL_HWPALETTE)
printf("SDL_HWPALETTE ");

if(s->flags & SDL_HWSURFACE)
printf("SDL_HWSURFACE ");
else
printf("SDL_SWSURFACE ");

if(s->flags & SDL_FULLSCREEN)
printf("SDL_FULLSCREEN ");

if(s->flags & SDL_OPENGL)
printf("SDL_OPENGL ");

if(s->flags & SDL_OPENGLBLIT)
printf("SDL_OPENGLBLIT ");

if(s->flags & SDL_RESIZABLE)
printf("SDL_RESIZABLE ");

if(s->flags & SDL_RLEACCEL)
printf("SDL_RLEACCEL ");

if(s->flags & SDL_SRCALPHA)
printf("SDL_SRCALPHA ");

if(s->flags & SDL_SRCCOLORKEY)
printf("SDL_SRCCOLORKEY ");

if(s->flags & SDL_PREALLOC)
printf("SDL_PREALLOC ");

printf("\n");
}

/**************************************************************************
****/

I think there are bugs in software blits . I will give patch next week .
But I am not sure whether it is the couse of your problem.

the bug , in abstraction, is , when we Blit a source Surface with Apha 1 to
a Destination Surface with Alpha 2 , what is the result’s Alpha ? the
Implemetion choose Alpha 2 in some cases or zero in some other cases . In
theory it must be Alpha1 + Alpha2 - Alpha1* Alpha2, for speed reason, I use
the larger one of Alpha 1 and Alpha 2.

2009/5/22 Alvin Beach > Hello all,

I fear my original email may has been lost so I will attempt to restate the
question more concisely.

Anyone know why I can only get Alpha support, RGBA, to work with video
modes
with 8, 16 or 24 bpp? It appears that the A in RGBA is being ignored with
32
bpp.

Any guidance/suggestions would be greatly appreciated.

Thanks,

Alvin

On May 19, 2009 09:14:48 am Alvin Beach wrote:

Hello all,

For some reason I cannot get alpha support for 32 bpp video modes. If I
use
8, 16 or 24 then the alpha value is used.

I’m not sure what has changed other than I am using KDE 4.2 with
composite
turned on. I have tried the program below on 3 different machines
(MacBook
Pro + radeonhd, Dell + radeonhd, custom built + nvidia). All machines
give
the same thing: All primitives are drawn opaque.

I’m an not using openGL. I’m simply using SDL to give me a surface and I
do
scribble on the surface.

Below is a test program I wrote. When I set the DEFAULT_DEPTH to 32, the
three overlapping rectangles are drawn opaque. If I set it to 8, 16, or
24,
I get transparency.

I have a print statement inside the test program that spits out some of
the
video info details. This is what I get on one of my machines:

Desktop Details
Window Manager present: YES

Video Details
Driver: x11
Video Memory: 0 KB
Dimensions: 640 x 480
Pixel Format
bpp: 32
Bpp: 4

Acceleration Details
Hardware surface: NO
Hardware-to-hardware blitting: NO
Hardware-to-hardware colourkey blits: NO
Hardware-to-hardware alpha blits: NO
Software-to-hardware blits: NO
Software-to-hardware colorkey blits: NO
Software-to-hardware alpha blits: NO
Accelerated colour fills: NO

Surface Details
Must Lock: NO
Flags: SDL_SWSURFACE

Anyone know what I am doing wrong? In past I have used 32 bpp and
received
full alpha support. My main development computer specs are:

openSUSE 11.1
KDE 4.2 with composite (kwin)
X.Org X Server 1.5.2
SDL 1.2.13-107.1 (openSUSE OSS repo)

Any guidance would be greatly appreciated.

Thank you,

Alvin

-----------8<--------------------
// SDL Alpha Support test program
// Compile (Next 2 lines should be 1 line in the console):
// g++ -g3 -O0 -o sdlalphatest sdlalphatest.cpp $(sdl-config --cflags)
// $(sdl-config --libs) -lSDL_gfx

#include <SDL.h>
#include <SDL_gfxPrimitives.h>

/**************************************************************************

****/ // locals

static const int DEFAULT_DEPTH = 32; // <-- Alpha only works with 8, 16
or
24

static void alpha_test(SDL_Surface *s);
static void print_surface_details(SDL_Surface *s);

/**************************************************************************

****/

int main(int argc, char *argv[])
{

  if(SDL_Init(SDL_INIT_VIDEO) != 0)
  {
          printf("Failed to init SDL video:\nReason: %s\n",

SDL_GetError());

          return EXIT_FAILURE;
  }

  SDL_Surface *s = SDL_SetVideoMode(640, 480, DEFAULT_DEPTH,

SDL_HWSURFACE|SDL_DOUBLEBUF);

  if(!s)
  {
          printf("Failed to create SDL surface: %s", SDL_GetError());
          SDL_Quit();
          return EXIT_FAILURE;
  }

  print_surface_details(s);

  // draw overlapping rectangles
  alpha_test(s);

  // Wait for events
  bool done = false;
  SDL_Event evt;

  while(!done && SDL_WaitEvent(&evt))
  {
          if(evt.type == SDL_QUIT)
          {
                  done = true;
                  continue;
          }

          if(evt.type != SDL_KEYUP)
                  continue;

          SDL_KeyboardEvent &key = evt.key;

          switch(key.keysym.sym)
          {
                  case SDLK_ESCAPE:
                          done = true;
                          break;

                  case SDLK_F5:
                          //SDL_UpdateRect(s, 0,0,0,0);
                          SDL_Flip(s);
                          break;

                  default:
                          ;                                       //

do nothing

          }
  }

  SDL_Quit();

  return EXIT_SUCCESS;

}

/**************************************************************************

****/

static void alpha_test(SDL_Surface *s)
{
SDL_LockSurface(s);

  const Uint32 WHITE = SDL_MapRGBA(s->format, 255, 255, 255, 255);

  // White background
  SDL_FillRect(s, 0, WHITE);

  rectangleRGBA(s, 100, 100, 200, 200, 255, 0, 0, 255);
  boxRGBA(s, 100, 100, 200, 200, 255, 0, 0, 100);

  rectangleRGBA(s, 150, 150, 250, 250, 0, 0, 255, 255);
  boxRGBA(s, 150, 150, 250, 250, 0, 0, 255, 100);

  rectangleRGBA(s, 125, 125, 175, 300, 0, 255, 0, 255);
  boxRGBA(s, 125, 125, 175, 300, 0, 255, 0, 100);

  //SDL_UpdateRect(s, 0,0,0,0);
  SDL_Flip(s);

  SDL_UnlockSurface(s);

}

/**************************************************************************

****/

static void print_surface_details(SDL_Surface *s)
{
char buf[32];

  const SDL_VideoInfo *vinfo = SDL_GetVideoInfo();

  printf(

" \n
Desktop Details \n
Window Manager present: %s \n
\n
Video Details \n
Driver: %s \n
Video Memory: %d KB \n
Dimensions: %d x %d \n
Pixel Format \n
bpp: %d \n
Bpp: %d \n
\n
Acceleration Details \n
Hardware surface: %s \n
Hardware-to-hardware blitting: %s \n
Hardware-to-hardware colourkey blits: %s \n
Hardware-to-hardware alpha blits: %s \n
Software-to-hardware blits: %s \n
Software-to-hardware colorkey blits: %s \n
Software-to-hardware alpha blits: %s \n
Accelerated colour fills: %s \n
\n
Surface Details \n
Must Lock: %s \n
",
(vinfo->wm_available ? “YES” : “NO”),
SDL_VideoDriverName(buf, 32),
vinfo->video_mem,
vinfo->current_w, vinfo->current_h,
vinfo->vfmt->BitsPerPixel,
vinfo->vfmt->BytesPerPixel,
(vinfo->hw_available ? “YES” : “NO”),
(vinfo->blit_hw ? “YES” : “NO”),
(vinfo->blit_hw_CC ? “YES” : “NO”),
(vinfo->blit_hw_A ? “YES” : “NO”),
(vinfo->blit_sw ? “YES” : “NO”),
(vinfo->blit_sw_CC ? “YES” : “NO”),
(vinfo->blit_sw_A ? “YES” : “NO”),
(vinfo->blit_fill ? “YES” : “NO”),
(SDL_MUSTLOCK(s) ? “YES” : “NO”)
);

  printf("\tFlags:                                ");

  if(s->flags & SDL_ANYFORMAT)
          printf("SDL_ANYFORMAT ");

  if(s->flags & SDL_ASYNCBLIT)
          printf("SDL_ASYNCBLIT ");

  if(s->flags & SDL_DOUBLEBUF)
          printf("SDL_DOUBLEBUF ");

  if(s->flags & SDL_HWACCEL)
          printf("SDL_HWACCEL ");

  if(s->flags & SDL_HWPALETTE)
          printf("SDL_HWPALETTE ");

  if(s->flags & SDL_HWSURFACE)
          printf("SDL_HWSURFACE ");
  else
          printf("SDL_SWSURFACE ");

  if(s->flags & SDL_FULLSCREEN)
          printf("SDL_FULLSCREEN ");

  if(s->flags & SDL_OPENGL)
          printf("SDL_OPENGL ");

  if(s->flags & SDL_OPENGLBLIT)
          printf("SDL_OPENGLBLIT ");

  if(s->flags & SDL_RESIZABLE)
          printf("SDL_RESIZABLE ");

  if(s->flags & SDL_RLEACCEL)
          printf("SDL_RLEACCEL ");

  if(s->flags & SDL_SRCALPHA)
          printf("SDL_SRCALPHA ");

  if(s->flags & SDL_SRCCOLORKEY)
          printf("SDL_SRCCOLORKEY ");

  if(s->flags & SDL_PREALLOC)
          printf("SDL_PREALLOC ");

  printf("\n");

}

/**************************************************************************

****/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

This is not a bug… It was a design decision. Different
alpha-blending modes should be available in SDL 1.3.

Jonny DOn Fri, May 22, 2009 at 11:10 AM, ??? <zengbo.zhang at gmail.com> wrote:

I think there are bugs in software blits . I will give patch next week .
But I am not sure whether it is the couse of your problem.

the bug , in abstraction, is , when we Blit a source Surface with Apha 1 to
a Destination Surface with Alpha 2 , what is the result’s Alpha ? the
Implemetion choose Alpha 2 in some cases or zero in some other cases . In
theory it must be Alpha1 + Alpha2 - Alpha1* Alpha2, for speed reason, I use
the larger one of Alpha 1 and Alpha 2.

2009/5/22 Alvin Beach

Hello all,

I fear my original email may has been lost so I will attempt to restate
the
question more concisely.

Anyone know why I can only get Alpha support, RGBA, to work with video
modes
with 8, 16 or 24 bpp? It appears that the A in RGBA is being ignored with
32
bpp.

Any guidance/suggestions would be greatly appreciated.

Thanks,

Alvin

On May 19, 2009 09:14:48 am Alvin Beach wrote:

Hello all,

For some reason I cannot get alpha support for 32 bpp video modes. If I
use
8, 16 or 24 then the alpha value is used.

I’m not sure what has changed other than I am using KDE 4.2 with
composite
turned on. I have tried the program below on 3 different machines
(MacBook
Pro + radeonhd, Dell + radeonhd, custom built + nvidia). All machines
give
the same thing: All primitives are drawn opaque.

I’m an not using openGL. I’m simply using SDL to give me a surface and I
do
scribble on the surface.

Below is a test program I wrote. When I set the DEFAULT_DEPTH to 32, the
three overlapping rectangles are drawn opaque. If I set it to 8, 16, or
24,
I get transparency.

I have a print statement inside the test program that spits out some of
the
video info details. This is what I get on one of my machines:

Desktop Details
Window Manager present: YES

Video Details
Driver: x11
Video Memory: 0 KB
Dimensions: 640 x 480
Pixel Format
bpp: 32
Bpp: 4

Acceleration Details
Hardware surface: NO
Hardware-to-hardware blitting: NO
Hardware-to-hardware colourkey blits: NO
Hardware-to-hardware alpha blits: NO
Software-to-hardware blits: NO
Software-to-hardware colorkey blits: NO
Software-to-hardware alpha blits: NO
Accelerated colour fills: NO

Surface Details
Must Lock: NO
Flags: SDL_SWSURFACE

Anyone know what I am doing wrong? In past I have used 32 bpp and
received
full alpha support. My main development computer specs are:

openSUSE 11.1
KDE 4.2 with composite (kwin)
X.Org X Server 1.5.2
SDL 1.2.13-107.1 (openSUSE OSS repo)

Any guidance would be greatly appreciated.

Thank you,

Alvin

-----------8<--------------------
// SDL Alpha Support test program
// Compile (Next 2 lines should be 1 line in the console):
// g++ -g3 -O0 -o sdlalphatest sdlalphatest.cpp $(sdl-config --cflags)
// $(sdl-config --libs) -lSDL_gfx

#include <SDL.h>
#include <SDL_gfxPrimitives.h>

/**************************************************************************
****/ // locals

static const int DEFAULT_DEPTH = 32; // <-- Alpha only works with 8, 16
or
24

static void alpha_test(SDL_Surface *s);
static void print_surface_details(SDL_Surface *s);

/**************************************************************************
****/

int main(int argc, char *argv[])
{

  if(SDL_Init(SDL_INIT_VIDEO) != 0)
  {
          printf("Failed to init SDL video:\nReason: %s\n",

SDL_GetError());
return EXIT_FAILURE;
}

  SDL_Surface *s = SDL_SetVideoMode(640, 480, DEFAULT_DEPTH,

SDL_HWSURFACE|SDL_DOUBLEBUF);

  if(!s)
  {
          printf("Failed to create SDL surface: %s",

SDL_GetError());
SDL_Quit();
return EXIT_FAILURE;
}

  print_surface_details(s);

  // draw overlapping rectangles
  alpha_test(s);

  // Wait for events
  bool done = false;
  SDL_Event evt;

  while(!done && SDL_WaitEvent(&evt))
  {
          if(evt.type == SDL_QUIT)
          {
                  done = true;
                  continue;
          }

          if(evt.type != SDL_KEYUP)
                  continue;

          SDL_KeyboardEvent &key = evt.key;

          switch(key.keysym.sym)
          {
                  case SDLK_ESCAPE:
                          done = true;
                          break;

                  case SDLK_F5:
                          //SDL_UpdateRect(s, 0,0,0,0);
                          SDL_Flip(s);
                          break;

                  default:
                          ;                                       //

do nothing
}
}

  SDL_Quit();

  return EXIT_SUCCESS;

}

/**************************************************************************
****/

static void alpha_test(SDL_Surface *s)
{
SDL_LockSurface(s);

  const Uint32 WHITE = SDL_MapRGBA(s->format, 255, 255, 255, 255);

  // White background
  SDL_FillRect(s, 0, WHITE);

  rectangleRGBA(s, 100, 100, 200, 200, 255, 0, 0, 255);
  boxRGBA(s, 100, 100, 200, 200, 255, 0, 0, 100);

  rectangleRGBA(s, 150, 150, 250, 250, 0, 0, 255, 255);
  boxRGBA(s, 150, 150, 250, 250, 0, 0, 255, 100);

  rectangleRGBA(s, 125, 125, 175, 300, 0, 255, 0, 255);
  boxRGBA(s, 125, 125, 175, 300, 0, 255, 0, 100);

  //SDL_UpdateRect(s, 0,0,0,0);
  SDL_Flip(s);

  SDL_UnlockSurface(s);

}

/**************************************************************************
****/

static void print_surface_details(SDL_Surface *s)
{
char buf[32];

  const SDL_VideoInfo *vinfo = SDL_GetVideoInfo();

  printf(

" \n
Desktop Details \n
Window Manager present: %s \n
\n
Video Details \n
Driver: %s \n
Video Memory: %d KB \n
Dimensions: %d x %d \n
Pixel Format \n
bpp: %d \n
Bpp: %d \n
\n
Acceleration Details \n
Hardware surface: %s \n
Hardware-to-hardware blitting: %s \n
Hardware-to-hardware colourkey blits: %s \n
Hardware-to-hardware alpha blits: %s \n
Software-to-hardware blits: %s \n
Software-to-hardware colorkey blits: %s \n
Software-to-hardware alpha blits: %s \n
Accelerated colour fills: %s \n
\n
Surface Details \n
Must Lock: %s \n
",
(vinfo->wm_available ? “YES” : “NO”),
SDL_VideoDriverName(buf, 32),
vinfo->video_mem,
vinfo->current_w, vinfo->current_h,
vinfo->vfmt->BitsPerPixel,
vinfo->vfmt->BytesPerPixel,
(vinfo->hw_available ? “YES” : “NO”),
(vinfo->blit_hw ? “YES” : “NO”),
(vinfo->blit_hw_CC ? “YES” : “NO”),
(vinfo->blit_hw_A ? “YES” : “NO”),
(vinfo->blit_sw ? “YES” : “NO”),
(vinfo->blit_sw_CC ? “YES” : “NO”),
(vinfo->blit_sw_A ? “YES” : “NO”),
(vinfo->blit_fill ? “YES” : “NO”),
(SDL_MUSTLOCK(s) ? “YES” : “NO”)
);

  printf("\tFlags:                                ");

  if(s->flags & SDL_ANYFORMAT)
          printf("SDL_ANYFORMAT ");

  if(s->flags & SDL_ASYNCBLIT)
          printf("SDL_ASYNCBLIT ");

  if(s->flags & SDL_DOUBLEBUF)
          printf("SDL_DOUBLEBUF ");

  if(s->flags & SDL_HWACCEL)
          printf("SDL_HWACCEL ");

  if(s->flags & SDL_HWPALETTE)
          printf("SDL_HWPALETTE ");

  if(s->flags & SDL_HWSURFACE)
          printf("SDL_HWSURFACE ");
  else
          printf("SDL_SWSURFACE ");

  if(s->flags & SDL_FULLSCREEN)
          printf("SDL_FULLSCREEN ");

  if(s->flags & SDL_OPENGL)
          printf("SDL_OPENGL ");

  if(s->flags & SDL_OPENGLBLIT)
          printf("SDL_OPENGLBLIT ");

  if(s->flags & SDL_RESIZABLE)
          printf("SDL_RESIZABLE ");

  if(s->flags & SDL_RLEACCEL)
          printf("SDL_RLEACCEL ");

  if(s->flags & SDL_SRCALPHA)
          printf("SDL_SRCALPHA ");

  if(s->flags & SDL_SRCCOLORKEY)
          printf("SDL_SRCCOLORKEY ");

  if(s->flags & SDL_PREALLOC)
          printf("SDL_PREALLOC ");

  printf("\n");

}

/**************************************************************************
****/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

So, if I understand correctly, the issue has nothing to do with my systems?
This is a bug in SDL? What can I do to get 32 bpp display surfaces back?
Everything that I am finding about 24 bpp vs. 32 bpp says that 32 bpp is
faster than 24 bpp. Is this true?

The SDL-based programs that I develop are in-house apps and, as such, the
hardware is known. I don’t need to worry about supporting a wide range of
hardware so I typically just hardcode the depth to 32. However, now to get
alpha blending (transparencies) I need to use a depth of 24. This is for the
same machines where 32 bpp was fine. I recently upgraded the machines to
openSUSE 11.1, could that be the problem (not openSUSE directly, but updated
Xorg, etc.)?

Many thanks,

AlvinOn May 22, 2009 12:10:57 pm ??? wrote:

I think there are bugs in software blits . I will give patch next week .
But I am not sure whether it is the couse of your problem.

the bug , in abstraction, is , when we Blit a source Surface with Apha 1 to
a Destination Surface with Alpha 2 , what is the result’s Alpha ? the
Implemetion choose Alpha 2 in some cases or zero in some other cases . In
theory it must be Alpha1 + Alpha2 - Alpha1* Alpha2, for speed reason, I use
the larger one of Alpha 1 and Alpha 2.

Ok. So the A channel in RGBA is ignored in 32 bpp depths?

I used to manually alter the pixels, so 32 bpp was just easier to do that.
However, I now use SDL_Image, SDL_gfx and SDE to do scribble on the surface
now.

I do not fully understanding, why, when I use SDL_gfx to draw a filled
rectangle that has an alpha of < 255, that it is not being blended with the
current contents of the SDL_Surface?

If you run the test program I attached[1], do you see 3 overlapping and
blended rectangles or do you see 3 overlapping and opaque rectangles.

Also, I am surprised that my Google searching has not turned up any relevant
results concerning the lack of alpha blending with 32 bpp video depths.

Cheers,

Alvin

[1] Program attached to the bottom of this message:
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2009-May/070468.htmlOn May 22, 2009 02:44:44 pm Jonathan Dearborn wrote:

This is not a bug… It was a design decision. Different
alpha-blending modes should be available in SDL 1.3.

Jonny D

Sorry, that reply was meant towards Zengbo. The bug he describes is
not what you’re experiencing.

I don’t think the attachment made it through. Send it to me offlist?

Jonny DOn Tue, May 26, 2009 at 7:24 AM, Alvin Beach wrote:

On May 22, 2009 02:44:44 pm Jonathan Dearborn wrote:

This is not a bug… ?It was a design decision. ?Different
alpha-blending modes should be available in SDL 1.3.

Jonny D

Ok. So the A channel in RGBA is ignored in 32 bpp depths?

I used to manually alter the pixels, so 32 bpp was just easier to do that.
However, I now use SDL_Image, SDL_gfx and SDE to do scribble on the surface
now.

I do not fully understanding, why, when I use SDL_gfx to draw a filled
rectangle that has an alpha of < 255, that it is not being blended with the
current contents of the SDL_Surface?

If you run the test program I attached[1], do you see 3 overlapping and
blended rectangles or do you see 3 overlapping and opaque rectangles.

Also, I am surprised that my Google searching has not turned up any relevant
results concerning the lack of alpha blending with 32 bpp video depths.

Cheers,

Alvin

[1] Program attached to the bottom of this message:
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2009-May/070468.html


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I do not fully understanding, why, when I use SDL_gfx to draw a filled
rectangle that has an alpha of < 255, that it is not being blended with the
current contents of the SDL_Surface?

That would be a problem with SDL_gfx, not SDL itself. If you create an
empty surface (that has all of its pixels fully transparent), draw a
filled rectangle with an alpha of < 255 (and hopefully > 0!), then
blit that surface unto your other surface, it should be blended
correctly. It’s possible that SDL_gfx sets the alpha component of the
pixels it puts down, without doing any blending?On Tue, May 26, 2009 at 7:24 AM, Alvin Beach wrote:


http://pphaneuf.livejournal.com/

I believe my problem stems from the SDL_gfx (-devel) RPMs. I have tried the
RPMs supplied by openSUSE in their OSS repo for 11.1 and the RPMs from the
games repo for openSUSE 11.1. Both are 2.0.17 and differ by the numbers after
the main version numbers.

I downloaded, compiled and installed the SDL_gfx 2.0.19 tarball from the
SDL_gfx website and now my test program works as expected with 32 bpp.

Now, the problem is with either SDL_gfx 2.0.17 or the way the RPMs are compile
and created.

Regardless, I’m happy now that I can get my 32 bpp back again even though this
means I need to install SDL_gfx from tarball. I guess I could use just roll my
own RPM for 2.0.19.

Many thanks to all for help!

Cheers,

AlvinOn May 26, 2009 10:32:01 am Pierre Phaneuf wrote:

On Tue, May 26, 2009 at 7:24 AM, Alvin Beach <@Alvin_Beach> wrote:

I do not fully understanding, why, when I use SDL_gfx to draw a filled
rectangle that has an alpha of < 255, that it is not being blended with
the current contents of the SDL_Surface?

That would be a problem with SDL_gfx, not SDL itself. If you create an
empty surface (that has all of its pixels fully transparent), draw a
filled rectangle with an alpha of < 255 (and hopefully > 0!), then
blit that surface unto your other surface, it should be blended
correctly. It’s possible that SDL_gfx sets the alpha component of the
pixels it puts down, without doing any blending?

I’m glad that it works now. I tried it and it works for me with 32
bits. It seems that I’m using SDL_gfx 2.0.13 though (and I’m on
Debian).

Jonny DOn Tue, May 26, 2009 at 9:59 AM, Alvin Beach wrote:

I believe my problem stems from the SDL_gfx (-devel) RPMs. I have tried the
RPMs supplied by openSUSE in their OSS repo for 11.1 and the RPMs from the
games repo for openSUSE 11.1. Both are 2.0.17 and differ by the numbers after
the main version numbers.

I downloaded, compiled and installed the SDL_gfx 2.0.19 tarball from the
SDL_gfx website and now my test program works as expected with 32 bpp.

Now, the problem is with either SDL_gfx 2.0.17 or the way the RPMs are compile
and created.

Regardless, I’m happy now that I can get my 32 bpp back again even though this
means I need to install SDL_gfx from tarball. I guess I could use just roll my
own RPM for 2.0.19.

Many thanks to all for help!

Cheers,

Alvin


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yes, in SDL 1.2, the 32-bit depth is RGBX, not RGBA. In SDL 1.3 there’s
initial support for choosing RGBA visuals, but it’s not completely
implemented yet.

See ya,
–SamOn Tue, May 26, 2009 at 4:24 AM, Alvin Beach wrote:

On May 22, 2009 02:44:44 pm Jonathan Dearborn wrote:

This is not a bug… It was a design decision. Different
alpha-blending modes should be available in SDL 1.3.

Jonny D

Ok. So the A channel in RGBA is ignored in 32 bpp depths?

I used to manually alter the pixels, so 32 bpp was just easier to do that.
However, I now use SDL_Image, SDL_gfx and SDE to do scribble on the surface
now.

I do not fully understanding, why, when I use SDL_gfx to draw a filled
rectangle that has an alpha of < 255, that it is not being blended with the
current contents of the SDL_Surface?

If you run the test program I attached[1], do you see 3 overlapping and
blended rectangles or do you see 3 overlapping and opaque rectangles.

Also, I am surprised that my Google searching has not turned up any
relevant
results concerning the lack of alpha blending with 32 bpp video depths.

Cheers,

Alvin

[1] Program attached to the bottom of this message:
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2009-May/070468.html


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Just to clarify, I’m talking about final output into composite visuals, not
blending into an opaque window.

See ya,
–SamOn Tue, May 26, 2009 at 7:45 AM, Sam Lantinga <@slouken> wrote:

Yes, in SDL 1.2, the 32-bit depth is RGBX, not RGBA. In SDL 1.3 there’s
initial support for choosing RGBA visuals, but it’s not completely
implemented yet.

See ya,
–Sam

On Tue, May 26, 2009 at 4:24 AM, Alvin Beach wrote:

On May 22, 2009 02:44:44 pm Jonathan Dearborn wrote:

This is not a bug… It was a design decision. Different
alpha-blending modes should be available in SDL 1.3.

Jonny D

Ok. So the A channel in RGBA is ignored in 32 bpp depths?

I used to manually alter the pixels, so 32 bpp was just easier to do that.
However, I now use SDL_Image, SDL_gfx and SDE to do scribble on the
surface
now.

I do not fully understanding, why, when I use SDL_gfx to draw a filled
rectangle that has an alpha of < 255, that it is not being blended with
the
current contents of the SDL_Surface?

If you run the test program I attached[1], do you see 3 overlapping and
blended rectangles or do you see 3 overlapping and opaque rectangles.

Also, I am surprised that my Google searching has not turned up any
relevant
results concerning the lack of alpha blending with 32 bpp video depths.

Cheers,

Alvin

[1] Program attached to the bottom of this message:
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2009-May/070468.html


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

That would be very cool.

Jonny DOn Tue, May 26, 2009 at 10:46 AM, Sam Lantinga wrote:

Just to clarify, I’m talking about final output into composite visuals, not
blending into an opaque window.

See ya,
–Sam

On Tue, May 26, 2009 at 7:45 AM, Sam Lantinga wrote:

Yes, in SDL 1.2, the 32-bit depth is RGBX, not RGBA.? In SDL 1.3 there’s
initial support for choosing RGBA visuals, but it’s not completely
implemented yet.

See ya,
–Sam

On Tue, May 26, 2009 at 4:24 AM, Alvin Beach wrote:

On May 22, 2009 02:44:44 pm Jonathan Dearborn wrote:

This is not a bug… ?It was a design decision. ?Different
alpha-blending modes should be available in SDL 1.3.

Jonny D

Ok. So the A channel in RGBA is ignored in 32 bpp depths?

I used to manually alter the pixels, so 32 bpp was just easier to do
that.
However, I now use SDL_Image, SDL_gfx and SDE to do scribble on the
surface
now.

I do not fully understanding, why, when I use SDL_gfx to draw a filled
rectangle that has an alpha of < 255, that it is not being blended with
the
current contents of the SDL_Surface?

If you run the test program I attached[1], do you see 3 overlapping and
blended rectangles or do you see 3 overlapping and opaque rectangles.

Also, I am surprised that my Google searching has not turned up any
relevant
results concerning the lack of alpha blending with 32 bpp video depths.

Cheers,

Alvin

[1] Program attached to the bottom of this message:
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2009-May/070468.html


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org