{"id":31,"date":"2011-10-20T16:13:21","date_gmt":"2011-10-20T19:13:21","guid":{"rendered":"http:\/\/mdqinc.com\/blog\/?p=31"},"modified":"2012-11-29T16:37:29","modified_gmt":"2012-11-29T19:37:29","slug":"python-cython-wrapper-for-sdl-1-3","status":"publish","type":"post","link":"https:\/\/mdqinc.com\/blog\/2011\/10\/python-cython-wrapper-for-sdl-1-3\/","title":{"rendered":"Python \/ Cython wrapper for SDL 1.3"},"content":{"rendered":"<p>The most famous Python bindings for <a href=\"http:\/\/libsdl.org\" target=\"_blank\">SDL<\/a> is probably the <a href=\"http:\/\/pygame.org\/\" target=\"_blank\">PyGame<\/a> project, but it&#8217;s oriented to the 1.2.x versions of the multiplatform library. There&#8217;s also <a href=\"https:\/\/github.com\/albertz\/PySDL\" target=\"_blank\">PySDL<\/a> by Albert Zeyer, which are automatically created from the SDL headers using a generator.<\/p>\n<p>I tried to do the same for Cython, using an automated generator to parse header files and output a Cython sxd file. Sadly the tools for that are a bit green and they don&#8217;t quite work yet, so I&#8217;ve made a <a href=\"http:\/\/cython.org\/\" target=\"_blank\">Cython<\/a> header file handcrafted from SDL 1.3 headers containing the functions I need (There&#8217;s SDL, SDL_image and SDL_ttf functions in there). Based on it and the SDL source code it&#8217;s very easy to expand it, so contributions are most welcome.<\/p>\n<p>Without further ado, <a href=\"http:\/\/mdqinc.com\/blog\/uploads\/SDL.pxd\"  target=\"_blank\">SDL.pxd<\/a>:<\/p>\n<pre class=\"brush:python\">cdef extern from \"SDL.h\":\r\n    ctypedef unsigned char Uint8\r\n    ctypedef unsigned long Uint32\r\n    ctypedef unsigned long long Uint64\r\n    ctypedef signed long long Sint64\r\n    ctypedef signed short Sint16\r\n    ctypedef unsigned short Uint16\r\n\r\n    ctypedef enum:\r\n        SDL_PIXELFORMAT_ARGB8888\r\n\r\n    ctypedef enum SDL_BlendMode:\r\n        SDL_BLENDMODE_NONE = 0x00000000\r\n        SDL_BLENDMODE_BLEND = 0x00000001\r\n        SDL_BLENDMODE_ADD = 0x00000002\r\n        SDL_BLENDMODE_MOD = 0x00000004\r\n\r\n    ctypedef enum SDL_TextureAccess:\r\n        SDL_TEXTUREACCESS_STATIC\r\n        SDL_TEXTUREACCESS_STREAMING\r\n        SDL_TEXTUREACCESS_TARGET\r\n\r\n    ctypedef enum SDL_RendererFlags:\r\n        SDL_RENDERER_SOFTWARE = 0x00000001\r\n        SDL_RENDERER_ACCELERATED = 0x00000002\r\n        SDL_RENDERER_PRESENTVSYNC = 0x00000004\r\n\r\n    ctypedef enum SDL_bool:\r\n        SDL_FALSE = 0\r\n        SDL_TRUE = 1\r\n\r\n    cdef struct SDL_Rect:\r\n        int x, y\r\n        int w, h\r\n\r\n    ctypedef struct SDL_Point:\r\n        int x, y\r\n\r\n    cdef struct SDL_Color:\r\n        Uint8 r\r\n        Uint8 g\r\n        Uint8 b\r\n        Uint8 unused\r\n\r\n    cdef struct SDL_Palette:\r\n        int ncolors\r\n        SDL_Color *colors\r\n        Uint32 version\r\n        int refcount\r\n\r\n    cdef struct SDL_PixelFormat:\r\n        Uint32 format\r\n        SDL_Palette *palette\r\n        Uint8 BitsPerPixel\r\n        Uint8 BytesPerPixel\r\n        Uint8 padding[2]\r\n        Uint32 Rmask\r\n        Uint32 Gmask\r\n        Uint32 Bmask\r\n        Uint32 Amask\r\n        Uint8 Rloss\r\n        Uint8 Gloss\r\n        Uint8 Bloss\r\n        Uint8 Aloss\r\n        Uint8 Rshift\r\n        Uint8 Gshift\r\n        Uint8 Bshift\r\n        Uint8 Ashift\r\n        int refcount\r\n        SDL_PixelFormat *next\r\n\r\n    cdef struct SDL_BlitMap\r\n\r\n    cdef struct SDL_Surface:\r\n        Uint32 flags\r\n        SDL_PixelFormat *format\r\n        int w, h\r\n        int pitch\r\n        void *pixels\r\n        void *userdata\r\n        int locked\r\n        void *lock_data\r\n        SDL_Rect clip_rect\r\n        SDL_BlitMap *map\r\n        int refcount\r\n\r\n    ctypedef enum SDL_EventType:\r\n        SDL_FIRSTEVENT     = 0,\r\n        SDL_QUIT           = 0x100\r\n        SDL_WINDOWEVENT    = 0x200\r\n        SDL_SYSWMEVENT\r\n        SDL_KEYDOWN        = 0x300\r\n        SDL_KEYUP\r\n        SDL_TEXTEDITING\r\n        SDL_TEXTINPUT\r\n        SDL_MOUSEMOTION    = 0x400\r\n        SDL_MOUSEBUTTONDOWN\r\n        SDL_MOUSEBUTTONUP\r\n        SDL_MOUSEWHEEL\r\n        SDL_INPUTMOTION    = 0x500\r\n        SDL_INPUTBUTTONDOWN\r\n        SDL_INPUTBUTTONUP\r\n        SDL_INPUTWHEEL\r\n        SDL_INPUTPROXIMITYIN\r\n        SDL_INPUTPROXIMITYOUT\r\n        SDL_JOYAXISMOTION  = 0x600\r\n        SDL_JOYBALLMOTION\r\n        SDL_JOYHATMOTION\r\n        SDL_JOYBUTTONDOWN\r\n        SDL_JOYBUTTONUP\r\n        SDL_FINGERDOWN      = 0x700\r\n        SDL_FINGERUP\r\n        SDL_FINGERMOTION\r\n        SDL_TOUCHBUTTONDOWN\r\n        SDL_TOUCHBUTTONUP\r\n        SDL_DOLLARGESTURE   = 0x800\r\n        SDL_DOLLARRECORD\r\n        SDL_MULTIGESTURE\r\n        SDL_CLIPBOARDUPDATE = 0x900\r\n        SDL_EVENT_COMPAT1 = 0x7000\r\n        SDL_EVENT_COMPAT2\r\n        SDL_EVENT_COMPAT3\r\n        SDL_USEREVENT    = 0x8000\r\n        SDL_LASTEVENT    = 0xFFFF\r\n\r\n    ctypedef enum SDL_WindowEventID:\r\n        SDL_WINDOWEVENT_NONE           #&lt; Never used *\/\r\n        SDL_WINDOWEVENT_SHOWN          #&lt; Window has been shown *\/\r\n        SDL_WINDOWEVENT_HIDDEN         #&lt; Window has been hidden *\/\r\n        SDL_WINDOWEVENT_EXPOSED        #&lt; Window has been exposed and should be\r\n                                        #     redrawn *\/\r\n        SDL_WINDOWEVENT_MOVED          #&lt; Window has been moved to data1, data2\r\n                                        # *\/\r\n        SDL_WINDOWEVENT_RESIZED        #&lt; Window has been resized to data1xdata2 *\/\r\n        SDL_WINDOWEVENT_SIZE_CHANGED   #&lt; The window size has changed, either as a result of an API call or through the system or user changing the window size. *\/\r\n        SDL_WINDOWEVENT_MINIMIZED      #&lt; Window has been minimized *\/\r\n        SDL_WINDOWEVENT_MAXIMIZED      #&lt; Window has been maximized *\/\r\n        SDL_WINDOWEVENT_RESTORED       #&lt; Window has been restored to normal size\r\n                                        # and position *\/\r\n        SDL_WINDOWEVENT_ENTER          #&lt; Window has gained mouse focus *\/\r\n        SDL_WINDOWEVENT_LEAVE          #&lt; Window has lost mouse focus *\/\r\n        SDL_WINDOWEVENT_FOCUS_GAINED   #&lt; Window has gained keyboard focus *\/\r\n        SDL_WINDOWEVENT_FOCUS_LOST     #&lt; Window has lost keyboard focus *\/\r\n        SDL_WINDOWEVENT_CLOSE           #&lt; The window manager requests that the\r\n                                        # window be closed *\/\r\n\r\n    ctypedef enum SDL_WindowFlags:\r\n        SDL_WINDOW_FULLSCREEN = 0x00000001\r\n        SDL_WINDOW_OPENGL = 0x00000002\r\n        SDL_WINDOW_SHOWN = 0x00000004\r\n        SDL_WINDOW_HIDDEN = 0x00000008\r\n        SDL_WINDOW_BORDERLESS = 0x00000010\r\n        SDL_WINDOW_RESIZABLE = 0x00000020\r\n        SDL_WINDOW_MINIMIZED = 0x00000040\r\n        SDL_WINDOW_MAXIMIZED = 0x00000080\r\n        SDL_WINDOW_INPUT_GRABBED = 0x00000100\r\n        SDL_WINDOW_INPUT_FOCUS = 0x00000200\r\n        SDL_WINDOW_MOUSE_FOCUS = 0x00000400\r\n        SDL_WINDOW_FOREIGN = 0x00000800\r\n\r\n    ctypedef enum SDL_RendererFlip:\r\n        SDL_FLIP_NONE = 0x00000000\r\n        SDL_FLIP_HORIZONTAL = 0x00000001\r\n        SDL_FLIP_VERTICAL = 0x00000002\r\n\r\n    cdef struct SDL_MouseMotionEvent:\r\n        Uint32 type\r\n        Uint32 windowID\r\n        Uint8 state\r\n        Uint8 padding1\r\n        Uint8 padding2\r\n        Uint8 padding3\r\n        int x\r\n        int y\r\n        int xrel\r\n        int yrel\r\n\r\n    cdef struct SDL_MouseButtonEvent:\r\n        Uint32 type\r\n        Uint32 windowID\r\n        Uint8 button\r\n        Uint8 state\r\n        Uint8 padding1\r\n        Uint8 padding2\r\n        int x\r\n        int y\r\n\r\n    cdef struct SDL_WindowEvent:\r\n        Uint32 type\r\n        Uint32 windowID\r\n        Uint8 event\r\n        Uint8 padding1\r\n        Uint8 padding2\r\n        Uint8 padding3\r\n        int data1\r\n        int data2\r\n\r\n    ctypedef Sint64 SDL_TouchID\r\n    ctypedef Sint64 SDL_FingerID\r\n\r\n    cdef struct SDL_TouchFingerEvent:\r\n        Uint32 type\r\n        Uint32 windowID\r\n        SDL_TouchID touchId\r\n        SDL_FingerID fingerId\r\n        Uint8 state\r\n        Uint8 padding1\r\n        Uint8 padding2\r\n        Uint8 padding3\r\n        Uint16 x\r\n        Uint16 y\r\n        Sint16 dx\r\n        Sint16 dy\r\n        Uint16 pressure\r\n\r\n    cdef struct SDL_KeyboardEvent:\r\n        pass\r\n    cdef struct SDL_TextEditingEvent:\r\n        pass\r\n    cdef struct SDL_TextInputEvent:\r\n        pass\r\n    cdef struct SDL_MouseWheelEvent:\r\n        Uint32 type\r\n        Uint32 windowID\r\n        int x\r\n        int y\r\n\r\n    cdef struct SDL_JoyAxisEvent:\r\n        pass\r\n    cdef struct SDL_JoyBallEvent:\r\n        pass\r\n    cdef struct SDL_JoyHatEvent:\r\n        pass\r\n    cdef struct SDL_JoyButtonEvent:\r\n        pass\r\n    cdef struct SDL_QuitEvent:\r\n        pass\r\n    cdef struct SDL_UserEvent:\r\n        pass\r\n    cdef struct SDL_SysWMEvent:\r\n        pass\r\n    cdef struct SDL_TouchFingerEvent:\r\n        pass\r\n    cdef struct SDL_TouchButtonEvent:\r\n        pass\r\n    cdef struct SDL_MultiGestureEvent:\r\n        pass\r\n    cdef struct SDL_DollarGestureEvent:\r\n        pass\r\n\r\n    cdef union SDL_Event:\r\n        Uint32 type\r\n        SDL_WindowEvent window\r\n        SDL_KeyboardEvent key\r\n        SDL_TextEditingEvent edit\r\n        SDL_TextInputEvent text\r\n        SDL_MouseMotionEvent motion\r\n        SDL_MouseButtonEvent button\r\n        SDL_MouseWheelEvent wheel\r\n        SDL_JoyAxisEvent jaxis\r\n        SDL_JoyBallEvent jball\r\n        SDL_JoyHatEvent jhat\r\n        SDL_JoyButtonEvent jbutton\r\n        SDL_QuitEvent quit\r\n        SDL_UserEvent user\r\n        SDL_SysWMEvent syswm\r\n        SDL_TouchFingerEvent tfinger\r\n        SDL_TouchButtonEvent tbutton\r\n        SDL_MultiGestureEvent mgesture\r\n        SDL_DollarGestureEvent dgesture\r\n\r\n    cdef struct SDL_RendererInfo:\r\n        char *name\r\n        Uint32 flags\r\n        Uint32 num_texture_formats\r\n        Uint32 texture_formats[16]\r\n        int max_texture_width\r\n        int max_texture_height\r\n\r\n    ctypedef struct SDL_Texture\r\n    ctypedef struct SDL_Renderer\r\n    ctypedef struct SDL_Window\r\n    ctypedef struct SDL_DisplayMode:\r\n        Uint32 format\r\n        int w\r\n        int h\r\n        int refresh_rate\r\n        void *driverdata\r\n\r\n    cdef struct SDL_RWops:\r\n        long (* seek) (SDL_RWops * context, long offset,int whence)\r\n        size_t(* read) ( SDL_RWops * context, void *ptr, size_t size, size_t maxnum)\r\n        size_t(* write) (SDL_RWops * context, void *ptr,size_t size, size_t num)\r\n        int (* close) (SDL_RWops * context)\r\n\r\n    cdef SDL_Renderer * SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)\r\n    cdef SDL_Texture * SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int h)\r\n    cdef SDL_Texture * SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)\r\n    cdef SDL_Surface * SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)\r\n    cdef int SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Rect * srcrect, SDL_Rect * dstrect)\r\n    cdef int SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Rect * srcrect, SDL_Rect * dstrect, double angle, SDL_Point *center, SDL_RendererFlip flip)\r\n    cdef void SDL_RenderPresent(SDL_Renderer * renderer)\r\n    cdef SDL_bool SDL_RenderTargetSupported(SDL_Renderer *renderer)\r\n    cdef int SDL_SetTargetTexture(SDL_Texture *texture)\r\n    cdef SDL_bool SDL_ResetTargetTexture(SDL_Renderer *renderer)\r\n    cdef void SDL_DestroyTexture(SDL_Texture * texture)\r\n    cdef void SDL_FreeSurface(SDL_Surface * surface)\r\n    cdef int SDL_UpperBlit (SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect)\r\n    cdef int SDL_LockTexture(SDL_Texture * texture, SDL_Rect * rect, void **pixels, int *pitch)\r\n    cdef void SDL_UnlockTexture(SDL_Texture * texture)\r\n    cdef void SDL_GetWindowSize(SDL_Window * window, int *w, int *h)\r\n    cdef SDL_Window * SDL_CreateWindow(char *title, int x, int y, int w, int h, Uint32 flags)\r\n    cdef int SDL_SetRenderDrawColor(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a)\r\n    cdef int SDL_RenderClear(SDL_Renderer * renderer)\r\n    cdef int SDL_SetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode blendMode)\r\n    cdef int SDL_GetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode *blendMode)\r\n    cdef SDL_Surface * SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)\r\n    cdef int SDL_Init(Uint32 flags)\r\n    cdef void SDL_Quit()\r\n    cdef int SDL_EnableUNICODE(int enable)\r\n    cdef Uint32 SDL_GetTicks()\r\n    cdef void SDL_Delay(Uint32 ms)\r\n    cdef int SDL_PollEvent(SDL_Event * event)\r\n    cdef SDL_RWops * SDL_RWFromFile(char *file, char *mode)\r\n    cdef void SDL_FreeRW(SDL_RWops *area)\r\n    cdef int SDL_GetRendererInfo(SDL_Renderer *renderer, SDL_RendererInfo *info)\r\n    cdef int SDL_RenderSetViewport(SDL_Renderer * renderer, SDL_Rect * rect)\r\n    cdef int SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode)\r\n    cdef int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode)\r\n    cdef int SDL_SetTextureColorMod(SDL_Texture * texture, Uint8 r, Uint8 g, Uint8 b)\r\n    cdef int SDL_SetTextureAlphaMod(SDL_Texture * texture, Uint8 alpha)\r\n    cdef char * SDL_GetError()\r\n\r\ncdef extern from \"SDL_image.h\":\r\n    cdef SDL_Surface *IMG_Load(char *file)\r\n\r\ncdef extern from \"SDL_ttf.h\":\r\n    ctypedef struct TTF_Font\r\n    cdef int TTF_Init()\r\n    cdef TTF_Font *  TTF_OpenFont( char *file, int ptsize)\r\n    cdef TTF_Font *  TTF_OpenFontIndex( char *file, int ptsize, long index)\r\n    cdef TTF_Font *  TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize)\r\n    cdef TTF_Font *  TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index)\r\n    #Set and retrieve the font style\r\n    #define TTF_STYLE_NORMAL    0x00\r\n    #define TTF_STYLE_BOLD      0x01\r\n    #define TTF_STYLE_ITALIC    0x02\r\n    #define TTF_STYLE_UNDERLINE 0x04\r\n    #define TTF_STYLE_STRIKETHROUGH 0x08\r\n    cdef int  TTF_GetFontStyle( TTF_Font *font)\r\n    cdef void  TTF_SetFontStyle(TTF_Font *font, int style)\r\n    cdef int  TTF_GetFontOutline( TTF_Font *font)\r\n    cdef void  TTF_SetFontOutline(TTF_Font *font, int outline)\r\n\r\n    #Set and retrieve FreeType hinter settings *\/\r\n    #define TTF_HINTING_NORMAL    0\r\n    #define TTF_HINTING_LIGHT     1\r\n    #define TTF_HINTING_MONO      2\r\n    #define TTF_HINTING_NONE      3\r\n    cdef int  TTF_GetFontHinting( TTF_Font *font)\r\n    cdef void  TTF_SetFontHinting(TTF_Font *font, int hinting)\r\n\r\n    #Get the total height of the font - usually equal to point size\r\n    cdef int  TTF_FontHeight( TTF_Font *font)\r\n\r\n    ## Get the offset from the baseline to the top of the font\r\n    #This is a positive value, relative to the baseline.\r\n    #*\/\r\n    cdef int  TTF_FontAscent( TTF_Font *font)\r\n\r\n    ## Get the offset from the baseline to the bottom of the font\r\n    #   This is a negative value, relative to the baseline.\r\n    # *\/\r\n    cdef int  TTF_FontDescent( TTF_Font *font)\r\n\r\n    ## Get the recommended spacing between lines of text for this font *\/\r\n    cdef int  TTF_FontLineSkip( TTF_Font *font)\r\n\r\n    ## Get\/Set whether or not kerning is allowed for this font *\/\r\n    cdef int  TTF_GetFontKerning( TTF_Font *font)\r\n    cdef void  TTF_SetFontKerning(TTF_Font *font, int allowed)\r\n\r\n    ## Get the number of faces of the font *\/\r\n    cdef long  TTF_FontFaces( TTF_Font *font)\r\n\r\n    ## Get the font face attributes, if any *\/\r\n    cdef int  TTF_FontFaceIsFixedWidth( TTF_Font *font)\r\n    cdef char *  TTF_FontFaceFamilyName( TTF_Font *font)\r\n    cdef char *  TTF_FontFaceStyleName( TTF_Font *font)\r\n\r\n    ## Check wether a glyph is provided by the font or not *\/\r\n    cdef int  TTF_GlyphIsProvided( TTF_Font *font, Uint16 ch)\r\n\r\n    ## Get the metrics (dimensions) of a glyph\r\n    #   To understand what these metrics mean, here is a useful link:\r\n    #    http:\/\/freetype.sourceforge.net\/freetype2\/docs\/tutorial\/step2.html\r\n    # *\/\r\n    cdef int  TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,int *minx, int *maxx, int *miny, int *maxy, int *advance)\r\n\r\n    ## Get the dimensions of a rendered string of text *\/\r\n    cdef int  TTF_SizeText(TTF_Font *font,  char *text, int *w, int *h)\r\n    cdef int  TTF_SizeUTF8(TTF_Font *font,  char *text, int *w, int *h)\r\n    cdef int  TTF_SizeUNICODE(TTF_Font *font,  Uint16 *text, int *w, int *h)\r\n\r\n    # Create an 8-bit palettized surface and render the given text at\r\n    #   fast quality with the given font and color.  The 0 pixel is the\r\n    #   colorkey, giving a transparent background, and the 1 pixel is set\r\n    #   to the text color.\r\n    #   This function returns the new surface, or NULL if there was an error.\r\n    #*\/\r\n    cdef SDL_Surface *  TTF_RenderText_Solid(TTF_Font *font, char *text, SDL_Color fg)\r\n    cdef SDL_Surface *  TTF_RenderUTF8_Solid(TTF_Font *font, char *text, SDL_Color fg)\r\n    cdef SDL_Surface *  TTF_RenderUNICODE_Solid(TTF_Font *font, Uint16 *text, SDL_Color fg)\r\n\r\n    # Create an 8-bit palettized surface and render the given glyph at\r\n    #   fast quality with the given font and color.  The 0 pixel is the\r\n    #   colorkey, giving a transparent background, and the 1 pixel is set\r\n    #   to the text color.  The glyph is rendered without any padding or\r\n    #   centering in the X direction, and aligned normally in the Y direction.\r\n    #   This function returns the new surface, or NULL if there was an error.\r\n    #*\/\r\n    cdef SDL_Surface *  TTF_RenderGlyph_Solid(TTF_Font *font, Uint16 ch, SDL_Color fg)\r\n\r\n    # Create an 8-bit palettized surface and render the given text at\r\n    #   high quality with the given font and colors.  The 0 pixel is background,\r\n    #   while other pixels have varying degrees of the foreground color.\r\n    #  This function returns the new surface, or NULL if there was an error.\r\n    #*\/\r\n    cdef SDL_Surface *  TTF_RenderText_Shaded(TTF_Font *font, char *text, SDL_Color fg, SDL_Color bg)\r\n    cdef SDL_Surface *  TTF_RenderUTF8_Shaded(TTF_Font *font, char *text, SDL_Color fg, SDL_Color bg)\r\n    cdef SDL_Surface *  TTF_RenderUNICODE_Shaded(TTF_Font *font, Uint16 *text, SDL_Color fg, SDL_Color bg)\r\n\r\n    # Create an 8-bit palettized surface and render the given glyph at\r\n    #   high quality with the given font and colors.  The 0 pixel is background,\r\n    #   while other pixels have varying degrees of the foreground color.\r\n    #   The glyph is rendered without any padding or centering in the X\r\n    #   direction, and aligned normally in the Y direction.\r\n    #   This function returns the new surface, or NULL if there was an error.\r\n    #\r\n    cdef SDL_Surface *  TTF_RenderGlyph_Shaded(TTF_Font *font,\r\n                    Uint16 ch, SDL_Color fg, SDL_Color bg)\r\n\r\n    # Create a 32-bit ARGB surface and render the given text at high quality,\r\n    #   using alpha blending to dither the font with the given color.\r\n    #   This function returns the new surface, or NULL if there was an error.\r\n    #*\/\r\n    cdef SDL_Surface *  TTF_RenderText_Blended(TTF_Font *font,\r\n                     char *text, SDL_Color fg)\r\n    cdef SDL_Surface *  TTF_RenderUTF8_Blended(TTF_Font *font,\r\n                     char *text, SDL_Color fg)\r\n    cdef SDL_Surface *  TTF_RenderUNICODE_Blended(TTF_Font *font,\r\n                     Uint16 *text, SDL_Color fg)\r\n\r\n    # Create a 32-bit ARGB surface and render the given glyph at high quality,\r\n    #   using alpha blending to dither the font with the given color.\r\n    #   The glyph is rendered without any padding or centering in the X\r\n    #   direction, and aligned normally in the Y direction.\r\n    #   This function returns the new surface, or NULL if there was an error.\r\n    #*\/\r\n    cdef SDL_Surface *  TTF_RenderGlyph_Blended(TTF_Font *font,\r\n                            Uint16 ch, SDL_Color fg)\r\n\r\n    # For compatibility with previous versions, here are the old functions *\/\r\n    #define TTF_RenderText(font, text, fg, bg)  \\\r\n    #    TTF_RenderText_Shaded(font, text, fg, bg)\r\n    #define TTF_RenderUTF8(font, text, fg, bg)  \\\r\n    #    TTF_RenderUTF8_Shaded(font, text, fg, bg)\r\n    #define TTF_RenderUNICODE(font, text, fg, bg)   \\\r\n    #    TTF_RenderUNICODE_Shaded(font, text, fg, bg)\r\n\r\n    # Close an opened font file *\/\r\n    cdef void  TTF_CloseFont(TTF_Font *font)\r\n\r\n    # De-initialize the TTF engine *\/\r\n    cdef void  TTF_Quit()\r\n\r\n    # Check if the TTF engine is initialized *\/\r\n    cdef int  TTF_WasInit()\r\n\r\n    # Get the kerning size of two glyphs *\/\r\n    cdef int TTF_GetFontKerningSize(TTF_Font *font, int prev_index, int index)<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The most famous Python bindings for SDL is probably the PyGame project, but it&#8217;s oriented to the 1.2.x versions of the multiplatform library. There&#8217;s also PySDL by Albert Zeyer, which are automatically created from the SDL headers using a generator. I tried to do the same for Cython, using an automated generator to parse header [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"_links":{"self":[{"href":"https:\/\/mdqinc.com\/blog\/wp-json\/wp\/v2\/posts\/31"}],"collection":[{"href":"https:\/\/mdqinc.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mdqinc.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mdqinc.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mdqinc.com\/blog\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":3,"href":"https:\/\/mdqinc.com\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":54,"href":"https:\/\/mdqinc.com\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions\/54"}],"wp:attachment":[{"href":"https:\/\/mdqinc.com\/blog\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mdqinc.com\/blog\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mdqinc.com\/blog\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}