Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render to half-sized framebuffer, then scale it up to achieve pixelated look

I am about to create a little 2D desktop game with libGdx and I want it to have that retro pixelated look you know from games like "Flappy Bird". To achieve that effect, I thought of the following:

  1. Create a game window (e.g. 640x480)
  2. Create a framebuffer half that size (i.e. 320x200)
  3. Render everything to the framebuffer
  4. Get the texture from the framebuffer
  5. Draw the texture to the screen with SpriteBatch, scaling it 2 times up and using TextureFilter.Nearest.

I know I could scale each sprite individually with SpriteBatch.draw() but I thought, rendering everything at its original resolution and just scale up the final composition might be easier.

So would the above technique be an appropriate way of getting that pixelated look?

like image 643
snorge Avatar asked Nov 23 '25 06:11

snorge


1 Answers

What you have in mind sounds like a perfectly fine approach. The downside is that it does involve an additional data copy, but on the other hand your original rendering is for only 1/4 of the pixels, which saves you quite a bit of rendering overhead.

In plain OpenGL, you could use glBlitFramebuffer() for step 5. This requires OpenGL 3.0 or higher. It's essentially the same operation as drawing a textured quad, but it's a single call, and the underlying implementation could potentially be more efficient.

like image 153
Reto Koradi Avatar answered Nov 25 '25 20:11

Reto Koradi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!