OpenGL framebuffers and lower resolutions
As always, OpenGL is really obvious once you figure it out. I've mentioned one before, and today I stumbled into another problem that just seemed so weird but so blatantly dumb when I found the solution.
While implementing a framebuffer object to give my upcoming sprite library some handy resolution options, all my projections got thrown off when I made the framebuffer smaller than the window. The basic setup is to render all sprites to the framebuffer first and then resize it to the requested pixel size in to the window. Resolutions still smaller than the window would feature a nice black border to leave the pixels at the desired size. But when I tried the smaller resolutions, the origo was thrown off and the pixel changed to non-specified sizes! The smaller I made it, the bigger the pixels and farther the origo went.
I figured it had something to do with my projection matrix, which was simply orthogonal to fit the pixels of the framebuffer. Well, no luck there, and a good bit of experimenting was done before that conclusion.
Finally, I came to realize, that the width of the smaller frame buffer isn't scaled properly via the viewport! The projection is suppose to normalize the values to the ranges -1 to 1 in both x and y-axis, and then the viewport translates it into pixel positions. So by re-sizing the framebuffer, without updating the viewport, the origo and scale of everything drawn was skewed to the lower left corner!
So the solution was simple enough! Use the glViewport to specify the size of the buffer you're rendering to, each time you switch! If you happen to use two render buffers of different sizes, you better keep track of this to not get damn confused about what's going on with your projections.
It was less obvious at first, since the glViewport is, atleast it was in my mind, considered as a one time setup when you fix your context at the start of your application.









