我正在尝试遵循youtube上的教程来学习SDL。但是当我尝试使用SDL_GetWindowPosition()和SDL_GetWindowSize()时,似乎并没有更新int *。
这是我的代码:
#include <iostream>
#include "include/SDL2/SDL.h"
using namespace std;
void CreateWindow(SDL_Window *win){
win = SDL_CreateWindow("Title",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
800, 600,
SDL_WINDOW_RESIZABLE);
if (win == nullptr)
cout<<"Could not create window.\n"<<SDL_GetError()<<'\n';
}
void QuitWindow(SDL_Window *win){
// SDL_Delay(3000); // 3 seconds
SDL_DestroyWindow(win);
SDL_Quit();
}
int main(int argc, char* argv[]) {
// initialize window
SDL_Init( SDL_INIT_EVERYTHING );
SDL_Window *win = nullptr;
CreateWindow(win);
// main loop
SDL_Event event;
bool run = true;
while (run){
int x, y, w, h;
while (SDL_PollEvent(&event)){
if (event.type == SDL_QUIT){
run = false;
QuitWindow(win);
break;
}
}
SDL_GetWindowPosition(win, &x, &y);
SDL_GetWindowSize(win, &w, &h);
cout<<x<<','<<y<<" ; "<<w<<','<<h<<endl;
}
return 0;
}
cout的结果类似于: 1048591,1872715060; 1,1965549662
我试图删除主循环,仅创建窗口-> getwindowposition-> getwindowsize->退出。但是仍然得到类似的结果。我该如何解决这个问题?