look nice I wanted to use Alpha-channeled *.png files for all the tiles.
All
was going well untill I changed to fullscreen… In 640x480 with 128x64
tiles when running windowed I got usualy 40fps. But changing to
fullscreen
on the same settings gave me 4fps! Why is that?
Settings :
SDL_SetVideoMode(480, 640, 32, SDL_HWSURFACE | SDL_DOUBLEBUF |
I think you meant:
Yeah I did ;). In the code though it’s alright - I made a mistake while
typing this post.
I noticed that changing SDL_DisplayFormatAlpha to SDL_DisplayFormat gave
me
back the 40fps on fullscreen but of course turned off Alpha-blending. Is
there any way to get 32-bit images on fullscreen running faster? And why
does the windowed mode run 40fps while the fullscreen mode can’t?
I’d have to look at the rest of your code to know exactly why. There are
plenty of things that could cause this problem, far too numerous to
list.
Currently it’s quite unreadable - because of the graphics lib abstraction
that’s half finished. Here are the main functions:
#define SCREENX 800
#define SCREENY 600
#define BITDEPTH 32
#define SDLFLAGS SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN
void CImage::load(char * fname) {
if (image) SDL_FreeSurface(image);
image = SDL_DisplayFormatAlpha(IMG_Load(image));
if (!image) Error(strcat("IMG_Load failed : ",fname));
}.
inline void CScreen::draw(SDL_Surface* image, int x, int y) {
destination.x = x;
destination.y = y;
destination.w = image->w;
destination.h = image->h;
SDL_BlitSurface(image, NULL, screenSurface, &destination);
}
inline void CScreen::update() {
SDL_Flip(screenSurface);
SDL_FillRect(screenSurface,0,0);
}
void CScreen::init() {
if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1))
fprintf(stderr,"Could not initialize SDL: %s.\n", SDL_GetError());
exit(-1);
}
screenSurface = SDL_SetVideoMode(SCREENX, SCREENY, BITDEPTH, SDLFLAGS);
if ( screenSurface == NULL ) {
fprintf(stderr, "Couldn't set video mode: %s\n",
SDL_GetError());
exit(-1);
}
initialized = true;
}
void CScreen::done() {
SDL_FreeSurface(screenSurface);
SDL_Quit();
initialized = false;
}