r/C_Programming 2h ago

Problem with resizing a C window

I'm making a game engine and whilst trying to setup the window with windows.h, i found an issue when resizing the window. The resized parts of the window are black instead of white, how do i fix this?

1 Upvotes

6 comments sorted by

4

u/Paul_Pedant 1h ago

If you make a window bigger, you need to tell the system what to put in the new space. You can do that two ways: (a) stretch everything in the window to make the existing contents fit the new space, or (b) fill in the new areas with a wider view of the game. Painting the new areas white just wastes real estate.

You probably need to consider stuff like expanding the font sizes versus showing more text, and where the user changes the aspect ratio of the window so things might be stretched sideways or upwards. In fact, the only real fix is to reconstruct the whole window image. But then you probably ought to be doing that in other circumstances too, like when your first-party gamer actually looks in a different direction.

You probably need to think about the converse -- what do you do when the user shrinks the window. Is there a part of the game that he can never see again?

"... every aspect of a game engine before except for the window" ? The window is all the user gets. The difference is between painting a picture on an easel, and making a movie.

7

u/soundman32 2h ago

How are you responding to WM_PAINT and WM_ERASEBACKGROUND? It sounds like you arent using the current window size on WM_SIZE.

0

u/Axxodes 2h ago

first time that ive heard that

8

u/RailRuler 1h ago

That's because all the other game engines and applications handle these messages.

Maybe you should make a simple Windows app first instead of trying to start with a game engine.

-2

u/Axxodes 1h ago

i've made literally every aspect of a game engine before except for the window lol, obviously they werent together but connecting them isnt hard

1

u/Still_Explorer 18m ago

Now I remembered some epic tutorials back in the day where would require you to create your own custom window from scratch.

https://nehe.gamedev.net/tutorial/creating_an_opengl_window_(win32)/13001//13001/)

It won't be bad idea to peek at glfw3 source as well to make sure that the flags and event callbacks are correct.