如何在 SDL 中创建颜色渐变 [英] How to create a color gradient in SDL
本文介绍了如何在 SDL 中创建颜色渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SDL 没有这样的功能,很好奇过去是否有人这样做过并且不介意将我引向正确的方向.我想在两种颜色之间创建一个渐变,以反映在矩形的高度上.
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.
推荐答案
只需在所需的 y 位置上循环,您可以:
Just make a loop over the desired y positions, in which you:
- 通过在渐变的端点颜色之间进行插值来计算所需的颜色.
- 调用
SDL_SetRenderDrawColor()
来设置颜色. - 调用
SDL_RenderDrawLine()
在当前 y 位置绘制一条水平线.
这篇关于如何在 SDL 中创建颜色渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文