Merge pull request #1406 from DrinkyBird/sdl-gl-attributes

SDL: Set GL attributes before creating the window
This commit is contained in:
UnknownShadow200 2025-07-31 07:40:18 +10:00 committed by GitHub
commit 8b11e8b5c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View File

@ -38,6 +38,8 @@ typedef struct _WINDATA {
#endif #endif
static void SetGLAttributes();
static void RefreshWindowBounds(void) { static void RefreshWindowBounds(void) {
SDL_GetWindowSize(win_handle, &Window_Main.Width, &Window_Main.Height); SDL_GetWindowSize(win_handle, &Window_Main.Width, &Window_Main.Height);
} }
@ -99,7 +101,10 @@ static void DoCreateWindow(int width, int height, int flags) {
void Window_Create2D(int width, int height) { DoCreateWindow(width, height, 0); } void Window_Create2D(int width, int height) { DoCreateWindow(width, height, 0); }
#if CC_GFX_BACKEND_IS_GL() #if CC_GFX_BACKEND_IS_GL()
void Window_Create3D(int width, int height) { DoCreateWindow(width, height, SDL_WINDOW_OPENGL); } void Window_Create3D(int width, int height) {
SetGLAttributes();
DoCreateWindow(width, height, SDL_WINDOW_OPENGL);
}
#else #else
void Window_Create3D(int width, int height) { DoCreateWindow(width, height, 0); } void Window_Create3D(int width, int height) { DoCreateWindow(width, height, 0); }
#endif #endif
@ -537,7 +542,7 @@ void Gamepads_Process(float delta) {
#if CC_GFX_BACKEND_IS_GL() #if CC_GFX_BACKEND_IS_GL()
static SDL_GLContext win_ctx; static SDL_GLContext win_ctx;
void GLContext_Create(void) { void SetGLAttributes(void) {
struct GraphicsMode mode; struct GraphicsMode mode;
InitGraphicsMode(&mode); InitGraphicsMode(&mode);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, mode.R); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, mode.R);
@ -553,7 +558,9 @@ void GLContext_Create(void) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif #endif
}
void GLContext_Create(void) {
win_ctx = SDL_GL_CreateContext(win_handle); win_ctx = SDL_GL_CreateContext(win_handle);
if (!win_ctx) Window_SDLFail("creating OpenGL context"); if (!win_ctx) Window_SDLFail("creating OpenGL context");
} }

View File

@ -11,6 +11,8 @@
static SDL_Window* win_handle; static SDL_Window* win_handle;
static Uint32 dlg_event; static Uint32 dlg_event;
static void SetGLAttributes();
static void RefreshWindowBounds(void) { static void RefreshWindowBounds(void) {
SDL_GetWindowSize(win_handle, &Window_Main.Width, &Window_Main.Height); SDL_GetWindowSize(win_handle, &Window_Main.Width, &Window_Main.Height);
} }
@ -84,7 +86,10 @@ static void DoCreateWindow(int width, int height, int flags) {
void Window_Create2D(int width, int height) { DoCreateWindow(width, height, 0); } void Window_Create2D(int width, int height) { DoCreateWindow(width, height, 0); }
#if CC_GFX_BACKEND_IS_GL() #if CC_GFX_BACKEND_IS_GL()
void Window_Create3D(int width, int height) { DoCreateWindow(width, height, SDL_WINDOW_OPENGL); } void Window_Create3D(int width, int height) {
SetGLAttributes();
DoCreateWindow(width, height, SDL_WINDOW_OPENGL);
}
#else #else
void Window_Create3D(int width, int height) { DoCreateWindow(width, height, 0); } void Window_Create3D(int width, int height) { DoCreateWindow(width, height, 0); }
#endif #endif
@ -567,7 +572,7 @@ void Gamepads_Process(float delta) {
#if CC_GFX_BACKEND_IS_GL() #if CC_GFX_BACKEND_IS_GL()
static SDL_GLContext win_ctx; static SDL_GLContext win_ctx;
void GLContext_Create(void) { void SetGLAttributes(void) {
struct GraphicsMode mode; struct GraphicsMode mode;
InitGraphicsMode(&mode); InitGraphicsMode(&mode);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, mode.R); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, mode.R);
@ -583,7 +588,9 @@ void GLContext_Create(void) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif #endif
}
void GLContext_Create(void) {
win_ctx = SDL_GL_CreateContext(win_handle); win_ctx = SDL_GL_CreateContext(win_handle);
if (!win_ctx) Window_SDLFail("creating OpenGL context"); if (!win_ctx) Window_SDLFail("creating OpenGL context");
} }