Drawing shapesSDL 3.2

SDL_RenderGeometry

Draws triangles from your own vertices, each with a position, a colour and texture coordinates.

Signature

bool SDL_RenderGeometry(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Vertex *vertices, int num_vertices, const int *indices, int num_indices);

How it works

The renderer's escape hatch for shapes it has no function for: gradients, rotated quads, thick lines, circles, deformed sprites. Every three vertices (or every three indices) make one triangle, and colours are interpolated across it.

SDL_Vertex has position (SDL_FPoint), color (SDL_FColor, floats 0–1 in SDL3) and tex_coord (SDL_FPoint, 0–1 across the texture).

Parameters

rendererSDL_Renderer *

The renderer.

textureSDL_Texture *

Texture to sample with tex_coord, or NULL for colour only.

verticesconst SDL_Vertex *

The vertex array.

num_verticesint

How many vertices.

indicesconst int *

Optional index array (reuse vertices between triangles), or NULL.

num_indicesint

How many indices (a multiple of 3), or 0.

Return value

true on success, false on failure.

Example

example.cpp
1SDL_Vertex verts[3] = {
2    {{640, 100}, {1, 0, 0, 1}, {0, 0}},   // red top
3    {{340, 600}, {0, 1, 0, 1}, {0, 0}},   // green left
4    {{940, 600}, {0, 0, 1, 1}, {0, 0}},   // blue right
5};
6SDL_RenderGeometry(renderer, nullptr, verts, 3, nullptr, 0);
Official SDL wiki