Screen Stretch, Opengl?


Miner49er

Active Member
Joined
Mar 1, 2004
Messages
655
Age
49
Website
www.lessermatters.co.uk
Hi Folks,


I'm currently hacking together a fantastic game which will hopefully be available for the Pandora (and everything as I'm using SDL and I already have it running on Linux and Windows...).

My problem is that The game is based heavily on a classic amiga gam and I'm currently ripping the graphics, so it's basically 320x200. On my PC this is fine, fullscreen takes me fullscreen, no black borders and stuff. On my little Acer Aspire One laptop, the LCD doesn't seem to want to go into 320x200 mode, so I get a tiny display in the center of the screen!!!

This is annoying.

So, I'm looking at using OpenGL and it's clever texture stuff, to stretch the screen (like ZSNES does, I think). I don't want to resize all the graphics at the moment.

So, does anyone have any ideas how I can convert a plain SDL game to openGL? I mean, i'm currently drawing everything to an SDL_surface - I'm guessing there _should_ be a way to convert that surface into a texture and then 'blit' that texture to the full screen size? Or am I wrong?

Or do I have convert each of my graphic objects into textures and 'blit' them all individually?

Please help me!!

Thanks,

m
 
Last edited by a moderator:
You can draw to a texture in OpenGL, but it's not the common way of doing things.

There's a trick to load OpenGL textures out of SDL surfaces using LockSurface and surface->pixels.
You can use this to convert your surfaces to textures and then draw those.
OpenGL, as far as I can remember, doesn't draw textures directly, so you also need a generic 'sprite' geometry, just like a 1 by 1 pixel square, and then scale and position it using the matrix stack.
edit: I mean there's no 'blit' function in OpenGL, you have to apply the texture you want, then draw some geometry with the proper texture coordinates.

Assuming that SDL doesn't have any method for screen stretching.
 
Last edited by a moderator:
http://pandorawiki.org/OpenGL_ES_1.1_Tutorial

It's amazingly easy in OGL, with no real downsides. When you create an orthangonal matrix to do stuff in 2D, you specify aspect ratio and width/height variables. Now, these can be whatever you want but they will relate to the right and the bottom of the screen, with the left and top being 0. What this means, is that no matter how big you define your screen in SDL, whatever you put for width will always be the right edge of the screen. Stretching kinda goes without saying in OGL ;). So, that's as easy as moving over to OGL.

If you want code to convert a SDL_surface into a OpenGL texture, I've got loads. Just ask.
 
Last edited by a moderator:
First, your laptop graphics drivers (or possibly the BIOS) may well have an option to sort this out for you and stretch small resolutions to the full screen automatically.

Second, if you are in control of when the game actually has to draw to the screen, you can make it blit to a 300x200 surface as you currently are and then on every update just rotozoom the surface to expand it to the screen size and put it into another, larger Surface that you actually draw to the screen (SDL_gfx module has a built-in rotozoomer, and there are several others). It's a performance hit but the chances are it will only be necessary on your computer (the Pandora will probably stretch that image automatically for you no problem).

Also, I've noticed that updating your SDL libs can sometimes fix such problems, and I know that when running as root on my Linux laptop, I get the same problem... running as other users tends to fix it entirely.
 
Last edited by a moderator:
Using OpenGL just for stretching a rectangle to the screen would be a waste of battery power on Pandora. This stretching can be done more efficiently by the display controller.
 
SDL, on its own is resolution dependent, This is the exact problem that I wrote Quad-Ren to solve.
 
'Xmas' said:
Using OpenGL just for stretching a rectangle to the screen would be a waste of battery power on Pandora. This stretching can be done more efficiently by the display controller.
He's talking about his personal laptop.
 
Last edited by a moderator:
'lulzfish' said:
'Xmas' said:
Using OpenGL just for stretching a rectangle to the screen would be a waste of battery power on Pandora. This stretching can be done more efficiently by the display controller.
He's talking about his personal laptop.


Whatever he does should end up applying to a Pandora version too, hopefully.

Using the display controller to stretch might not be an easily available or desirable option. You wouldn't want to mess with X11 environment by changing the display settings out from underneath other things - it'd be worse than writing directly to the framebuffer. Drawing a single textured quad (albeit a large one) isn't going to take a ton of GPU resources or battery time. With any luck the environment or SDL will have some options for scaling window surfaces readily available.

Of course that doesn't solve your current problems, but yeah, OGL is a good choice. The other alternative is to scale it yourself - a 2x2 or 3x3 scale should be sufficient for your netbook and straightforward to write.
 
Last edited by a moderator:
'Exophase' said:
The other alternative is to scale it yourself - a 2x2 or 3x3 scale should be sufficient for your netbook and straightforward to write.
This is what I've done and it seems to work a treat at the moment - I'll try with the CPU 'turned down' at some point. It's very easy to underestimate the power of CPU's nowadays - I just though looping through each pixel would be slow as hell! But no, it's dead quick and I'm dead pleased with the results!!! WHOOOT!

Thanks for the tips guys - The next game I tinker with will have to use OGL I reckon, just from playing with trying to get this screen doubled I can see the power of it - so quick!

Damn, It's nice to see my little game running on my Aspire One at the correct resolution!
 
Last edited by a moderator:
Back
Top