May 7, 2017
A while ago, I talked about issues with pixel art scaling in game development. At the time, I did not want to work with OpenGL shaders. OpenGL is not an easy-to-approach library. However, I bit the bullet and learned how to use them.
Since April 2016, I have been working on a new game project in my spare time. This project is written in Rust, and uses a library called SDL2 (Rust bindings for a C library of the same name) for the graphics and user input and stuff. But I got to the point where I wanted to get good pixel art scaling to work at any resolution (better than what I had for Weaponless), so I needed to write an OpenGL shader and use the OpenGL methods directly. An OpenGL shader is also necessary to do something like make an enemy flash when hit.
I learned that writing a shader isn't just about writing a shader. You also need to write code that generates proper input for the shader. The pixel art shader that I designed is intended to approximate an oversampled nearest interpolation with anti-aliasing. Another issue occurs when I want to tile images together. In order to get the transitions between tiles to look smooth, I need to render to a temporary back-buffer using simple nearest sampling and then render that back-buffer to the screen using my pixel shader.
It was tricky to learn, but I am pleased with the improved graphics and effects. I think once this code is a little more mature, I will Open-Source this part of it, so that others could use it directly or use it as an example.
UPDATE: this source code is now available as part of Gate. More details can be found here.