[SDL] SDL 1.3 image scaling

ebyard e_byard at yahoo.co.uk
Thu Dec 23 01:26:15 PST 2010


Hi

Yeah I have done the same, here's some test code. I'd be interested to see what happens on your system.


Code:

#include "SDL.h"
#include "SDL_image.h"
#include <stdio.h>

int wmain(int argc, char *argv[])
{
	int numdisplays, defaultdisplay, i;
	int nummodes, j;
	int * scalemode;
	SDL_TextureScaleMode scaleMode = SDL_TEXTURESCALEMODE_FAST;
	SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;

	SDL_Surface *testImg;
	SDL_Rect srcRect,dstRect;
	SDL_Texture *testTxu;

	SDL_DisplayMode mode;

	srcRect.w = 1024;
	srcRect.h = 768;

	if (SDL_Init(SDL_INIT_VIDEO) != 0) 
	{
		printf("Error initializing SDL: ");
		return 1;
	}
	
//	IMG_Init(IMG_INIT_BMP);
	Uint32 ticks = SDL_GetTicks();
	testImg = IMG_Load("test.bmp"); // is a 24 bit BMP but same happens with a 32 bit PNG...
	printf("Load time = %ld mS ",SDL_GetTicks() - ticks);
	if (testImg == NULL)
	{
		printf("Error loading file %s",IMG_GetError());
		return 1;
	}
//	SDL_DisplayFormat(testImg);

	atexit(SDL_Quit);
 
	SDL_SelectVideoDisplay(0);
	SDL_Window *window1 = SDL_CreateWindow("Window 1",0,0,1280,1024,SDL_WINDOW_SHOWN|SDL_WINDOW_MAXIMIZED);
	SDL_CreateRenderer(window1,-1,SDL_RENDERER_SINGLEBUFFER); // used to use hardware accel - should turn it back on!
	SDL_SelectRenderer(window1);

	SDL_SelectVideoDisplay(1);
	SDL_Window *window2 = SDL_CreateWindow("Window 2",0,0,1280,1024,SDL_WINDOW_SHOWN|SDL_WINDOW_MAXIMIZED);
	SDL_CreateRenderer(window2,-1,SDL_RENDERER_SINGLEBUFFER);
	SDL_SelectRenderer(window2);

	srcRect.x = 0;
	srcRect.y = 0;
	dstRect.x = dstRect.y = 0;

	dstRect.w = 1280;
	dstRect.h = 1024;

	for (i=0;i<2;i++)
	{
		SDL_SelectVideoDisplay(i);

		if (i==0)	// There seems to be a bug in SDL where SDL_GetCurrentVideoDisplay always returns 0 so have to use this for now!
			SDL_SelectRenderer(window1);
		else
			SDL_SelectRenderer(window2);

		testTxu = SDL_CreateTextureFromSurface(0,testImg);
		SDL_SetTextureScaleMode(testTxu,scaleMode);
		SDL_SetTextureBlendMode(testTxu,blendMode);
		SDL_RenderClear(); /* clear the screen */
		ticks = SDL_GetTicks();
		SDL_RenderCopy(testTxu,&srcRect,&dstRect); /* render the area of the texture defined by textureRegion (use NULL for the full thing) */
		printf("Render time = %ld mS \r\n",SDL_GetTicks() - ticks);
		SDL_RenderPresent(); /* update the screen */
	}
	SDL_Delay(5000);
	SDL_FreeSurface(testImg);

	IMG_Quit();
	SDL_DestroyWindow(window1);
	SDL_DestroyWindow(window2);
	return 0;
}







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20101223/16170471/attachment-0008.htm>


More information about the SDL mailing list