Search code examples
c++opengl3dsdl-2opengl-3

How to render opengl 3.3 into an SDL2 Texture?


I have been making 2D games with SDL2 for a while now and I decided recently to do 3D games using opengl 3.3 .

Since I have much c++ code made with pure SDL2 that I could reuse in that engine, I wondered, how could I manage to make opengl render to an SDL_Texture ?

The idea is to do stuff in 3D with opengl, put it into an SDL_Texture, and then do stuff in 2D and render it with SDL2.


Solution

  • Render to a FBO, use a PBO to pull the pixels back to main memory, then upload the pixels to a SDL_Texture.

    That's not exactly a "fast path" though, you're probably better off doing everything with OpenGL.