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");
}
/******************************************************************************/