I wrote a snippet. Its main logic just like this:
int main() {
// create a window and a texture and other initializations
// always render the texture to the center of the window
bool quit = false;
while (!quit) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
quit = true;
}
if (e.type == SDL_WINDOWEVENT) {
switch (e.window.event) {
// when window is resized, repaint the texture to the center
case SDL_WINDOWEVENT_SIZE_CHANGED: {
windowWidth = e.window.data1;
windowHeight = e.window.data2;
RenderMyTextureToCenter(windowWidth, windowHeight);
}
}
}
}
}
}
It partly meeted my requirement.I found that texture only repainted when resizing was totally done.But if I keep dragging my mouse and zoom the window, the texture will not repaint.I want my texture always keep in the center even during the resizing.How can I realize that?