Jump to content
  • Advertisement
Sign in to follow this  
Mastadex

[SDL] Slow rendering - HELP

This topic is 4977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Is SDL better at software then OpenGL? I know that OpenGL obviously owns at hardware but I was wandering about the other way around.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!