diff options
| -rw-r--r-- | include/saffron_api.h | 5 | ||||
| -rw-r--r-- | include/saffron_window.h | 3 | ||||
| -rw-r--r-- | src/saffron_window.c | 12 |
3 files changed, 20 insertions, 0 deletions
diff --git a/include/saffron_api.h b/include/saffron_api.h index 964eaa9..99b4988 100644 --- a/include/saffron_api.h +++ b/include/saffron_api.h @@ -7,8 +7,11 @@ #include "saffron_text.h" #include "saffron_button.h" #include <SDL3/SDL_render.h> +#include <SDL3/SDL_video.h> #include <SDL3_ttf/SDL_ttf.h> #include <SDL3/SDL_pixels.h> +#include <SDL3/SDL_egl.h> +#include <SDL3/SDL_opengles2.h> bool saffron_init(void); void saffron_quit(void); @@ -42,4 +45,6 @@ void saffron_widget_set_theme(SaffronWidget* widget, SaffronTheme* theme); */ void saffron_hook_sdl_all_events(SaffronWindow* window, bool (*callback)(SDL_Event* event), int priority); +SDL_GLContext saffron_window_get_gl_context(SaffronWindow* window); + #endif diff --git a/include/saffron_window.h b/include/saffron_window.h index 89bf684..1552814 100644 --- a/include/saffron_window.h +++ b/include/saffron_window.h @@ -2,6 +2,8 @@ #define SAFFRON_WINDOW_H #include <SDL3/SDL.h> +#include <SDL3/SDL_egl.h> +#include <SDL3/SDL_opengles2.h> #include "saffron_event_hooks.h" #include "saffron_widget.h" @@ -13,6 +15,7 @@ typedef struct { const char* title; SfInternalEventHook hooks[32]; int hook_count; + SDL_GLContext gl_context; } SaffronWindow; #endif diff --git a/src/saffron_window.c b/src/saffron_window.c index 6c89c50..a909bc3 100644 --- a/src/saffron_window.c +++ b/src/saffron_window.c @@ -21,19 +21,30 @@ SaffronWindow* saffron_window_new(const char* title, int w, int h) { Uint32 flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_OPENGL; window->sdl_window = SDL_CreateWindow(title, w, h, flags); + + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles2"); window->renderer = SDL_CreateRenderer(window->sdl_window, NULL); + + window->gl_context = SDL_GL_CreateContext(window->sdl_window); + SDL_GL_MakeCurrent(window->sdl_window, window->gl_context); + window->root->theme = SF_MACRO_DEFAULT_THEME; return window; } void saffron_window_free(SaffronWindow* window) { + SDL_GL_DestroyContext(window->gl_context); SDL_DestroyRenderer(window->renderer); SDL_DestroyWindow(window->sdl_window); saffron_widget_free(window->root); free(window); } +SDL_GLContext saffron_window_get_gl_context(SaffronWindow* window) { + return window->gl_context; +} + static void handle_mouse_down(SDL_Event* event, SaffronWindow* window) { if (event->type != SDL_EVENT_MOUSE_BUTTON_DOWN) return; @@ -93,6 +104,7 @@ void saffron_window_main(SaffronWindow *window) { SDL_SetRenderDrawColor(window->renderer, 0, 0, 0, 255); SDL_RenderClear(window->renderer); + SDL_GL_MakeCurrent(window->sdl_window, window->gl_context); // just in case! saffron_widget_draw(window->root, window->renderer); SDL_RenderPresent(window->renderer); |
