c++ - SDL best way to draw gradient background
问题描述
I'm trying to draw gradient (Both horizontal & vertical) background, problem is this causes high cpu usage. Size of a gradient paint is 32767x32767 but of course i'm only drawing based on screen width/height and on offset (starting point of painting). As far as i know i cant put such big painting in memory so paint should be created dynamically. I am using this code right now (on 1600x900 it uses 10-20% of cpu, without gradient paint (looping SDL_RenderDrawLine) it's just 0%):
SDL_SetRenderDrawColor(Renderer, 59, 156, 156, 255);
SDL_RenderClear(Renderer);
for (int X = 0; X < Width; X++)
{
SDL_SetRenderDrawColor(Renderer, 75, 0, 130, X * 255 / 0xfff);
SDL_RenderDrawLine(Renderer, X, 0, X, Height);
}
for (int Y = 0; Y < Height; Y++)
{
SDL_SetRenderDrawColor(Renderer, 75, 0, 130, Y * 255 / 0xfff);
SDL_RenderDrawLine(Renderer, 0, Y, Width, Y);
}
Is there better way to solve this problem ?
解决方案
推荐阅读
- node.js - 404 未找到 nginx/1.18.0 (Ubuntu)
- javascript - 在列表中使用带有 Post 的 href
- flutter - Flutter Page createRoute 设置属性
- r - 使用 zipcodeR 包的两个邮政编码之间的距离不起作用
- scala - NoClassDefFoundError: scala/collection/StringOps
- matlab - matlab如何改变轴的功率?
- c++ - C++ 二维数组拼图
- javascript - 当顶级组件使用 ComponentDidMount 时,使用带有 Hooks 的道具的状态
- php - 如何在 Laravel 中调用变量
- reactjs - 使用 ngnix 作为反向代理进行部署时在反应应用程序中获取空白页面