Jump to content

  • Log In with Google      Sign In   
  • Create Account


SDL 2.0 - Double Screen Resolution


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Tolito   Members   -  Reputation: 256

Like
0Likes
Like

Posted 25 January 2014 - 10:46 PM

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!



Sponsor:

#2 dejaime   Crossbones+   -  Reputation: 3715

Like
1Likes
Like

Posted 26 January 2014 - 12:41 AM

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, 26 January 2014 - 01:08 AM.


#3 Tolito   Members   -  Reputation: 256

Like
0Likes
Like

Posted 26 January 2014 - 03:23 AM

Thank you for your response!

 

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.



#4 exOfde   Members   -  Reputation: 807

Like
4Likes
Like

Posted 26 January 2014 - 03:58 AM

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, 26 January 2014 - 04:07 AM.


#5 Ludus   Members   -  Reputation: 966

Like
1Likes
Like

Posted 26 January 2014 - 01:04 PM

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.



#6 Tolito   Members   -  Reputation: 256

Like
0Likes
Like

Posted 31 January 2014 - 12:16 AM

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!



#7 Acharis   Crossbones+   -  Reputation: 3080

Like
0Likes
Like

Posted 01 February 2014 - 05:42 AM


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.


Europe1300.eu - Historical Realistic Medieval Sim (BETA)





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS