API reference
This reference covers the SDL3 functions that the lessons use. Each page has the real declaration, a description of each parameter, and code from a working program. Each page also tells you the SDL2 name, and it links to the lesson that runs the code and to a download of the full program.
SDL has more than 1,200 functions. For the rest, read the official SDL documentation.
No function matches this search.
Application
Functions that start a program, run it, and end it.
SDL_InitStarts the parts of SDL that your program needs. Call it before most other SDL functions.SDL_AppInitYou write this function, and SDL calls it one time at the start of the program. Use it for setup.SDL_AppIterateYou write this function, and SDL calls it again and again, about one time for each frame. Update and draw here.SDL_AppEventYou write this function. SDL calls it for each event, such as a key press or a click on the close button.SDL_AppQuitYou write this function, and SDL calls it one time at the end of the program. Free your own resources here.SDL_GetErrorGets a message that describes the last error in SDL. Call it just after a function reports a failure.SDL_LogPrints a message, in the same way as printf. On the desktop it goes to the terminal, and in a browser it goes to the console.
Windows and drawing
Functions that open a window and draw on it.
SDL_CreateWindowAndRendererMakes a window and a renderer in one call. The window is the rectangle on the screen, and the renderer is the object that draws in it.SDL_SetRenderVSyncMakes the present step wait for the screen. Without it, a program draws as fast as it can and uses a full CPU core.SDL_SetRenderDrawColorSets the color for the next drawing calls. The color stays until you set another one.SDL_SetRenderDrawBlendModeSets how the next drawing calls mix with the pixels that are already there.SDL_RenderClearFills the full hidden picture with the current draw color. Most programs call this first in each frame.SDL_RenderPresentShows the hidden picture on the screen. Call it one time at the end of each frame.SDL_RenderPointColors one pixel with the current draw color.SDL_RenderLineDraws a line between two points, one pixel wide.SDL_RenderLinesJoins a list of points in order with straight lines.SDL_RenderRectDraws the outline of a rectangle, one pixel wide.SDL_RenderFillRectFills a rectangle with the current draw color.SDL_RenderGeometryDraws triangles from a list of vertices. The graphics card fills each triangle and blends the vertex colors across it.SDL_RenderDebugTextDraws a line of text in a built-in font, with no font file. It is for a quick message while you debug.SDL_ConvertEventToRenderCoordinatesChanges the position in a mouse or touch event from window coordinates to renderer coordinates.
Images and textures
Functions that load images and draw them.
SDL_LoadPNGLoads a PNG file into a surface, an image in main memory.SDL_CreateTextureFromSurfaceCopies a surface to the graphics card as a texture. You draw textures, and they are fast.SDL_DestroySurfaceFrees a surface.SDL_DestroyTextureFrees a texture. After this call, the texture pointer is not valid.SDL_GetTextureSizeGets the size of a texture in pixels.SDL_SetTextureScaleModeSets how a texture looks at a new size.SDL_RenderTextureDraws a texture, or a part of it, at a position and size.SDL_RenderTextureRotatedDraws a texture with a rotation, a flip, or both.
Input and time
Functions that read the keyboard, test positions, and measure time.
SDL_GetKeyboardStateGets an array that tells you which keys are down now. Use it for keys that the user holds.SDL_PointInRectFloatTests whether a point is inside a rectangle. This is the test for a click on a button.SDL_GetTicksNSGets the time since SDL started, in nanoseconds. Use two readings to measure a time.
Audio
Functions that load sound and send it to the speakers.
SDL_LoadWAVLoads a WAV file into memory.SDL_OpenAudioDeviceStreamOpens an audio device and gives you a stream that is connected to it. A stream is a queue for samples that also converts their format.SDL_ResumeAudioStreamDeviceStarts or continues the device of a stream. A new stream makes no sound until you call this.SDL_PutAudioStreamDataAdds samples to the end of a stream. The device plays them in order, and the function returns at once.SDL_ClearAudioStreamRemoves all the samples that wait in a stream. Use it to stop a sound at once.SDL_GetAudioStreamQueuedGets the number of bytes that wait in a stream.SDL_DestroyAudioStreamFrees a stream. For a stream from SDL_OpenAudioDeviceStream, this also closes its device.
Files, memory, and strings
Functions that load files, manage memory, and work with text.
SDL_LoadFileReads a full file into new memory, and adds a null character at the end.SDL_mallocAllocates memory. The memory is not cleared.SDL_callocAllocates memory for an array, and fills it with zeros.SDL_freeFrees memory from an SDL function.SDL_memmoveCopies a block of memory, and it handles a source and a destination that overlap.SDL_strlenGets the length of a string, not counting the null character.SDL_strchrFinds the first copy of a character in a string.SDL_snprintfWrites formatted text into an array, as snprintf does. It never writes past the size that you give.SDL_zeroFills a variable or a struct with zeros. This is a macro, so you give the object and not its address.SDL_arraysizeGives the number of elements in an array. This is a macro.
Math
Small math functions and macros.
SDL_clampKeeps a value between a minimum and a maximum. This is a macro.SDL_minGives the smaller of two values. This is a macro.SDL_maxGives the larger of two values. This is a macro.SDL_floorfRounds a float down to a whole number.SDL_sinfGives the sine of an angle in radians.SDL_cosfGives the cosine of an angle in radians.SDL_sqrtfGives the square root of a number.
Text with SDL_ttf
Functions from the separate SDL_ttf library, which draws text from a font file.
TTF_InitStarts SDL_ttf. Call it before any other SDL_ttf function.TTF_QuitEnds SDL_ttf. Close your fonts first.TTF_OpenFontOpens a font file at one size. For a second size, open the file again.TTF_CloseFontCloses a font and frees its memory.TTF_RenderText_Blended_WrappedDraws text into a new surface, with smooth edges. Long text breaks onto new lines at the width that you choose.