Welcome! Log In Create A New Profile

Advanced

SDL screen resolution

Posted by TheDrev 
SDL screen resolution
April 07, 2009 08:45PM
Hi !

I've made and port some games with wii-sdl, but I still got a question with the screen resolution.

Say I got a tilemap of 15*15 tiles of 32*32 px. So the map size is 480*480.

When the screen surface is created with that dimension, the resulting image is centered, the left and right sides of the TV is black, and cannot be used to blit.

Apparently, the dimension that cover the whole screen is 640*480, so, the game need 20 tiles width and 15 tiles height.

Is there a way to stretch a screen surface of 480*480 or less, so it can fill the TV screen ?



Edited 3 time(s). Last edit at 04/08/2009 09:18AM by TheDrev.
Re: SDL screen resolution
April 07, 2009 09:03PM
Yes.

Create a secondary surface and blit everything to that. Then use SDL_SoftStretch to stretch it to the screen surface.

        SDL_Rect dr = {0,0,640,480};
        SDL_Rect sr = {0,0,480,480};

        dr.x = (int)(sr.w - dr.w) / 2;
        dr.y = (int)(sr.h - dr.h) / 2;

        SDL_SoftStretch(backbuffer,&sr,screen,&dr);



Edited 1 time(s). Last edit at 04/07/2009 09:03PM by scanff.
Re: SDL screen resolution
April 08, 2009 07:22AM
Or you could just add some padding to the layout, add some background image and/or usable buttons.
Re: SDL screen resolution
April 08, 2009 09:25AM
Thanks !

It is safe ? It's not documented and there is a warn.

/* Not in public API at the moment - do not use! */
extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);

I'll test that anyway :D
Re: SDL screen resolution
April 08, 2009 07:16PM
I use it and it works just fine.
Re: SDL screen resolution
April 12, 2009 11:28PM
I tried but I see no differances

void draw (SDL_Surface *screen)
{

	SDL_Rect dr;
	SDL_Rect sr;
	
	sr.x=0;
	sr.y=0;
	sr.h=480;
	sr.w=480;
	
	dr.h=480;
	dr.w=640;
	dr.x = (int)(sr.w - dr.w) / 2;
	dr.y = (int)(sr.h - dr.h) / 2;

      SDL_Surface *backbuffer = SDL_SetVideoMode( 640, 480, 8, SDL_FULLSCREEN);
	
    while (!done)
    {
             //Logic & blit on screen surface
             ...
		
	SDL_SoftStretch(screen,&sr,backbuffer,&dr);
        SDL_Flip(backbuffer);
    }



Edited 3 time(s). Last edit at 04/13/2009 03:41PM by TheDrev.
Re: SDL screen resolution
April 13, 2009 02:02AM
Your dr.x is negative, shouldn't that be 0?

Michael



Edited 1 time(s). Last edit at 04/13/2009 02:03AM by Michael.
Re: SDL screen resolution
April 13, 2009 11:10AM
I tried with a lot of values, including 0.


Watching the source code of this function (which is self explanatory), we can see what parameters settings that produce errors...
[stage.maemo.org]

I assume that :

- surface must have the same format surface.
- Clipping is not supported (maybe that's why nothing is displayed is part of the image is 'out the screen',with dr.x negative)
Re: SDL screen resolution
April 13, 2009 04:00PM
Hey hey it works after hours of test.
I did not found docs and examples on the Internet, so there is the way I used if that helps :

First init the screen with the resulting resolution, for example :

screen = SDL_SetVideoMode( 640, 480, 8, SDL_HWSURFACE);


Like scanff said, blit everything to a backbuffer SDL_Surface*
But warning, this backbuffer must have the same format as the screen surface, so use the SDL_DisplayFormat func for init (it's allocate memory too...).

SDL_Surface* backbuffer = SDL_DisplayFormat(screen);
SDL_Rect srcrect = {0,0,480,480};            //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
SDL_Rect dstrect = {0,0,640,480};            //equals screen resolution

then blit in the backbuffer and finally do the stretch and flip

SDL_SoftStretch(backbuffer,&srcrect,screen,&dstrect);
SDL_Flip(screen);


As a conclusion, most games use large maps that even require scrolling, and , like in a common used map format the problem is reversed and the number of tiles to display is calculated from the screen res.

In my case there the game rules belong to a restricted number of tiles, this stretch method must be used.


Now I'd like to have mP3/ogg and PNG support and everything will be set XD.
Any clues ? I read that the sdl source must be recompiled with flags, but there is no svn on the google code page and I'm not that smart anyway...


Edit :

Sorry to dig out an old topic, just to notice that there is a simple way to stretch screen with SDL app that uses the function SDL_GetVideoSurface().

in a .h header file includedin the files where the SDL_GetVideoSurface() is present, define the backbuffer and a macro :

#ifndef GLOBALS_H
#define GLOBALS_H

#include <SDL/SDL.h>

SDL_Surface* backbuffer;

#define SDL_GetBufferSurface() backbuffer

#endif

... and replace SDL_GetVideoSurface() with SDL_GetBufferSurface with your favorite source editor. If it crashes you can easly re-replace your macro...

there is also the stretch lib [sdl-stretch.sourceforge.net] kinda looks what is present in the apple ][ emulator.
I'll try to compile it to see if the generated ppc assembler works fine.



Edited 4 time(s). Last edit at 12/19/2009 02:14AM by TheDrev.
Sorry, only registered users may post in this forum.

Click here to login