c++ - 如何在 Linux 中将 SDL 窗口居中?

标签 c++ linux sdl

我试图找到一种方法来创建一个以屏幕为中心的 SDL 窗口,我找到了这段代码

#ifdef WIN32
#include <SDL_syswm.h>
SDL_SysWMinfo i;
SDL_VERSION( &i.version );
if ( SDL_GetWMInfo ( &i) ) {
HWND hwnd = i.window;
SetWindowPos( hwnd, HWND_TOP, x, y, width, height, flags );
}
#endif // WIN32

但它仅适用于 Windows。我如何在 Linux 中执行此操作?

最佳答案

使用putenv()在初始化 SDL 和创建窗口之前:

#include <SDL.h>
#include <SDL_getenv.h>

int main( int argc, char* argv[] )
{
    putenv("SDL_VIDEO_CENTERED=1"); 
    // init SDL, create window, main loop, etc.
    ...
}

关于c++ - 如何在 Linux 中将 SDL 窗口居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11986520/

相关文章:

javascript - 如何在 npm install 中克服这个错误?

php - 使用 key 文件加密,使用密码解密

c++ - OpenGL glGenVertexArray() 异常

c++ - Linux 相当于 DllMain

c++ - 仍然得到二进制 "<<": no operator found which takes a right-hand with <string>

c++ - 在没有数组的情况下更新最后 3 个值?

ruby - 在路径下删除 Ruby 中的文件夹

c++ - SDL 2.0 中的 SDL_GetVideoSurface() 等效函数

c++ - Windows Vista/7 上的 SDL_Mixer MIDI 音量问题

c++ - 如何翻转数组中的某些数字