1 renderer over mutlple cpp's

luca00555 wrote:

I’ve been trying really hard but I can’t seem to find a sollution.
I want to initialize SDL in another cpp than the cpp where the drawing is done, how can I create a renderer in for say gfxinit.cpp and pass it on to gfxmain.cpp?

This is not a problem. When you create renderer you got a rendering context variable (a pointer to SDL_Renderer). If you want to use this context in other c/cpp files declare it as a global var or a field of a global structure with “extern” specifier. You can create a header file and declare your rendering context var in this header (something like: extern SDL_Renderer* your_renderer;). Then include this header file to your c/cpp files where you want to use this renderer.

Nice, it’s finally working. What I did wrong was, I had my coordinating system in a cpp, the engine in another cpp and the drawing in another cpp, but forgot to include “SDL.h” in the coordinating system cpp. This caused my .h file with the extern SDL_Renderer* your_renderer; line to think SDL_Renderer is not a valid arguement.