SDL_BlitSurface not blitting anything?

Hi (again) all… I still have some problems :frowning:

Is there some speacial cases where SDL_BlitSurface doesn’t blit anything???
I’m trying to load an image from a file (in the attached example, I used
SDL_LoadBMP) but I got the same problem with SDL_image functions. I’d like
to convert this file to another format (the one from the example of
SDL_CreateRGBSurface) then copy this new image to a third surface and
finally blit that third surface to the screen. The conversion seems to be
alright but then
when I blit from my ‘converted’ image to my third image, it seems like
nothing happens??? See example below: the ‘converted’ image blits fine but
the third image is misssing… Any idea of what I’ve done wrong???

#include “SDL.h”
#include <stdlib.h>
int main(int argc, char *argv[])
{
SDL_Event Event;
SDL_Surface *Screen;
bool Quit;

if (SDL_Init(SDL_INIT_VIDEO) < 0) exit(1);
atexit(SDL_Quit);

Screen = SDL_SetVideoMode(320, 200, 0, SDL_SWSURFACE);
if (Screen == NULL) exit(1);

SDL_Surface *surf0, *surf1, *surf2;
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask =

0x000000ff;
#else
rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask =
0xff000000;
#endif
surf0 = SDL_LoadBMP(“paille0.bmp”);
surf1 = SDL_CreateRGBSurface(SDL_SWSURFACE, surf0->w, surf0->h, 32,
rmask, gmask, bmask, amask);
surf2 = SDL_CreateRGBSurface(SDL_SWSURFACE, surf0->w, surf0->h, 32,
rmask, gmask, bmask, amask);
if ((surf0==NULL) || (surf1 == NULL) || (surf2 == NULL)) exit(1);

if (SDL_BlitSurface(surf0, NULL, surf1, NULL) < 0)
     fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
if (SDL_BlitSurface(surf1, NULL, surf2, NULL) < 0)
    fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
Quit = false;
while (!Quit) {
    while (SDL_PollEvent(&Event))
        if (Event.type==SDL_QUIT)
            Quit = true;

    SDL_Rect dstrect1 = {0,0,0,0};
    if (SDL_BlitSurface(surf1, NULL, Screen, &dstrect1) < 0)
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());

    SDL_Rect dstrect2 = {64,0,0,0};
    if (SDL_BlitSurface(surf2, NULL, Screen, &dstrect2) < 0)
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());

    SDL_UpdateRect(Screen, 0, 0, 0, 0);
}
SDL_FreeSurface(surf2);
SDL_FreeSurface(surf1);
SDL_FreeSurface(surf0);
return 0;

}

Thanks if you read till here :),
Ga?tan.

“Gaetan de Menten” wrote:

when I blit from my ‘converted’ image to my third image, it seems like
nothing happens??? See example below: the ‘converted’ image blits fine but
the third image is misssing… Any idea of what I’ve done wrong???

surfaces with alpha channels are created with SDL_SRCALPHA. Remove it
(SDL_SetAlpha) to get non-blending blits. Also, RGBA->RGBA blits do not
change the destination alpha channel. It’s all in the docs

if (SDL_BlitSurface(surf0, NULL, surf1, NULL) < 0)
     fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
if (SDL_BlitSurface(surf1, NULL, surf2, NULL) < 0)
    fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());

Notice how you blit the images over to surf0 and surf1.

    SDL_Rect dstrect1 = {0,0,0,0};
    if (SDL_BlitSurface(surf1, NULL, Screen, &dstrect1) < 0)
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());

That means this should be surf0, not surf1,

    SDL_Rect dstrect2 = {64,0,0,0};
    if (SDL_BlitSurface(surf2, NULL, Screen, &dstrect2) < 0)
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());

and this should be surf1 not surf2.–
Jordan Wilberding <@Jordan_Wilberding>
Diginux.net Sys Admin

<wod.sourceforge.net>
<aztec.sourceforge.net>

“Fight war, not wars,
destroy power, not people”
-Crass