Howdy folks,
I’m pretty new to the GL family, but I’ve got a game up and running with GLES 2 inside an SDL2 window. I’m pretty familiar with SDL, but I’m having a bit of trouble with scaling resolution.
I know that I could just watch for window events, destroy and recreate the GL context, and call it a day. But I want to maintain a particular internal resolution (for retro pixely vibes). I’ve worked with SDL textures and renderers before, so my mind immediately went to copying the GL buffer to an SDL texture, then stretching the texture via the renderer, ez pz.
I’ve done a bit of digging, but haven’t found examples of what exactly I’m looking for. At my current stage of research, it looks like I’ll need to:
- Either generate a new FBO and texture, or bind to the one created by SDL(???)
- Draw stuff
- glReadPixels, into a uint8 buffer (sizeof(char) * pb_w * pb_h * 4)
- copy ^this buffer to the SDL_Texture
- SDL_SetRenderTarget/SDL_RenderCopy/SDL_RenderPresent
But so far, I can’t even seem to get expected results at step 3. Despite rendering a red triangle on a black background, it seems I’m just reading exclusively black pixels.
Source here: sdl2-gles2-tri.c · GitHub
Any suggestions welcome, doesn’t have to be FBO → Texture → Renderer, just looking for any tips on how to set a static resolution for GL and stretch it with the SDL window.
Thanks!
– Ben