SDL School

API reference / Windows and drawing

SDL_RenderLine

Function, SDL3

Draws a line between two points, one pixel wide.

Declaration

#include <SDL3/SDL.h>

bool SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2);

Parameters

rendererThe renderer.
x1The x position of the first point.
y1The y position of the first point.
x2The x position of the second point.
y2The y position of the second point.

Return value

True on success. On failure it returns false.

Example

Draw shapes
float half_width = SDL_sqrtf(radius * radius - dy * dy);

SDL_RenderLine(renderer, x - half_width, y + dy, x + half_width, y + dy);

See this code run in Draw shapes. Download the full program (.zip)

In SDL2

Use SDL_RenderDrawLineF for float positions.

See also