The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
1 renderer over mutlple cpp's
luca00555


Joined: 04 Jan 2015
Posts: 33
Location: The Netherlands
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?
Re: 1 renderer over mutlple cpp's
Alex


Joined: 19 Sep 2014
Posts: 35
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.
luca00555


Joined: 04 Jan 2015
Posts: 33
Location: The Netherlands
C++ says it's too much information to pass on, could you make an example code for me?
luca00555


Joined: 04 Jan 2015
Posts: 33
Location: The Netherlands
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.
Thanks!