Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL3 support #760

Open
trexxet opened this issue Jan 4, 2025 · 3 comments
Open

SDL3 support #760

trexxet opened this issue Jan 4, 2025 · 3 comments

Comments

@trexxet
Copy link

trexxet commented Jan 4, 2025

Shouldn't be hard, just a few patches to nuklear_sdl_gl3.h

Here's my working solution using CMake:

file(READ ${NUKLEAR_PREFIX_INCLUDE}/nuklear_sdl_gl3.h SDL_FILE_CONTENTS)
string(REPLACE "SDL2" "SDL3" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_GetTicks64" "SDL_GetTicks" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_GL_GetDrawableSize" "SDL_GetWindowSizeInPixels" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_TRUE" "true" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_FALSE" "false" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_KEYUP" "SDL_EVENT_KEY_UP" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_KEYDOWN" "SDL_EVENT_KEY_DOWN" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_MOUSEBUTTONUP" "SDL_EVENT_MOUSE_BUTTON_UP" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_MOUSEBUTTONDOWN" "SDL_EVENT_MOUSE_BUTTON_DOWN" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_MOUSEMOTION" "SDL_EVENT_MOUSE_MOTION" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_MOUSEWHEEL" "SDL_EVENT_MOUSE_WHEEL" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_TEXTINPUT" "SDL_EVENT_TEXT_INPUT" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDLK_b" "SDLK_B" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDLK_c" "SDLK_C" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDLK_e" "SDLK_E" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDLK_r" "SDLK_R" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDLK_v" "SDLK_V" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDLK_x" "SDLK_X" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDLK_z" "SDLK_Z" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "const Uint8* state = SDL_GetKeyboardState(0);" "const _Bool* state = SDL_GetKeyboardState(0);" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "SDL_SetRelativeMouseMode(" "SDL_SetWindowRelativeMouseMode(sdl.win, " SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
string(REPLACE "switch(evt->key.keysym.sym)" "switch(evt->key.key)" SDL_FILE_CONTENTS "${SDL_FILE_CONTENTS}")
file(WRITE ${NUKLEAR_PREFIX_INCLUDE}/nuklear_sdl_gl3.h "${SDL_FILE_CONTENTS}")

Also, please, add the extern "C" wrap to nuklear_sdl_gl3.h

@RobLoach
Copy link
Contributor

RobLoach commented Jan 5, 2025

Would love for either SDL_GPU or SDL_renderer implementation so it would work across different graphics platforms.

Two attempts that I know of...

  1. lessthan3 started up a port of the sdl3_gl2 demos: Added demo updated for SDL3 #719
  2. I've opened up a sdl3 branch with some initial attempts too

@trexxet
Copy link
Author

trexxet commented Jan 6, 2025

Oh, should have searched for PRs - I have checked issues only.
Anyway, this patch may be useful for anyone trying to use SDL3 before official support.

@trexxet trexxet closed this as completed Jan 6, 2025
@RobLoach RobLoach reopened this Jan 7, 2025
@RobLoach
Copy link
Contributor

RobLoach commented Jan 7, 2025

Still worth to keep the issue open. Good to have a tracking thread, thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants