[SDL] Slow rendering - HELP

Started by
2 comments, last by Think128 19 years, 1 month ago
Im using the newest version of SDL, in software mode. My screen size is 800x600x32. My images are 32Bit PNGs (I use SDL_Image). The thing is that I get very different FPS on computer that have similar stats. I get ~200 FPS in windowed on my machine and 19 FPS on fullscreen. There is not that much Blitting involved. I use a mixture of images, ones that use the alpha channel in the PNG file and ones that use a color key for transparency. Here is some of my code: Init:

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
// Bite Order
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	rmask = 0x00000000;
	gmask = 0x000000ff;
	bmask = 0x0000ff00;
	amask = 0x00ff0000;
#else
	rmask = 0x00ff0000;
	gmask = 0x0000ff00;
	bmask = 0x000000ff;
	amask = 0x00000000;
#endif
newScr = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);

Here is How I load my Images. SDL_Surface *LoadImage(const char *file, SDL_Surface *screen, bool AlphaFlag) - file is the File Name - screen is the main SDL Surface - AlphaFlag tells the function to use PNG alpha channel or not. [T/F]

SDL_Surface *LoadImage(const char *file, SDL_Surface *screen, bool AlphaFlag)
{
	Uint32 color_key;
	SDL_Surface *tempImg;
	SDL_Surface *newImg;
	SDL_RWops *rwop;

	// Opens the file and reads it into a temp image
	rwop = SDL_RWFromFile(file, "rb");

	tempImg = IMG_LoadPNG_RW(rwop);

	// If the Image is Alpha Enabled
	if (AlphaFlag)
	{
		// Creates a new Surface With Alpha Channel
		newImg = SDL_CreateRGBSurface(SDL_SWSURFACE, tempImg->w, tempImg->h, 32, rmask, gmask, bmask, amask);
		newImg = SDL_DisplayFormatAlpha(tempImg);
	}else{
		// Creates a new Surface without an Alpha Channel
		newImg = SDL_CreateRGBSurface(SDL_SWSURFACE, tempImg->w, tempImg->h, 32, rmask, gmask, bmask, amask);
		newImg = SDL_DisplayFormat(tempImg);
	}

	if (tempImg)
	{
		// Kills the temp Image
		SDL_FreeSurface(tempImg);
	}

	// Sets the transparency
	if (AlphaFlag)
	{
		color_key = SDL_MapRGBA(screen->format, 0, 0, 0, 255);
	}else{
		// Resort to Pure Green as Transparency
		color_key = SDL_MapRGB(screen->format, 0, 255, 0);
	}

	// Set Color Key
	SDL_SetColorKey(newImg, SDL_SRCCOLORKEY | SDL_RLEACCEL, color_key);
	
	return newImg;
}

Is SDL_RLEACCEL a bad thing in this case? Is it slow because of the SDL_BYTEORDER? Could the speed be better if it was run on Hardware Instead? In some cases there are over 50 images being blitted onto the screen, all are preloaded into memory before they are rendered in a loop (for a menu system). Is there a way i can boost this code?? Could the slow down be because im running it in Visual Studio with Debug mode, and not release mode?
Advertisement
I believe SDL_DOUBLEBUF was the culprit. :(
Most of the time, SDL has trouble creating a hardware surface in windowed mode. You're probably getting a good framerate because it's defaulting to software (even though you explicitly implied hardware).

The reason you're lagging in fullscreen is, well, its SDL. Try using SDL with OpenGL (I promise it's as easy as SDL). http://www.libsdl.org/opengl/index.php
- A momentary maniac with casual delusions.
Is SDL better at software then OpenGL? I know that OpenGL obviously owns at hardware but I was wandering about the other way around.

This topic is closed to new replies.

Advertisement