How to create a color gradient in SDL

c, sdl

Solution

Just make a loop over the desired y positions, in which you:

- Compute the desired color by interpolating between the gradient's endpoint colors.

- Call `SDL_SetRenderDrawColor()` to set the color.

- Call `SDL_RenderDrawLine()` to draw a horizontal line at the current y position.

Problem

SDL has no function like this, curious if anyone in the past has done it and wouldn't mind heading me in the right direction. I want to create a gradient between two colors to be reflected on the height of a rectangle.

Original source

Related problems