dwnste/imgui_sdl_osx

Improvement - SDL2 from CS:GO

aKalisch opened this issue · 2 comments

As you currently link the SDL2.framework to the dylib statically it doesn't seem to be the best approach since you already have the libsdl2-2.0.0.dylib loaded through CS:GO.

For compiling the headers you could simply install SDL2 through brew:
brew install sdl2

Afterwards you can implement the SDL calls to your code like this:

#include <SDL2/SDL.h>

// ...
DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window* window, int* w, int* h) {
    typedef void(*currFn) (SDL_Window*, int*, int*);
    static currFn SDL_GetWindowSizeFn = reinterpret_cast<currFn>(dlsym(RTLD_DEFAULT, "SDL_GetWindowSize"));
    
    return SDL_GetWindowSizeFn(window, w, h);
}
// ...
DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_Window* window, SDL_GLContext context) {
    typedef int(*currFn) (SDL_Window*, SDL_GLContext);
    static currFn SDL_GL_MakeCurrentFn = reinterpret_cast<currFn>(dlsym(RTLD_DEFAULT, "SDL_GL_MakeCurrent"));
    
    return SDL_GL_MakeCurrentFn(window, context);
}
// ...

The good thing about this:

  • You don't need to change the imgui_impl_sdl.* to your implemented calls
  • You don't need a third-party library/class to get your hooks
  • You can share your library to others without having them installed SDL2

It's a very good find. Can you maybe make a pulll request?

OK, I've updated everything.