3
\$\begingroup\$

I want to create a menu for a game using a color gradient as the background. Is there a way to create a gradient background instead of using an image for it (since I don't know what size the window will be, using an image is no option).

Please note: I need to achieve this using only the C standard library and the SDL, no other library and no C++.

\$\endgroup\$
3
\$\begingroup\$

See this StackOverflow answer: There is no ready-made way in SDL, so you will have to manually create the gradient by computing the color for each line and drawing it. More details in the linked answer.

Some additional inspiration can be drawn from the following two threads on gamedev.net:

  1. SDL Gradient
  2. Better Gradients

Regarding the image & window size argument: You could probably use an precomputed gradient image and make it stretch to the current window size. That would probably be faster from a performance point of view and still be able to handle all window sizes.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.