Blitting surfaces

In my current project, most of the time I simply draw directly to the
screen. However, I’d like to create a small 200x200 surface to draw on,
then blit that to the screen. Usually when I do this kind of thing, it’s
not a problem. This time, I’m just getting a big black box where there
should be a white outline of a box.

I create the surface debug_panel like so:

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif

dw = 200;
dh = 200;
dx = screen->w - dw - 1;
dy = screen->h - dh - 1;

debug_panel = SDL_CreateRGBSurface(SDL_SWSURFACE, dw, dh, 8, rmask, gmask,
bmask, amask);

Then I have my painting function:

void draw_debug_panel()
{

draw_square(debug_panel,SDL_MapRGB(debug_panel->format,255,255,255),0,0,dw,dh);

SDL_Surface *s = SDL_DisplayFormat(debug_panel);
SDL_BlitSurface(s,NULL,screen,NULL);

SDL_FreeSurface(s);

}

I then have an SDL_Flip() call in my main redrawing loop (yes, it’s a
doublebuffered 8-bit surface). draw_square() is your normal pixel-plotting
function that works fine if I pass it the screen surface. Help, anyone?—
Cheers,
Josh

PGP: http://revvy.box43.net/Josh_Matthews.asc

Nevermind, I have discovered that I have to use DisplayFormat after creating
the surface, not after painting to it. I never saw that documented, though
=\On 5/13/06, Josh Matthews wrote:

In my current project, most of the time I simply draw directly to the
screen. However, I’d like to create a small 200x200 surface to draw on,
then blit that to the screen. Usually when I do this kind of thing, it’s
not a problem. This time, I’m just getting a big black box where there
should be a white outline of a box.

I create the surface debug_panel like so:

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif

dw = 200;
dh = 200;
dx = screen->w - dw - 1;
dy = screen->h - dh - 1;

debug_panel = SDL_CreateRGBSurface(SDL_SWSURFACE, dw, dh, 8, rmask, gmask,
bmask, amask);

Then I have my painting function:

void draw_debug_panel()
{

draw_square(debug_panel,SDL_MapRGB(debug_panel->format,255,255,255),0,0,dw,dh);

SDL_Surface *s = SDL_DisplayFormat(debug_panel);
SDL_BlitSurface(s,NULL,screen,NULL);

SDL_FreeSurface(s);

}

I then have an SDL_Flip() call in my main redrawing loop (yes, it’s a
doublebuffered 8-bit surface). draw_square() is your normal pixel-plotting
function that works fine if I pass it the screen surface. Help, anyone?


Cheers,
Josh

PGP: http://revvy.box43.net/Josh_Matthews.asc


Cheers,
Josh

PGP: http://revvy.box43.net/Josh_Matthews.asc