调整SDL2窗口的大小?

时间:2013-12-23 00:40:06

标签: c++ window sdl sdl-2

刚刚从SDL1.2跳转到SDL2,转换了我的代码,但无法弄清楚如何调整窗口大小。这是我现在的代码:

SDL_DestroyWindow(Window);
Window = SDL_CreateWindow("Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ScreenSizeX, ScreenSizeY, SDL_WINDOW_SHOWN);
screen = SDL_GetWindowSurface(Window);

你可以看到只是破坏窗口并创建一个新窗口。邋but但它的工作原理。我想要的只是调整窗口大小,是否可能?

4 个答案:

答案 0 :(得分:15)

我相信您可以使用SDL_CreateWindow中的SDL_WINDOW_RESIZABLE标志来调整窗口大小。

答案 1 :(得分:9)

您可以查看维基文档:SDL_SetWindowSize

答案 2 :(得分:2)

要在SDL中调整窗口大小,请首先将其设置为标志SDL_WINDOW_RESIZABLE,然后在开关中检测窗口大小调整事件,最后调用以下方法SDL_SetWindowSize(m_window, windowWidth, windowHeight)glViewport(0, 0, windowWidth, windowHeight)

switch中,如果只需要窗口的最终大小,请使用标记SDL_WINDOWEVENT_RESIZED;如果要在第一个窗口和最后一个窗口之间的所有大小,请使用SDL_WINDOWEVENT_SIZE_CHANGED

要完成此操作,请使用新的窗口宽度和高度更新您自己的相机。

m_window = SDL_CreateWindow("INCEPTION",
    SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
    m_windowWidth, m_windowHeight,
    SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);


switch (m_event.type) {

    case SDL_WINDOWEVENT:

        if (m_event.window.event == SDL_WINDOWEVENT_RESIZED) {
            logFileStderr("MESSAGE:Resizing window...\n");
            resizeWindow(m_event.window.data1, m_event.window.data2);
        }
        break;

    default:
        break;
}


void InceptionServices::resizeWindow(int windowWidth, int windowHeight) {
    logFileStderr("MESSAGE: Window width, height ... %d, %d\n", windowWidth, windowHeight);
    m_camera->resizeWindow(windowWidth, windowHeight);
    glViewport(0, 0, windowWidth, windowHeight);
}

答案 3 :(得分:1)

Window = SDL_CreateWindow(
  "Test",
  SDL_WINDOWPOS_UNDEFINED,
  SDL_WINDOWPOS_UNDEFINED,
  ScreenSizeX,
  ScreenSizeY,
  SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
);

使用这个函数调用