github.com/gotranspile/cxgo@v0.3.7/libs/sdl2.go (about)

     1  package libs
     2  
     3  import (
     4  	"github.com/gotranspile/cxgo/types"
     5  )
     6  
     7  const (
     8  	sdl2H          = "SDL2/SDL.h"
     9  	sdl2OpenGLH    = "SDL2/SDL_opengl.h"
    10  	sdl2OpenGLExtH = "SDL2/SDL_opengl_glext.h"
    11  	sdl2StdIncH    = "SDL2/SDL_stdinc.h"
    12  )
    13  
    14  func init() {
    15  	RegisterLibrary(sdl2H, func(c *Env) *Library {
    16  		boolT := types.BoolT()
    17  		sintT := types.IntT(4)
    18  		uintT := types.UintT(4)
    19  		sint16T := types.IntT(2)
    20  		uint16T := types.UintT(2)
    21  		uint8T := types.UintT(1)
    22  		strT := c.C().String()
    23  		bufT := c.PtrT(nil)
    24  		scanT := types.NamedT("sdl.Scancode", sintT)
    25  		blendT := types.NamedTGo("SDL_BlendMode", "sdl.BlendMode", sintT)
    26  		timerT := types.NamedTGo("SDL_TimerID", "sdl.TimerID", sintT)
    27  		keymodT := types.NamedTGo("SDL_Keymod", "sdl.Keymod", sintT)
    28  		fingerT := types.NamedTGo("SDL_FingerID", "sdl.FingerID", sintT)
    29  		rectT := types.NamedT("sdl.Rect", types.StructT([]*types.Field{
    30  			{Name: types.NewIdentGo("x", "X", sint16T)},
    31  			{Name: types.NewIdentGo("y", "Y", sint16T)},
    32  			{Name: types.NewIdentGo("w", "W", uint16T)},
    33  			{Name: types.NewIdentGo("h", "H", uint16T)},
    34  		}))
    35  		muT := types.NamedT("sdl.Mutex", c.MethStructT(map[string]*types.FuncType{
    36  			"Lock":    c.FuncTT(nil),
    37  			"Unlock":  c.FuncTT(nil),
    38  			"Destroy": c.FuncTT(nil),
    39  		}))
    40  		ksymT := types.NamedT("sdl.Keysym", types.StructT([]*types.Field{
    41  			{Name: types.NewIdentGo("scancode", "Scancode", scanT)},
    42  		}))
    43  		evkeybT := types.NamedT("sdl.KeyboardEvent", types.StructT([]*types.Field{
    44  			{Name: types.NewIdentGo("keysym", "Keysym", ksymT)},
    45  			{Name: types.NewIdentGo("state", "Env", uint8T)},
    46  		}))
    47  		evwinT := types.NamedT("sdl.WindowEvent", types.StructT([]*types.Field{
    48  			{Name: types.NewIdentGo("event", "Event", uint8T)},
    49  		}))
    50  		evmbT := types.NamedT("sdl.MouseButtonEvent", types.StructT([]*types.Field{
    51  			{Name: types.NewIdentGo("button", "Button", uint8T)},
    52  			{Name: types.NewIdentGo("state", "Env", uint8T)},
    53  			{Name: types.NewIdentGo("x", "X", sintT)},
    54  			{Name: types.NewIdentGo("y", "Y", sintT)},
    55  		}))
    56  		evmmT := types.NamedT("sdl.MouseMotionEvent", types.StructT([]*types.Field{
    57  			{Name: types.NewIdentGo("x", "X", sintT)},
    58  			{Name: types.NewIdentGo("y", "Y", sintT)},
    59  			{Name: types.NewIdentGo("xrel", "Xrel", sintT)},
    60  			{Name: types.NewIdentGo("yrel", "Yrel", sintT)},
    61  		}))
    62  		evmwT := types.NamedT("sdl.MouseWheelEvent", types.StructT([]*types.Field{
    63  			{Name: types.NewIdentGo("x", "X", sintT)},
    64  			{Name: types.NewIdentGo("y", "Y", sintT)},
    65  		}))
    66  		textT := c.C().BytesN(32)
    67  		evtxtT := types.NamedT("sdl.TextInputEvent", types.StructT([]*types.Field{
    68  			{Name: types.NewIdentGo("text", "Text", textT)},
    69  		}))
    70  		evtxteT := types.NamedT("sdl.TextEditingEvent", types.StructT([]*types.Field{
    71  			{Name: types.NewIdentGo("text", "Text", textT)},
    72  		}))
    73  		surfaceT := types.NamedTGo("SDL_Surface", "sdl.Surface", types.StructT([]*types.Field{
    74  			{Name: types.NewIdentGo("w", "W", sintT)},
    75  			{Name: types.NewIdentGo("h", "H", sintT)},
    76  			{Name: types.NewIdentGo("pitch", "Pitch", sintT)},
    77  			{Name: types.NewIdentGo("pixels", "Pixels", bufT)},
    78  			{Name: types.NewIdentGo("clip_rect", "ClipRect", rectT)},
    79  			{Name: types.NewIdent("Lock", c.FuncTT(sintT))},
    80  			{Name: types.NewIdent("Unlock", c.FuncTT(nil))},
    81  			{Name: types.NewIdent("Free", c.FuncTT(nil))},
    82  			{Name: types.NewIdent("SetColorKey", c.FuncTT(sintT, sintT, uintT))},
    83  			{Name: types.NewIdent("GetClipRect", c.FuncTT(nil, c.PtrT(rectT)))},
    84  			{Name: types.NewIdent("SetBlendMode", c.FuncTT(sintT, blendT))},
    85  		}))
    86  		textureT := types.NamedTGo("SDL_Texture", "sdl.Texture", c.MethStructT(map[string]*types.FuncType{
    87  			"Destroy": c.FuncTT(nil),
    88  		}))
    89  		evT := types.NamedT("sdl.Event", types.StructT([]*types.Field{
    90  			{Name: types.NewIdentGo("type", "Type", sintT)},
    91  			{Name: types.NewIdentGo("edit", "Edit", evtxteT)},
    92  			{Name: types.NewIdentGo("text", "Text", evtxtT)},
    93  			{Name: types.NewIdentGo("key", "Key", evkeybT)},
    94  			{Name: types.NewIdentGo("button", "Button", evmbT)},
    95  			{Name: types.NewIdentGo("motion", "Motion", evmmT)},
    96  			{Name: types.NewIdentGo("wheel", "Wheel", evmwT)},
    97  			{Name: types.NewIdentGo("window", "Window", evwinT)},
    98  		}))
    99  		glCtxT := types.NamedTGo("SDL_GLContext", "sdl.GLContext", types.StructT(nil))
   100  		winT := types.NamedT("sdl.Window", c.MethStructT(map[string]*types.FuncType{
   101  			"SetFullscreen":     c.FuncTT(sintT, uintT),
   102  			"GetSize":           c.FuncTT(nil, c.PtrT(sintT), c.PtrT(sintT)),
   103  			"GetPosition":       c.FuncTT(nil, c.PtrT(sintT), c.PtrT(sintT)),
   104  			"SetSize":           c.FuncTT(nil, sintT, sintT),
   105  			"SetPosition":       c.FuncTT(nil, sintT, sintT),
   106  			"Minimize":          c.FuncTT(nil),
   107  			"Restore":           c.FuncTT(nil),
   108  			"SetGrab":           c.FuncTT(nil, boolT),
   109  			"SetResizable":      c.FuncTT(nil, boolT),
   110  			"SetBordered":       c.FuncTT(nil, boolT),
   111  			"SetTitle":          c.FuncTT(nil, strT),
   112  			"GetDisplayIndex":   c.FuncTT(sintT, strT),
   113  			"GLGetDrawableSize": c.FuncTT(nil, c.PtrT(sintT), c.PtrT(sintT)),
   114  			"GLSwap":            c.FuncTT(nil),
   115  			"GLCreateContext":   c.FuncTT(glCtxT),
   116  		}))
   117  		renderT := types.NamedTGo("SDL_Renderer", "sdl.Renderer", c.MethStructT(map[string]*types.FuncType{
   118  			"Present": c.FuncTT(nil),
   119  			"Destroy": c.FuncTT(nil),
   120  		}))
   121  		timerFuncT := types.NamedTGo("SDL_TimerCallback", "sdl.TimerFunc", c.FuncTT(uintT, uintT, c.PtrT(nil)))
   122  		return &Library{
   123  			Imports: map[string]string{
   124  				"sdl": RuntimeOrg + "/sdl",
   125  			},
   126  			Types: map[string]types.Type{
   127  				"SDL_Window":           winT,
   128  				"SDL_Renderer":         renderT,
   129  				"SDL_Scancode":         scanT,
   130  				"SDL_BlendMode":        blendT,
   131  				"SDL_Keymod":           keymodT,
   132  				"SDL_FingerID":         fingerT,
   133  				"SDL_TimerID":          timerT,
   134  				"SDL_Rect":             rectT,
   135  				"SDL_mutex":            muT,
   136  				"SDL_Keysym":           ksymT,
   137  				"SDL_KeyboardEvent":    evkeybT,
   138  				"SDL_WindowEvent":      evwinT,
   139  				"SDL_MouseButtonEvent": evmbT,
   140  				"SDL_MouseMotionEvent": evmmT,
   141  				"SDL_MouseWheelEvent":  evmwT,
   142  				"SDL_TextInputEvent":   evtxtT,
   143  				"SDL_TextEditingEvent": evtxteT,
   144  				"SDL_Event":            evT,
   145  				"SDL_Surface":          surfaceT,
   146  				"SDL_Texture":          textureT,
   147  				"SDL_GLContext":        glCtxT,
   148  				"SDL_TimerCallback":    timerFuncT,
   149  			},
   150  			Idents: map[string]*types.Ident{
   151  				"SDL_itoa":                       types.NewIdent("sdl.Itoa", c.FuncTT(strT, sintT, strT, sintT)),
   152  				"SDL_uitoa":                      types.NewIdent("sdl.Uitoa", c.FuncTT(strT, uintT, strT, sintT)),
   153  				"SDL_GetError":                   types.NewIdent("sdl.GetError", c.FuncTT(strT)),
   154  				"SDL_GetTicks":                   types.NewIdent("sdl.GetTicks", c.FuncTT(uintT)),
   155  				"SDL_PollEvent":                  types.NewIdent("sdl.PollEvent", c.FuncTT(sintT, c.PtrT(evT))),
   156  				"SDL_Delay":                      types.NewIdent("sdl.Delay", c.FuncTT(nil, uintT)),
   157  				"SDL_Init":                       types.NewIdent("sdl.Init", c.FuncTT(sintT, uintT)),
   158  				"SDL_CreateMutex":                types.NewIdent("sdl.CreateMutex", c.FuncTT(c.PtrT(muT))),
   159  				"SDL_CreateWindow":               types.NewIdent("sdl.CreateWindow", c.FuncTT(c.PtrT(winT), strT, sintT, sintT, sintT, sintT, uintT)),
   160  				"SDL_CreateRGBSurfaceWithFormat": types.NewIdentGo("SDL_CreateRGBSurfaceWithFormat", "sdl.CreateRGBSurfaceWithFormat", c.FuncTT(c.PtrT(surfaceT), uintT, sintT, sintT, sintT, uintT)),
   161  				"SDL_BlitSurface":                types.NewIdentGo("SDL_BlitSurface", "sdl.BlitSurface", c.FuncTT(sintT, c.PtrT(surfaceT), c.PtrT(rectT), c.PtrT(surfaceT), c.PtrT(rectT))),
   162  				"SDL_BlitScaled":                 types.NewIdentGo("SDL_BlitScaled", "sdl.BlitScaled", c.FuncTT(sintT, c.PtrT(surfaceT), c.PtrT(rectT), c.PtrT(surfaceT), c.PtrT(rectT))),
   163  				"SDL_AddTimer":                   types.NewIdentGo("SDL_AddTimer", "sdl.AddTimer", c.FuncTT(timerT, uintT, timerFuncT, c.PtrT(nil))),
   164  				"SDL_RemoveTimer":                types.NewIdentGo("SDL_RemoveTimer", "sdl.RemoveTimer", c.FuncTT(boolT, timerT)),
   165  				"SDL_GL_DeleteContext":           types.NewIdentGo("SDL_GL_DeleteContext", "sdl.GLDeleteContext", c.FuncTT(nil, glCtxT)),
   166  				"SDL_GL_SetSwapInterval":         types.NewIdentGo("SDL_GL_SetSwapInterval", "sdl.GLSetSwapInterval", c.FuncTT(sintT, sintT)),
   167  				"SDL_GetDisplayBounds":           types.NewIdentGo("SDL_GetDisplayBounds", "sdl.GetDisplayBounds", c.FuncTT(sintT, sintT, c.PtrT(rectT))),
   168  				"SDL_GetGlobalMouseState":        types.NewIdentGo("SDL_GetGlobalMouseState", "sdl.GetGlobalMouseState", c.FuncTT(uintT, c.PtrT(sintT), c.PtrT(sintT))),
   169  				"SDL_GetEventState":              types.NewIdentGo("SDL_GetEventState", "sdl.GetEventState", c.FuncTT(uint8T, uintT)),
   170  				"SDL_SetRelativeMouseMode":       types.NewIdentGo("SDL_SetRelativeMouseMode", "sdl.SetRelativeMouseMode", c.FuncTT(sintT, boolT)),
   171  				"SDL_GetModState":                types.NewIdentGo("SDL_GetModState", "sdl.GetModState", c.FuncTT(keymodT)),
   172  				"SDL_StartTextInput":             types.NewIdentGo("SDL_StartTextInput", "sdl.StartTextInput", c.FuncTT(nil)),
   173  				"SDL_StopTextInput":              types.NewIdentGo("SDL_StopTextInput", "sdl.StopTextInput", c.FuncTT(nil)),
   174  				"SDL_CreateRenderer":             types.NewIdentGo("SDL_CreateRenderer", "sdl.CreateRenderer", c.FuncTT(c.PtrT(renderT), c.PtrT(winT), sintT, uintT)),
   175  				"SDL_CreateTextureFromSurface":   types.NewIdentGo("SDL_CreateTextureFromSurface", "sdl.CreateTextureFromSurface", c.FuncTT(c.PtrT(textureT), c.PtrT(renderT), c.PtrT(surfaceT))),
   176  				"SDL_RenderCopy":                 types.NewIdentGo("SDL_RenderCopy", "sdl.RenderCopy", c.FuncTT(sintT, c.PtrT(renderT), c.PtrT(textureT), c.PtrT(rectT), c.PtrT(rectT))),
   177  
   178  				"SDL_BLENDMODE_NONE":            types.NewIdentGo("SDL_BLENDMODE_NONE", "sdl.BLENDMODE_NONE", blendT),
   179  				"SDL_PIXELFORMAT_RGBA5551":      types.NewIdentGo("SDL_PIXELFORMAT_RGBA5551", "sdl.PIXELFORMAT_RGBA5551", sintT),
   180  				"SDL_PIXELFORMAT_RGB565":        types.NewIdentGo("SDL_PIXELFORMAT_RGB565", "sdl.PIXELFORMAT_RGB565", sintT),
   181  				"SDL_PIXELFORMAT_RGB555":        types.NewIdentGo("SDL_PIXELFORMAT_RGB555", "sdl.PIXELFORMAT_RGB555", sintT),
   182  				"SDL_RENDERER_ACCELERATED":      types.NewIdentGo("SDL_RENDERER_ACCELERATED", "sdl.RENDERER_ACCELERATED", sintT),
   183  				"SDL_RENDERER_PRESENTVSYNC":     types.NewIdentGo("SDL_RENDERER_PRESENTVSYNC", "sdl.RENDERER_PRESENTVSYNC", sintT),
   184  				"SDL_NUM_SCANCODES":             types.NewIdentGo("SDL_NUM_SCANCODES", "sdl.NUM_SCANCODES", sintT),
   185  				"SDL_PRESSED":                   types.NewIdentGo("SDL_PRESSED", "sdl.PRESSED", sintT),
   186  				"SDL_SCANCODE_SPACE":            types.NewIdentGo("SDL_SCANCODE_SPACE", "sdl.SCANCODE_SPACE", sintT),
   187  				"KMOD_LSHIFT":                   types.NewIdentGo("KMOD_LSHIFT", "sdl.KMOD_LSHIFT", sintT),
   188  				"KMOD_RSHIFT":                   types.NewIdentGo("KMOD_RSHIFT", "sdl.KMOD_RSHIFT", sintT),
   189  				"KMOD_RALT":                     types.NewIdentGo("KMOD_RALT", "sdl.KMOD_RALT", sintT),
   190  				"SDL_INIT_VIDEO":                types.NewIdent("sdl.INIT_VIDEO", uintT),
   191  				"SDL_INIT_TIMER":                types.NewIdent("sdl.INIT_TIMER", uintT),
   192  				"SDL_WINDOWPOS_UNDEFINED":       types.NewIdent("sdl.WINDOWPOS_UNDEFINED", sintT),
   193  				"SDL_WINDOWPOS_CENTERED":        types.NewIdent("sdl.WINDOWPOS_CENTERED", sintT),
   194  				"SDL_WINDOW_RESIZABLE":          types.NewIdent("sdl.WINDOW_RESIZABLE", uintT),
   195  				"SDL_WINDOW_OPENGL":             types.NewIdent("sdl.WINDOW_OPENGL", uintT),
   196  				"SDL_WINDOW_FULLSCREEN_DESKTOP": types.NewIdent("sdl.WINDOW_FULLSCREEN_DESKTOP", uintT),
   197  			},
   198  			// TODO
   199  			Header: `
   200  #include <` + BuiltinH + `>
   201  
   202  #define Uint32 _cxgo_uint32
   203  #define Uint16 _cxgo_uint16
   204  #define Uint8 _cxgo_uint8
   205  #define Sint32 _cxgo_sint32
   206  #define Sint16 _cxgo_sint16
   207  #define Sint8 _cxgo_sint8
   208  #define SDL_bool _cxgo_go_bool
   209  typedef Sint32 SDL_FingerID;
   210  typedef Sint32 SDL_Scancode;
   211  typedef Sint32 SDL_Keymod;
   212  typedef Sint32 SDL_BlendMode;
   213  typedef Sint32 SDL_TimerID;
   214  
   215  
   216  #define SDL_TRUE 1
   217  #define SDL_FALSE 0
   218  const Sint32 SDL_PIXELFORMAT_RGBA5551 = 1;
   219  const Sint32 SDL_PIXELFORMAT_RGB565 = 2;
   220  const Sint32 SDL_PIXELFORMAT_RGB555 = 3;
   221  
   222  const Sint32 SDL_RENDERER_ACCELERATED = 1;
   223  const Sint32 SDL_RENDERER_PRESENTVSYNC = 2;
   224  
   225  #define SDL_NUM_SCANCODES 512
   226  
   227  typedef struct{
   228    Sint16 x, y;
   229    Uint16 w, h;
   230  } SDL_Rect;
   231  
   232  #define SDL_TEXTEDITING 770
   233  #define SDL_TEXTINPUT 771
   234  #define SDL_KEYDOWN 768
   235  #define SDL_KEYUP 769
   236  #define SDL_MOUSEBUTTONDOWN 1025
   237  #define SDL_MOUSEBUTTONUP 1026
   238  #define SDL_MOUSEMOTION 1024
   239  #define SDL_MOUSEWHEEL 1027
   240  #define SDL_WINDOWEVENT 512
   241  
   242  #define SDL_WINDOWEVENT_FOCUS_LOST 13
   243  #define SDL_WINDOWEVENT_FOCUS_GAINED 12
   244  
   245  #define SDL_BUTTON_LEFT 1
   246  #define SDL_BUTTON_RIGHT 3
   247  #define SDL_BUTTON_MIDDLE 2
   248  
   249  const Sint32 SDL_PRESSED = 1;
   250  
   251  const Sint32 SDL_SCANCODE_SPACE = 1;
   252  const Sint32 KMOD_LSHIFT = 1;
   253  const Sint32 KMOD_RSHIFT = 2;
   254  const Sint32 KMOD_RALT = 3;
   255  
   256  const Uint32 SDL_INIT_VIDEO = 1;
   257  const Uint32 SDL_INIT_TIMER = 2;
   258  const Sint32 SDL_WINDOWPOS_UNDEFINED = -1;
   259  const Sint32 SDL_WINDOWPOS_CENTERED = -2;
   260  const Uint32 SDL_WINDOW_RESIZABLE = 1;
   261  const Uint32 SDL_WINDOW_OPENGL = 2;
   262  const SDL_BlendMode SDL_BLENDMODE_NONE = 1;
   263  
   264  typedef struct{
   265      SDL_Scancode scancode;
   266  } SDL_Keysym;
   267  
   268  typedef struct{
   269      SDL_Keysym keysym;
   270      Uint8 state;
   271  } SDL_KeyboardEvent;
   272  
   273  typedef struct{
   274      Uint8 button;
   275      Uint8 state;
   276      Sint32 x,y;
   277  } SDL_MouseButtonEvent;
   278  
   279  typedef struct{
   280      Sint32 x, y;
   281      Sint32 xrel, yrel;
   282  } SDL_MouseMotionEvent;
   283  
   284  typedef struct{
   285      Sint32 x, y;
   286  } SDL_MouseWheelEvent;
   287  
   288  typedef struct{} SDL_TouchFingerEvent;
   289  
   290  typedef struct{
   291      char text[32];
   292  } SDL_TextEditingEvent;
   293  
   294  typedef struct{
   295      char text[32];
   296  } SDL_TextInputEvent;
   297  
   298  typedef struct{
   299      Uint8 event;
   300  } SDL_WindowEvent;
   301  
   302  typedef struct{
   303      int type;
   304      SDL_TextEditingEvent edit;
   305      SDL_TextInputEvent text;
   306      SDL_KeyboardEvent key;
   307      SDL_MouseButtonEvent button;
   308      SDL_MouseMotionEvent motion;
   309      SDL_MouseWheelEvent wheel;
   310      SDL_WindowEvent window;
   311  } SDL_Event;
   312  
   313  const Uint32 SDL_WINDOW_FULLSCREEN_DESKTOP = 0;
   314  
   315  typedef struct SDL_GLContext {} SDL_GLContext;
   316  
   317  typedef struct SDL_Window {
   318  	Sint32 (*SetFullscreen)(Uint32 flags);
   319  	void (*GetSize)(Sint32 *w, Sint32 *h);
   320  	void (*GetPosition)(Sint32 *x, Sint32 *y);
   321  	void (*SetSize)(Sint32 w, Sint32 h);
   322  	void (*SetPosition)(Sint32 x, Sint32 y);
   323  	void (*Minimize)(void);
   324  	void (*Restore)(void);
   325  	void (*SetGrab)(SDL_bool);
   326  	void (*SetResizable)(SDL_bool);
   327  	void (*SetBordered)(SDL_bool);
   328  	void (*SetTitle)(const char*);
   329  	Sint32 (*GetDisplayIndex)(void);
   330  	void (*GLGetDrawableSize)(Sint32* w, Sint32* h);
   331  	void (*GLSwapWindow)(void);
   332  	SDL_GLContext (*GLCreateContext)(void);
   333  } SDL_Window;
   334  
   335  const char* SDL_GetError(void);
   336  
   337  Uint32 SDL_GetTicks(void);
   338  SDL_Window* SDL_CreateWindow(const char* title, Sint32 x, Sint32 y, Sint32 w, Sint32 h, Uint32 flags);
   339  #define SDL_SetWindowFullscreen(win, flags) ((SDL_Window*)win)->SetFullscreen(flags)
   340  #define SDL_SetWindowSize(win, w, h) ((SDL_Window*)win)->SetSize(w, h)
   341  #define SDL_SetWindowPosition(win, x, y) ((SDL_Window*)win)->SetPosition(x, y)
   342  #define SDL_SetWindowGrab(win, v) ((SDL_Window*)win)->SetGrab(v)
   343  #define SDL_SetWindowTitle(win, v) ((SDL_Window*)win)->SetTitle(v)
   344  #define SDL_MinimizeWindow(win) ((SDL_Window*)win)->Minimize()
   345  #define SDL_RestoreWindow(win) ((SDL_Window*)win)->Restore()
   346  #define SDL_GetWindowDisplayIndex(win) ((SDL_Window*)win)->GetDisplayIndex()
   347  #define SDL_SetWindowResizable(win, v) ((SDL_Window*)win)->SetResizable(v)
   348  #define SDL_SetWindowBordered(win, v) ((SDL_Window*)win)->SetBordered(v)
   349  #define SDL_GetWindowPosition(win, x, y) ((SDL_Window*)win)->GetPosition(x, y)
   350  #define SDL_GetWindowSize(win, w, h) ((SDL_Window*)win)->GetSize(w, h)
   351  
   352  #define SDL_GL_GetDrawableSize(win, w, h) ((SDL_Window*)win)->GLGetDrawableSize(w, h)
   353  #define SDL_GL_SwapWindow(win) ((SDL_Window*)win)->GLSwap()
   354  #define SDL_GL_CreateContext(win) ((SDL_Window*)win)->GLCreateContext()
   355  
   356  typedef struct SDL_Renderer {
   357  	void (*Destroy)(void);
   358  	void (*Present)(void);
   359  } SDL_Renderer;
   360  
   361  SDL_Renderer* SDL_CreateRenderer(SDL_Window* window, Sint32 index, Uint32 flags);
   362  
   363  #define SDL_RenderPresent(r) ((SDL_Renderer*)r)->Present()
   364  #define SDL_DestroyRenderer(r) ((SDL_Renderer*)r)->Destroy()
   365  
   366  char *SDL_itoa(Sint32 value, char *str, Sint32 radix);
   367  char *SDL_uitoa(Uint32 value, char *str, Sint32 radix);
   368  void SDL_Delay(Uint32 ms);
   369  
   370  typedef struct SDL_mutex {
   371  	void (*Lock)(void);
   372  	void (*Unlock)(void);
   373  	void (*Destroy)(void);
   374  } SDL_mutex;
   375  
   376  SDL_mutex* SDL_CreateMutex(void);
   377  
   378  #define SDL_DestroyMutex(m) ((SDL_mutex*)m)->Destroy()
   379  #define SDL_LockMutex(m) ((SDL_mutex*)m)->Lock()
   380  #define SDL_UnlockMutex(m) ((SDL_mutex*)m)->Unlock()
   381  
   382  
   383  typedef struct SDL_Surface {
   384      Sint32 w, h;
   385      Sint32 pitch;
   386      void* pixels;
   387      SDL_Rect clip_rect;
   388  
   389  	Sint32 (*Lock)(void);
   390  	void (*Unlock)(void);
   391  	void (*Free)(void);
   392  	Sint32 (*SetColorKey)(Sint32 flag, Uint32 key);
   393  	void (*GetClipRect)(SDL_Rect* rect);
   394  	Sint32 (*SetBlendMode)(SDL_BlendMode blendMode);
   395  } SDL_Surface;
   396  
   397  SDL_Surface* SDL_CreateRGBSurfaceWithFormat(Uint32 flags, Sint32 width, Sint32 height, Sint32 depth, Uint32 format);
   398  
   399  #define SDL_LockSurface(s) ((SDL_Surface*)s)->Lock()
   400  #define SDL_UnlockSurface(s) ((SDL_Surface*)s)->Unlock()
   401  #define SDL_FreeSurface(s) ((SDL_Surface*)s)->Free()
   402  #define SDL_SetColorKey(s, f, k) ((SDL_Surface*)s)->SetColorKey(f, k)
   403  #define SDL_GetClipRect(s, r) ((SDL_Surface*)s)->GetClipRect(r)
   404  #define SDL_SetSurfaceBlendMode(s, m) ((SDL_Surface*)s)->SetBlendMode(m)
   405  Sint32 SDL_BlitSurface(SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect);
   406  Sint32 SDL_BlitScaled(SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect);
   407  
   408  typedef struct SDL_Texture {
   409  	void (*Destroy)(void);
   410  } SDL_Texture;
   411  SDL_Texture* SDL_CreateTextureFromSurface(SDL_Renderer* renderer, SDL_Surface*  surface);
   412  #define SDL_DestroyTexture(t) ((SDL_Texture*)t)->Destroy()
   413  
   414  Sint32 SDL_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect);
   415  
   416  
   417  Sint32 SDL_GL_SetSwapInterval(Sint32 interval);
   418  void SDL_GL_DeleteContext(SDL_GLContext context);
   419  Sint32 SDL_Init(Uint32 flags);
   420  Sint32 SDL_PollEvent(SDL_Event* event);
   421  void SDL_StartTextInput(void);
   422  void SDL_StopTextInput(void);
   423  SDL_Keymod SDL_GetModState(void);
   424  Sint32 SDL_SetRelativeMouseMode(SDL_bool enabled);
   425  Uint8 SDL_GetEventState(Uint32 type);
   426  Uint32 SDL_GetGlobalMouseState(int* x, int* y);
   427  Sint32 SDL_GetDisplayBounds(Sint32 displayIndex, SDL_Rect* rect);
   428  
   429  typedef Uint32 (*SDL_TimerCallback)(Uint32 interval, void* param);
   430  SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void* param);
   431  SDL_bool SDL_RemoveTimer(SDL_TimerID id);
   432  `,
   433  		}
   434  	})
   435  	RegisterLibrary(sdl2OpenGLH, func(c *Env) *Library {
   436  		return &Library{
   437  			// TODO
   438  			Header: `
   439  #include <` + BuiltinH + `>
   440  `,
   441  		}
   442  	})
   443  	RegisterLibrary(sdl2OpenGLExtH, func(c *Env) *Library {
   444  		return &Library{
   445  			// TODO
   446  			Header: `
   447  #include <` + BuiltinH + `>
   448  `,
   449  		}
   450  	})
   451  	RegisterLibrary(sdl2StdIncH, func(c *Env) *Library {
   452  		return &Library{
   453  			// TODO
   454  			Header: `
   455  #include <` + BuiltinH + `>
   456  `,
   457  		}
   458  	})
   459  }