更改 SDL 背景
有没有办法将空 SDL 窗口的颜色更改为白色而不是黑色?我不想更改任何默认设置。我只是想为我正在编写的这个特定程序更改它。我不想使用图像文件,但如果必须的话,我会的。
我不知道这是否重要,但我正在使用 SDL_SetVideoMode()
我的代码非常基本:
if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
return 1;
SDL_Surface * screen = NULL;
screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE);
SDL_FillRect(screen, NULL, 0xFFFFFF);
SDL_Delay(3000);
Is there any way to change the color of an empty SDL window to be white instead of black? I don't want to change any default settings. I'm just trying to change it for this particular program that I'm writing. I don't want to use an image file, but if I have to, I will.
I don't know if this matters, but I'm using SDL_SetVideoMode()
My code is very basic:
if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
return 1;
SDL_Surface * screen = NULL;
screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE);
SDL_FillRect(screen, NULL, 0xFFFFFF);
SDL_Delay(3000);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要调用 SDL_Flip 才能显示您的更改。
You need to call SDL_Flip for your changes to show up.
使用
surf = SDL_SetVideoMode(...)
从窗口获取表面,然后执行Acquire the surface from your Window using
surf = SDL_SetVideoMode(...)
and then do您可以使用 SDL_FillRect 用您想要的颜色填充屏幕/表面。
You could use SDL_FillRect to fill the screen/a surface with your desired color.
您需要在 SDL_FillRect 之后调用 SDL_UpdateRect。
You need to call SDL_UpdateRect after SDL_FillRect.