Public Group

# SDL 2.0 - Double Screen Resolution

This topic is 1811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm unfortunately bringing this topic back from the dead (initially posted here: http://www.gamedev.net/topic/651375-double-screen-resolution/)

In favor of using SDL_BlitScaled, I migrated all of the code to SDL 2.0. Unfortunately, the slowdown is back again. How can I double the screen resolution so that every 1x1 pixel is a 2x2 pixel? I'm surprised that they still haven't implemented anything like this. It runs at full speed at the small resolution, but I would like for it to be double that without having to scale all of the graphics in advance, which will consume more ram.

Is there something that I am forgetting? Thanks!

##### Share on other sites

Well, rescaling everything on every frame doesn't look like a good idea to me, unless:

1 - Zooming in and out plays a significant role on your gameplay;

2 - Your game is zooming in and out constantly or too often;

3 - You'd need to use too many different zoom levels simultaneously.

But I am afraid I don't know anything that can render a scaled image without actually going through the expensive process of scaling it.

But if you do not change your zoom continuously or anything like that, I'd recommend against real-time scaling. It is a rather expensive process, and I'd prefer not to do it on-the-fly.

In most cases, RAM is cheaper than computing power, so I would choose to pre-scale everything to a given zoom level.

But if the zoom level changes too often, pre-scaling may really be a bad option. In this case, you should try to reduce the number of scaling processes to a minimum.

The first thing I'd try would be drawing everything to a Buffer and then bliting it scaled to the screen. But it would still require a scaling of a big chunk of data on-the-fly, so... no miracles.

Can you give us more details on why exactly you need this feature?

Edited by dejaime

##### Share on other sites

One image is approximately 10,000x8 pixels, which doubles to 20,000x16. Having everything scaled in advance was working well with SDL 1.2, but when storing that many pixels was the only way to display a scaled version to the screen and they couldn't all be stored, and having been told that SDL 2.0 could natively draw graphics double the scale without a slowdown, I migrated the code to SDL 2.0.

There unfortunately is still a slowdown, even when scaling only the final version of the image instead of each individual one.

The native resolution is less than 320x240 pixels. This is a suitable resolution for the graphics that are in use and it saves space. It looks much better with double the resolution, however, but has high-detailed graphics that cannot all be stored in ram if everything is double the scale.

I heard that SDL 2.0 could natively do this. Would the slowdown still be present if I were to write my own version of SDL_BlitSurface that blits four pixels for every one pixel of a surface? What I'm thinking SDL_BlitScaled does is it does math to scale the surfaces before blitting them to the screen.

##### Share on other sites

I would suggest you to use SDL_Textures instead of SDL_Surfaces.

SDL_Textures are being compute by your videocard and is much faster

then the "old style".

Also the scaleing is automatic there. you need just a SDL_Rect of the end

resolution you want and tada SDL do the job for you and it's scaled.

The function you need would be then

int SDL_RenderCopy(SDL_Renderer*   renderer,
SDL_Texture*    texture,
const SDL_Rect* srcrect,
const SDL_Rect* dstrect)



http://wiki.libsdl.org/SDL_RenderCopy

Edited by exOfde

##### Share on other sites

As exOfde has already said, you should be using textures instead of surfaces. This will allow you to take advantage of your GPU's processing power to transform images quickly and efficiently, and scaling is automatic given the destination rect. The reason you're experiencing slowdown is because you're using the CPU for image processing, which is very slow for that kind of thing.

##### Share on other sites

Thank you for the useful responses, everyone! My guess was that using SDL_Textures instead would help, but there was a problem loading a 10,000x8 image as a texture. It looks like using an image that is squarer works, so that is no longer a problem.

I think my last question regarding SDL_Textures is this: by what means can I edit the contents of an SDL_Renderer? With SDL_Surfaces, using what will be rendered to the screen as a surface, I can easily edit pixels. I wrote a function to multiply a color to every pixel on a surface, which is then rendered to more. How can I go about doing the same thing for a renderer? Maybe I should start a new topic, but replies to this question are welcome. Thanks again, everyone!

##### Share on other sites

but there was a problem loading a 10,000x8 image as a texture. It looks like using an image that is squarer works, so that is no longer a problem.
It's not about "squarity" (non power of 2 textures are supported extremelly well nowadays) but about maximum size (each dimension sepatrately). Also, just that it works on your machine means nothing (it's GPU dependant).

Generally and oversimplyfying and making assumptions:

- at the moment of writing up to 1024 is a very safe size, if it does now work it means the hardware is too outdated to bother

- 8192 is the maximum that is reasoanably safe for modern/higher end machine, do not exceed this number under any circumstances (at the moment of writing this post)

- my unscientific and not necessarily correct observation is that 4096 is a safe target size or 2048 if you want to support older laptops

I think my last question regarding SDL_Textures is this: by what means can I edit the contents of an SDL_Renderer? With SDL_Surfaces, using what will be rendered to the screen as a surface, I can easily edit pixels.
The short answer is, you can't. OK, you can but... It's a can of worms, can be ultra slow on some machines (and again, just because it works fast on your machine means nothing). Generally, it's highly not recommended.

If you need to direct pixel access it's probably best to just do it on SDL_Surface and then convert to SDL_Texture.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634059
• Total Posts
3015291
×