Jump to content
  • Advertisement
Sign in to follow this  
tdcoish

Supersampling in SDL2

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, this is my first time post. Anyway, I have a very simple game that I'm working on, and, being a simple 2D game, there's lots of processor power left over to throw at different things. I decided I wanted to supersample the game, also known as downsampling. I want to render the game at double the final resolution, and then blend/scale to the final resolution.

 

The problem is that SDL2 just doesn't seem to give any easy way of creating a renderer at any resolution different from the window.

 

I've tried to use SDL_SetRenderLogicalSize, and a few other things, but right now the only thing that I think would work is creating a texture at the supersampled resolution that I write everything to, and then manually blitting everything, and then creating a resolution at the final resolution that I blend everything down to again, before sending that to the renderer. The problem with that, is that it really reduces a lot of the benefit of SDL2 in the first place.

 

It's very possible that I'm just coming at this from the wrong direction.

 

Share this post


Link to post
Share on other sites
Advertisement
Well, at least in DirectX you usually do supersampling in hardware, i.e. using a multisampled render target (framebuffer) instead of manually rendering to twice the resolution and then downscaling. Check if SDL2 doesn't have an option to set the backbuffer to be multisampled, perhaps.

Share this post


Link to post
Share on other sites

Looks like I'll need to use OpenGL instead of the SDL2 2D API. The relevant line of code is something like:

 

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLE_BUFFERS, 1);

 

That would require me rewriting the rendering of the game though. I'll definitely keep looking, and may simply convert to doing that. Thanks for the reply.

Share this post


Link to post
Share on other sites

Hi,

 

This may or may not be relevant to your problem, but I write this in the hope that it may help somehow...

 

I looked into supersampling some time ago for improving the rendering of the game I'm writing, where all of its original assets are low resolution (PSX era), and so my first stab at the solution came in the form of rescaling the sprites in real-time (during load / init) using the scale2x algorithm (easily ported to utilize SDL2), and later settled with simply loading pre-scaled scale2x assets at load-time (for sake of simplicity). The hqx algorithm is probably worth looking into, too FYI.

 

I bring up a window with a size two times that of the original resolution (768x448), and then use SDL_SetLogicalSize with the original game asset resolution (384x224). I take into account for the difference in positioning and size coordinates of game objects by computing the proper origins, offsets and what not at compile / build time -- although it is best that these be done at run-time, I simply haven't gotten around to situating things to do at run-time...

 

As I'm still learning the ins and outs of game programming, I have no idea how efficient or wise this kind of implementation holds in the long run, but I can attest to it holding up at least through several internal rewrites of rendering code, and is easily integrated with other rendering systems in mind (i.e.: libRocket). The downside (of which I've seen) boils down to that of maintenance cost (of keeping up with two different resolutions, assuming you do not wish to throw away the original).

 

(In case you have not), you should familiarize yourself with the SDL2 hint SDL_HINT_RENDER_SCALE_QUALITY especially when in use with SDL_SetLogicalSize, as this makes a significant difference in the resulting image. "Linear" produces anti-aliased results, which is great for rendering text, but at the potential cost of degrading low resolution artwork, which generally yields a better image with "nearest".

Share this post


Link to post
Share on other sites

Thanks for the reply. I tried something similar, although maybe only half-assed it, and it didn't really work for me. As of right now, supersampling is a low priority thing with the game, but when the project is nearing completion I'll return to this post and try to figure it out again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!