   Blit SDL surface onto another
  How can I blit an SDL surface onto another using a 1-bit alpha mask, colorkey and per-surface alpha at the same time?   
  The documentation for SDL_BlitSurface() tells you how it will behave in the presence of these options. I don't believe SDL supports a 1 bit alpha channel at all.You could probably manipulate the surfaces so that they will work. The link above says that you can blit a surface with a colour key and per-surface alpha. So you would just have to write colour keyed pixels rather than using a 1-bit alpha mask.But I think I understand what you are trying to do. You have a surface where you want to be able to easily turn on and off pixels (the 1 bit alpha mask) while retaining colour keyed blits and per-surface alpha. Is this even remotely right? I can't think of a really clean way to do that with SDL, without keeping two copies of every surface.   ;Quote:Original post by rip-offThe documentation for SDL_BlitSurface() tells you how it will behave in the presence of these options. I don't believe SDL supports a 1 bit alpha channel at all.You could probably manipulate the surfaces so that they will work. The link above says that you can blit a surface with a colour key and per-surface alpha. So you would just have to write colour keyed pixels rather than using a 1-bit alpha mask.But I think I understand what you are trying to do. You have a surface where you want to be able to easily turn on and off pixels (the 1 bit alpha mask) while retaining colour keyed blits and per-surface alpha. Is this even remotely right? I can't think of a really clean way to do that with SDL, without keeping two copies of every surface.Yes, exactly what I want.So do I just have to write my own blit function which would blit the surface pixel by pixel?;Quote:So do I just have to write my own blit function which would blit the surface pixel by pixel?That is one way of doing it. Another might be something like this:class Surface : private noncopyable // like boost::noncopyable{    // This class takes ownership of the pointer    // It will call SDL_FreeSurface() on it.    Surface(SDL_Surface *surface, Uint32 colourKey)    :  original(surface),  display(0)    {   SDL_SetColourKey(original, SDL_SRCCOLORKEY, colourKey);   display = SDL_DisplayFormat(original);   if(!display)   { // handle error, e.g. exception with SDL_GetError()   }    }    ~Surface()    {   SDL_FreeSurface(display);   SDL_FreeSurface(original);    }    void togglePixel(int x, int y, bool on)    {   // check bounds here   // set and get pixel defined:   // http://www.libsdl.org/cgi/docwiki.cgi/Pixel_Access   if(on)   { setpixel(display, x, y, getpixel(original, x, y));   }   else   { setpixel(display, x, y, display->format->colorkey);   }    }    void setalpha(Uint8 alpha)    {   SDL_SetAlpha(display, SDL_SRCALPHA, alpha);    }    void blit(int x, int y, SDL_Surface *destination)    {   SDL_Rect rect = {x,y};   SDL_BlitSurface(display, NULL, destination, &rect);    }private:    SDL_Surface *original, *display;};You could possibly save a little memory by making a raw copy of the pixels in a std::vector<> rather than using a duplicate SDL surface (which involves a few separate allocations, the SDL_Surface, its pixels and the PixelFormat at the very least IIRC).It depends on how frequently you are changing pixels. Coding your own version of blitsurface() could slow down every blit (SDL uses a number of software tricks like assembly in some of the code paths of BlitSurface()). This method caches these changes into a "display" surface, which might be faster (but only profiling will give you the final answer).While the speed note is undecided, this class was a lot easier to implement than a custom blit function. If it meets your minimum speed requirements then that is all you need.   ;  Thanks, problem solved.