SDL_QuickReference - nalinkanwar/yagdp GitHub Wiki
SDL_Init() : Main Init function for SDL can optionally pass argument for initing subsystems e.g. SDL_INIT_VIDEO, SDL_INIT_EVENTS, SDL_INIT_EVERYTHING, SDL_INIT_AUDIO, SDL_INIT_TIMER etc. SDL_InitSubSystem() : See above, SDL_Init can only be called once at start, use this to turn systems on/off later
SDL_Delay() : os independent sleep
SDL_GetError() : errno is set on error and this function gives us info about it
SDL_Quit()
SDL_CreateWindow(Title, Pos X, Pos Y, Width, Height, Flags) : pos constants > SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_UNDEFINED few useful flags > SDL_WINDOW_FULLSCREEN, SDL_WINDOW_RESIZABLE, SDL_WINDOW_HIDDEN, SDL_WINDOW_BORDERLESS, SDL_WINDOW_FULLSCREEN_DESKTOP
SDL_UpdateWindowSurface(window) : This is like flip; it switches framebuffers to show updated framebuffer; call when you are done drawing to that surface.
SDL_DestroyWindow()
SDL_GetWindowSurface(window) : Get handle of the surface(i.e. SDL_Surface) of window
SDL_LoadBMP() : returns a SDL_Surface containing the image
SDL_BlitSurface(, <src SDL_Rect/NULL>, , ) : Copy one surface to another, SDL_Rect can be passed if we want part of surface instead of whole surface(NULL)
SDL_BlitScaled(, <src surface SDL_Rect/NULL>, , <dst SDL_Rect/NULL>) : Copy & Scale surfaces; same as above except dst rect can be NULL and it will copy over whole dst surface & scale where necessary This won't truncate a surface but scale it, while SDL_BlitSurface will if src > dst
SDL_ConvertSurface(), SDL_PixelFormat, 0) : Converts loaded sprites to surface's pixel format for optimized blitting You should convert each of your loaded files to window's format usually using >format. Don't forget to get rid of old surface! Last argument is deprecated & for 1.2 compat
SDL_SetColorKey(, <0/1>, ) : This sets the transparent color for the texture. This will very useful for us. The second argument turns color key on or off, and last argument is the color that is supposed to be transparent.
SDL_LockSurface() : Lock the surface for direct access to it's pixels via .pixels using .format for bitdepth info SDL_UnlockSurface( : Unlock the surface
SDL_SetSurfaceRLE(, <0/1>) : Turn on or off RLE compression while blitting. This greatly improves performance for large textures with lots of similar coloured pixel in a row. NEED to lock/unlock surface before accessing it's pixels when using this.
SDL_MapRGB(, , , ) : Returns Color(UInt32) that is mapped to the for the RGB values provided SDL_MapRGBA(, , , , )
SDL_GetRGB(, , <&r>, <&g>, <&b>) : Returns r,g,b values in for value SDL_GetRGBA(, , <&r>, <&g>, <&b>, <&a>)
SDL_FreeSurface()
SDL_CreateTextureFromSurface(, ): Just like ConvertSurface, it turns surface to SDL_Texture for rendering Don't forget to get rid of old surface!
SDL_SetTextureColorMod(, , , ) : Modulate colours of texture; for e.g. if i pass (255, 128, 255) for a texture, all the green colour in texture will be halved (255/2 = 128)
SDL_SetTextureAlphaMod(, ) : Modulate Alpha value of colours in a texture. This when used with proper BlendMode can give us translucent effect textures
SDL_SetTextureBlendMode(, ) : Texture specific blend mode; Remember this is only important when the texture that you're trying to blend is put onto another texture.
SDL_DestroyTexture()
SDL_CreateRenderer(, <index/1>, ): Create a 2D rendering context for the window indexes: SDL_RENDERER_SOFTWARE(fallback), SDL_RENDERER_ACCELERATED (hw), SDL_RENDERER_PRESENTVSYNC (vsync, 'or' with other two flags)
SDL_SetRenderDrawColor(, r, g, b, a): What colour to use while drawing render primitives (Rect, Line & Clear) a is alpha usually SDL_ALPHA_OPAQUE unless you are doing Blending
SDL_SetRenderDrawBlendMode(, ) : Defines how to blend alpha channel when overwriting existing colour with new one. modes are SDL_BLENDMODE_NONE, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_ADD, SDL_BLENDMODE_MOD
SDL_RenderClear() : Clears the screen to RenderDrawColor
SDL_RenderCopy(<rndrr, , <srcSDL_Rect/NULL>, <dstSDL_Rect/NULL>): Similar to BlitSurface, Render the texture onto the surface. Will stretch src to dst if Rect is specified and is larger/smaller.
SDL_RenderPresent() : Render the present copy to screen, similar to UpdateWindowSurface()
SDL_RenderSetViewport(, SDL_Rect/NULL) : This is used to segment the screen into different parts; Once a viewport is set, all the renderings after it will be done in that viewport. Set NULL to reset Viewport.
SDL_RenderGetViewport(, SDL_Rect) : Get current viewport for that renderer
SDL_PollEvent(<&event>): e.type : Lots of different types, few notable are : SDL_KEYDOWN, SDL_KEYUP, SDL_MOUSEMOTION, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_QUIT, SDL_WINDOWEVENT
e.key.keysym.sym : keyboard event; returns SDLK_UP, SDLK_DOWN, SDLK_LEFT, SDLK_RIGHT, SDLK_ENTER, SDLK_ESCAPE and so on
scancode is 'physical keycode' and keycode is 'virtual keycode', we use keycode mostly unless physical location of keys matter
SDL_Point : Pixel in Rendering method .x & .y SDL_Rect: Basic rectangle object for SDL has x,y,w,h for specifying parameters
SDL_RenderDrawPoint(,,) : Draw a pixel with RenderColor SDL_RenderDrawLine(,,,,) : Draw a line with RenderColor SDL_RenderDrawRect(,<SDL_Rect>) : Draw a rectangle with RenderColor
SDL_RenderDrawPoints(, <SDL_Point *>, ) : Draw multiple points from array of SDL_Point(s). SDL_RenderDrawLines(, <SDL_Point *>, ) : Draw a polygon from array of SDL_Point(s). SDL_RenderDrawRects(, <SDL_Rect *>, ) : Draw rectangles with RenderColor
SDL_RenderFillRect(, ) : Draw a rectangle and fill it with RenderColor SDL_RenderFillRects(, <SDL_Rect *>, ) : Draw rectangles and fill them with RenderColor