On Mon, Feb 16, 2009 at 11:39 AM, Kai Sterker <kai.ster...@gmail.com> wrote:
> On Mon, Feb 16, 2009 at 10:29 AM, Kai Sterker <kai.ster...@gmail.com> wrote:
>
>> I might have to add some debug info about the properties of the screen
>> surface we actually get on OSX and compare that with Linux/Win32.
>
> Here's what I get on Windows:

And that on OSX

Video information:
Video driver used:                   Quartz
Internal game depth:                 32
Can create hardware surfaces:        No
Window manager available:            Yes
Hardware blits accelerated:          No
Colorkey hardware blits accelerated: No
Alpha hardware blits accelerated:    No
Software blits accelerated:          No
Colorkey software blits accelerated: No
Alpha software blits accelerated:    No
Color fill blits accelerated:        No
Total video memory available:        0 Kb
Fullscreen:                          No
Alpha value:                         255

Actually, it occurred to me that I can do export SDL_VIDEODRIVER=X11
on the Mac too. And guess what. Runs without problems, just like on
Linux. Output is pretty much the same:

Tenebrae:~/adonthell/adonthell-build/test kai$ export SDL_VIDEODRIVER=X11
Tenebrae:~/adonthell/adonthell-build/test kai$ export DISPLAY=:0.0
Tenebrae:~/adonthell/adonthell-build/test kai$ .libs/guitest -g
../../adonthell/test/
Video information:
Video driver used:                   x11
Internal game depth:                 32
Can create hardware surfaces:        No
Window manager available:            Yes
Hardware blits accelerated:          No
Colorkey hardware blits accelerated: No
Alpha hardware blits accelerated:    No
Software blits accelerated:          No
Colorkey software blits accelerated: No
Alpha software blits accelerated:    No
Color fill blits accelerated:        No
Total video memory available:        0 Kb
Fullscreen:                          No
Alpha value:                         255

Then I went and wrote a little test that loads a PNG with alpha
channel (using SDL_Image) and draw that on a white screen surface.
Works like a charm too. See the attached file for the test code.
Compiles with

gcc -o graywin graywin.c -g -O2 -I/usr/local/include/SDL
-D_GNU_SOURCE=1 -D_THREAD_SAFE -I/usr/X11R6/include -DHAVE_OPENGL
-L/usr/local/lib -lSDLmain -lSDL -lSDL_image -Wl,-framework,Cocoa

Since I couldn't figure out any more, I've posted something to the SDL
mailing list too, in the hope that maybe folks there can shed some
light on this. Having a small working test case would be beneficial,
however.

Kai
/* Simple program:  Fill a colormap with gray and stripe it down the screen */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "SDL.h"
#include "SDL_image.h"

#define R_MASK 0x000000ff
#define G_MASK 0x0000ff00
#define B_MASK 0x00ff0000
#define A_MASK 0xff000000
#define BYTES_PER_PIXEL 32

void put_pix (int x, int y, Uint32 col, SDL_Surface *vis) 
{
    Uint8 * offset = ((Uint8 *) vis->pixels) + y * vis->pitch
    + x*vis->format->BytesPerPixel;
    
    switch (vis->format->BytesPerPixel) 
    {
        case 1:
            *((Uint8 *) (offset)) = (Uint8) col;
            break;
        case 2:
            *((Uint16 *) (offset)) = (Uint16) col;
            break;
        case 3:
        {
            Uint8 r, g, b;
            
            r = (col >> vis->format->Rshift);
            g = (col >> vis->format->Gshift);
            b = (col >> vis->format->Bshift);
            *((offset) + (vis->format->Rshift >> 3)) = r; 
            *((offset) + (vis->format->Gshift >> 3)) = g;
            *((offset) + (vis->format->Bshift >> 3)) = b;
            break;
        }
        case 4:
            *((Uint32 *) (offset)) = (Uint32) col;
            break;
    }
}

Uint32 get_pix (int x, int y, SDL_Surface *vis)
{
    Uint32 col;
    
    Uint8 * offset = ((Uint8 *) vis->pixels) + y * vis->pitch
        + x * vis->format->BytesPerPixel;
    
    switch (vis->format->BytesPerPixel) 
    {
        case 1:
            col = *((Uint8 *)(offset));
            break;
        case 2:
            col = *((Uint16 *)(offset));
            break;
        case 3:
        {
            Uint8 r, g, b;
            col = 0;
            Uint32 t;
            
            r = *((offset) + (vis->format->Rshift >> 3)); 
            g = *((offset) + (vis->format->Gshift >> 3));
            b = *((offset) + (vis->format->Bshift >> 3));
            
            t = r << vis->format->Rshift;
            col |= t; 
            t = g << vis->format->Gshift;
            col |= t; 
            t = b << vis->format->Bshift;
            col |= t; 
            
            break;
        }
        case 4:
            col = *((Uint32 *)(offset));
            break;
        default:
            col = 0;
            break;
    }
    return col;
}

const float kernel[] ={.0,.26,.42,0.1,.42,.26,0};

typedef union {
        Uint8 c[4];
        Uint32 i;
} color;

void gaussianblur(SDL_Surface* s)
{
        int i, j, k;
        
        SDL_LockSurface(s);
        //make a copy of the data
        Uint32 data[200 * 30];
        k = 0;
        for (j = 0; j < 30; j++)
                for (i = 0; i < 200; i++)
                        data[k++] = get_pix(i, j, s);
    
        //horizontal
        for (j = 0; j < 30; j++)
        {
                for (i = 0; i < 200; i++)
                {
                        int kmin = i < 4? 3 - i : 0;
                        int kmax = i > 200 - 4? 200 - i + 3 : 7;
                        color c, r;
                        r.i = 0;
                        for (k = kmin; k < kmax; k++)
                        {
                                c.i = data[j * 200 + i + (k - 3)];
                                r.c[0] += c.c[0] * kernel[k];
                                r.c[1] += c.c[1] * kernel[k];
                                r.c[2] += c.c[2] * kernel[k];
                                r.c[3] += c.c[3] * kernel[k];
                        }
                        put_pix(i, j, r.i, s);
                }
        }
    /*
        //another copy, smeared horizontally
        k = 0;
        for (j = 0; j < s->height(); j++)
                for (i = 0; i < s->length(); i++)
                        data[k++] = s->get_pix(i, j);
        //vertical
        for (j = 0; j < s->height(); j++)
        {
                for (i = 0; i < s->length(); i++)
                {
                        int kmin = j < 4? 3 - j : 0;
                        int kmax = j > s->height() - 4? s->height() - j + 3 : 7;
                        color c, r;
                        r.i = 0;
                        for (k = kmin; k < kmax; k++)
                        {
                                c.i = data[(j + (k - 3)) * s->length() + i];
                                r.c[0] += c.c[0] * kernel[k];
                                r.c[1] += c.c[1] * kernel[k];
                                r.c[2] += c.c[2] * kernel[k];
                                r.c[3] += c.c[3] * kernel[k];
                        }
                        s->put_pix(i, j, r.i);
                }
        }
     */
        SDL_UnlockSurface(s);
}

int main(int argc, char *argv[])
{
        SDL_Surface *screen;
        Uint32 videoflags = SDL_HWSURFACE | SDL_DOUBLEBUF;
        int    done;
        SDL_Event event;
        int width, height, bpp;

        /* Initialize SDL */
        if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
                fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
                exit(1);
        }

        /* See if we try to get a hardware colormap */
        width = 512;
        height = 512;
        bpp = 0;

        /* Set a video mode */
        screen = SDL_SetVideoMode (width, height, bpp, videoflags);
    if (!screen) return 2;

    SDL_Surface *icn;
    SDL_Surface *vis;
    SDL_Surface *tmp = SDL_CreateRGBSurface (
             SDL_HWSURFACE | SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_ASYNCBLIT,
             200, 30, BYTES_PER_PIXEL,
             R_MASK, G_MASK, B_MASK, A_MASK);
    
    // does created surface match screen?
    if (screen->format->BitsPerPixel != BYTES_PER_PIXEL)
    {
        vis = SDL_DisplayFormatAlpha (tmp);
        SDL_FreeSurface (tmp);
    }
    else
    {
        vis = tmp;
    }
    
    
    SDL_Rect dstrect;
    dstrect.x = 0;
    dstrect.y = 0;
    dstrect.w = 200;
    dstrect.h = 30;    
    SDL_FillRect (vis, &dstrect, 0x88ff0088);
    gaussianblur (vis);

    dstrect.x = 200;

    SDL_RWops *file = SDL_RWFromFile ("alpha.png", "rb");
    SDL_Surface *alpha = IMG_LoadPNG_RW (file);
    alpha = SDL_ConvertSurface (alpha, vis->format, SDL_HWSURFACE | 
SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_ASYNCBLIT);
    
        /* Wait for a keystroke */
        done = 0;
        while ( !done) 
    {
        while (SDL_PollEvent(&event) ) {
        
            SDL_SetAlpha (vis, SDL_SRCALPHA, 255);
            SDL_BlitSurface (vis, NULL, screen, &dstrect); 
            SDL_SetAlpha (alpha, SDL_SRCALPHA, 255);
            SDL_BlitSurface (alpha, NULL, screen, NULL); 
            SDL_Flip (screen);
            SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 
255));
        
            switch (event.type) {
                case SDL_KEYDOWN:
                    if ( event.key.keysym.sym == SDLK_ESCAPE ) {
                        done = 1;
                    }
                    break;
                default:
                    break;
            }
                }
        }
    
        SDL_Quit();
        return(0);
}
_______________________________________________
Adonthell-devel mailing list
Adonthell-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/adonthell-devel

Reply via email to