Sdl - Lowering Resolution?


entozoon

Still Fresh
Joined
Sep 29, 2006
Messages
5
Hello all, I've just started to develop SDL programs for the gp2x in the normal 320x240 resolution and I would like to know if there's a way to make a program that runs (fullscreen) in a lower resolution, such as 160x120 or even 80x60.

(I have an idea for a pixel-art style game so lower resolution would be useful).

- I've tried changing the videomode like this
screen = SDL_SetVideoMode( 160, 120, 32, SDL_SWSURFACE);
works fine in windows but it seems to make it crash on the gp2x

I hope there's a simple way to do it otherwise I'm gonna have to come up with some crazy method that makes like four pixels for every pixel and arrrgh. lol


PS: Anyone know why sometimes when I have SDL_ShowCursor(SDL_DISABLE); it still shows the cursor?

Thanks in advance everyone!!

-Myke
 
First of all the surface should be 16 (or 8) bits, not 32. Also, not every SDL supports scaling, you should perhaps use the Open2x libraries if you don't already.

Alternatively, you could have something like

Code:
// this is what gets shown on the LCD
SDL_Surface* realScreen = SDL_SetVideoMode(320, 240, 16, SDL_SWSURFACE);
SDL_PixelFormat* f = realScreen->format;

// this is what you draw to
SDL_Surface* screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 160, 120, f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);

// *game drawing code goes here*

if(SDL_MUSTLOCK(screen)) SDL_LockSurface(screen);
if(SDL_MUSTLOCK(realScreen)) SDL_LockSurface(realScreen);

// draw screen->pixels to realScreen->pixels

if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
if(SDL_MUSTLOCK(realScreen)) SDL_UnlockSurface(realScreen);

SDL_flip(realScreen);
 
Cheat and just zoom a rectangle around the bit of your screen your interested in making sure you keep the right aspect ratio (there are GP2X SDL features to do that in hardware) and only render data to the bit your showing ;) .

SDL_GP2X_Display

Hackish I know but should give you what you want without any pain and the hardware will scale up your image to the LCD resolution.

As for the SDL_ShowCursor(SDL_DISABLE);, there are some specifics of the GP2X handling of that.

To copy a comment from some of my source code ;)

Code:
   // GP2X Specific, must be called after any SDL_SetVideoMode to ensure the hardware cursor is off
   // Note: On the GP2X SDL_SetVideoMode recalls SDL_Init().
   SDL_ShowCursor(SDL_DISABLE);
 
hmm.. both really interesting ideas.

I'm relatively inexperienced so can't quite think how to go about drawing all the pixels from one surface to another although that sounds like the best bet.

I'll try my hand at the zooming one to save myself a larger headache than this is already giving me

.. wonder which would be fastest..
 
If I recall correctly, GP2X has support for zooming the framebuffer itself, effectively supporting other resolutions natively. I think this would be a better alternative to using the hardware blits to do zooming. Maybe SDL can be modified to support this?
 
Yeah that's what I was getting at, couldn't see a way to do it but then again I'm new to all this stuff.
 
Miek said:
Yeah that's what I was getting at, couldn't see a way to do it but then again I'm new to all this stuff.

I have get rid of SDL on my side and I attack the hardware registers. Yes there is a way to use a scaler where you would have lower resolution than 320x240 (like 160x240, 160x120...). However, this affect the RGB layer only.

I think it may be possible to use it with SDL as you can overwrite the hardware registers and use the 16-bit screen pointers in SDL (from what I remember I was using before switching to hardware).

These are the registers I modify when I set a resolution (I assume you are in 16-bit display):

0xC0002906 = 1024 * SIZE_X / 320
0xC0002908 = 2 * SIZE_X * SIZE_Y / 240
0xC000183A = (SIZE_X / 8 - 1)|((SIZE_X / 8 - 1)<<8)
0xC000181E = 0xC0001824 = SIZE_Y
0xC0001820 = 0xC0001826 = SIZE_X-1
0xC0002892 = SIZE_X
0xC0003010 = SIZE_X
0xC0003014 = SIZE_Y
0xC000290C = SIZE_X

I am now doing some research to modify the TV-Output. I do have the 720x480 (ntsc) with 16 (multiplex YCrCb and 24 bit RGB color throughput), I also got a 720x240 non-interlaced but sometimes the switch doesn't work but very few times... about 1 on 30 tries.

I have to work also to get a native lower resolution on TV, I think it may be possible to also do it on the LCD.

I try to understand all the clocks and timing of all those output mode...

Regards,
 
Last edited by a moderator:
Back
Top