I recently saw (don't remember where, may be on a site related to OpenGL) a screen with 4 parts, each displaying a different thing. Hence the question that came to me was how would I do that in GDI? And some animations would be fun too.
As a beginner, I started to Google around (may be not enough) but didn't find what I really had in mind. Sure MSDN has a lot of stuff and I started to read it, but eh, it was time to gather the pieces and start programing.
By now, my GDI beginner's mantra is:
- Nothing magical
- SetPixel does it all
- Nothing voodoo
- BitBlt does it too
Once it's clear that multiple display is just a matter of selecting coordinates where to place pixels, things take an easier turn. Playing around with BitBlt, StrechtBlt (for scaling), SetPixel (for rotation, haven't yet tried PlgBlt) is fun ... when you know ... but when you begin you surely would like to get encouraged without being overwhelmed with tones of details sometimes hard to fathom.
I'd like to try here a little analogy between the drawing process with GDI and the real world.
Get a device context (think of it as a drawing surface)
|Take a sheet of paper (from the copy machine down the corridor)|
|Load an image (bunch of bits) in memory|
Choose an image that goes through your mind
|Transfer the bits (BitBlt) from the memory to the video card frame buffer (its RAM) for display ||Transfer from your mind to the sheet of paper|
|Restore objects borrowed to the system (avoid GDI objects/memory leaks)||Give your co-worker his golden pen back.|
Not being my intention to dissert on windows programming and the message pump, I would just say that the
message is where to put the code to get started as the Win 32 project template under VS 2010 kindly invites to.
Animations lie on timers and on displaying at a different coordinates (or displaying something else).
The trick is just to declare the timers when Windows creates the window (under the
message) and unset them when (just before) the window is destroyed. I preferred to use callback functions rather than dealing with the
The figure above shows a repeated pattern in the upper left quadrant, a scaling in the upper right quadrant, a rotation in the lower left quadrant and a scrolling text in the lower right one. Animations are toggled by the SPACE bar.
That's it, apart may be from the small rotation matrix, the rest of the code was pretty straightforward.
Althought it's perfectible, I'd like to think of it as a nice starting point that might give the desire to explore game programming.
Any comment, improvement, constructive critic is welcome. Till then, happy coding fellow beginners.