Window & Image scaling

Hi

I am developing an application with SDL 1.3 which, on the target system, uses dual 1600x1080 windows (2 monitors). On my dev system, I am limited to 1600x900 and 1 monitor, and so I’d like to implement a “viewport” where I can set a zoom factor which then lets me view both windows on one monitor, and then come release time, I just set the zoom to 0.

I guess this means scaling all the graphics down - can this be done easily with SDL 1.3 ?

Thanks in advance
Ed

Anyone? I need help! :slight_smile:

Image scaling, or texture scaling rather, is much improved in SDL 1.3 over 1.2; it’s hardware implemented as far as I understand.

The RenderCopy() function takes an SDL_Texture(pointer) and two SDL_Rects(pointers) as arguments; a source ‘src’ rect; the rectangular region of the target Texture to copy pixels FROM, and the destination ‘dest’ rect; the rectangular region on the Render target to copy TO. In SDL 1.2, the equivalent BlitSurface() took essentially the same arguments but only used the x,y coordinates of the ‘dest’ rect to decide where to place the source surface, starting with the upper left pixel of the src rect. In 1.3, RenderCopy uses the width and height of the ‘dest’ rect as well. If the dest rect is wider/thinner or taller/shorter than the source rect, then the source is effectively stretched to fill only the dest rect.

In fewer words, yes, 1.3 does have graphics scaling. In fact, it has several scaling Modes, offering lower quality+fast / higher quality + slow interpolation. As far as built-in viewport functionality goes; i don’t think there is, so you’ll have to implement that logic yourself.

Here are some links of interest from the wiki:

http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy?highlight=(\bCategoryVideo\b)|(CategoryEnum)|(CategoryStruct)

http://wiki.libsdl.org/moin.cgi/SDL_TextureScaleMode?highlight=(\bCategoryEnum\b)|(CategoryVideo)

ebyard wrote:> Anyone? I need help! :slight_smile:

Well, I guess I’ll give it a shot. Since you want a view port use one.

The easy way is to just use OpenGL for your graphics and then use
glViewport() to set the view port. That way you can code everything in what
ever coordinate system you want and it will be scaled to fit inside the
specified viewport. Or, if you are really hardcore and hate OpenGL then you
can implement a simple viewport mechanism and scale all your coordinates in
your code. I wouldn’t do that. Then again you can just use OpenGL and draw
all your graphics using coordinates in the range 0 to 1.0 and again use
glViewport to make it take up as much or as little of the screen(s) as you
want. That last one, using coordinates in the range 0 to 1 and then scaling
has the nice side effect of allowing you to adapt to any size of screen.
Writing code tied to a specific number of pixels is just a really bad idea.

Bob PendletonOn Fri, Oct 1, 2010 at 7:53 AM, ebyard <e_byard at yahoo.co.uk> wrote:

Anyone? I need help! [image: Smile]


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

Hi,

As above, if you use OpenGL with SDL, then the problem is trivial; just set
the rendering area to a different size with glViewport(…). Internally,
OpenGL will do the scaling for you. You’re best off with an orthographic
matrix if you want a (meaningful) representation of a scalar.

If you’re just using plain 'ol SDL, you can simply render everything to a
single surface, and then resize that surface appropriately to match your
screen. In your production code, you can remove this intermediary buffer,
and just draw onto the standard back buffer as you normally do.

Ian