# sdl2-compat: render: SDL\_CreateWindowAndRenderer updated for latest SDL3.

**URL:** <https://discourse.libsdl.org/t/sdl2-compat-render-sdl-createwindowandrenderer-updated-for-latest-sdl3/50718>\
**Category:** SDL Commits\
**Created:** [April 26, 2024, 5:16am UTC](https://discourse.libsdl.org/t/sdl2-compat-render-sdl-createwindowandrenderer-updated-for-latest-sdl3/50718 "2024-04-26T05:16:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [April 26, 2024, 5:16am UTC](https://discourse.libsdl.org/t/sdl2-compat-render-sdl-createwindowandrenderer-updated-for-latest-sdl3/50718/1 "2024-04-26T05:16:03Z")

</div>

> <https://github.com/libsdl-org/sdl2-compat/commit/77ccc859c3e5d1855d0ade3e5fc13e8316368ccd>
>
> This just implements the simple SDL2 function instead of calling the SDL3
> equiva…lent, because we want to use the SDL2 wrappers for SDL\_CreateWindow
> and SDL\_CreateRenderer, etc.

```diff
From 77ccc859c3e5d1855d0ade3e5fc13e8316368ccd Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 26 Apr 2024 01:14:06 -0400
Subject: [PATCH] render: SDL_CreateWindowAndRenderer updated for latest SDL3.

This just implements the simple SDL2 function instead of calling the SDL3
equivalent, because we want to use the SDL2 wrappers for SDL_CreateWindow
and SDL_CreateRenderer, etc.
---
 src/sdl2_compat.c | 24 ++++++++++++++++++++++++
 src/sdl3_syms.h | 2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 7936ef1..6a40063 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -6285,6 +6285,30 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
     return window;
 }
 
+DECLSPEC int SDLCALL
+SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags,
+ SDL_Window **window, SDL_Renderer** renderer)
+{
+ // This function's code is exactly what SDL2 does (including not checking that `window` and `renderer` aren't NULL),
+ // but we want to make sure these go through the sdl2-compat CreateWindow and CreateRenderer functions
+ // to do some compatibility magic, instead of just calling the SDL3 equivalent of this function.
+
+ *window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED,
+ SDL_WINDOWPOS_UNDEFINED,
+ width, height, window_flags);
+ if (!*window) {
+ *renderer = NULL;
+ return -1;
+ }
+
+ *renderer = SDL_CreateRenderer(*window, -1, 0);
+ if (!*renderer) {
+ return -1;
+ }
+
+ return 0;
+}
+
 DECLSPEC SDL_Window * SDLCALL
 SDL_CreateWindowFrom(const void *data)
 {
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 68e9ebf..1b3c4ee 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -301,7 +301,7 @@ SDL3_SYM_RENAMED(SDL_bool,EnclosePoints,GetRectEnclosingPoints,(const SDL_Point
 SDL3_SYM_RENAMED(SDL_bool,IntersectRectAndLine,GetRectAndLineIntersection,(const SDL_Rect *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
 SDL3_SYM_PASSTHROUGH(int,GetNumRenderDrivers,(void),(),return)
 SDL3_SYM(const char *,GetRenderDriver,(int a),(a),return);
-SDL3_SYM_PASSTHROUGH(int,CreateWindowAndRenderer,(int a, int b, Uint32 c, SDL_Window **d, SDL_Renderer** e),(a,b,c,d,e),return)
+SDL3_SYM(int,CreateWindowAndRenderer,(const char *a, int b, int c, Uint32 d, SDL_Window **e, SDL_Renderer** f),(a,b,c,d,e,f),return)
 SDL3_SYM(SDL_Renderer*,CreateRenderer,(SDL_Window *a, const char *b, Uint32 c),(a,b,c),return)
 SDL3_SYM_PASSTHROUGH(SDL_Renderer*,CreateSoftwareRenderer,(SDL_Surface *a),(a),return)
 SDL3_SYM_PASSTHROUGH(SDL_Renderer*,GetRenderer,(SDL_Window *a),(a),return)

```
