Hi (again) all… I still have some problems
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.