Fast Graphics Under Windows

Published September 14, 1999 by Seumas McNally, posted by Myopic Rhino
Do you see issues with this article? Let us know.
Advertisement
Lots of books have been written on this subject. The bottom line for 2D graphics is to use CreateDIBSection() (consult your handy dandy Windows development environment documentation) and friends for windowed or otherwise very system-friendly fast graphics, and DirectDraw for fast full screen graphics where you get to dictate the color mode (8-bit, 16-bit, 32-bit, etc.).

The trick to CreateDIBSection() is that to actually get your bitmap to the screen, you have to jump through a few hoops. First you have to use CreateCompatibleDC() to create a Device Context to blit from (think of it as just a hunk of program that knows how to move pixels), SelectObject() your HBITMAP into it, then obtain the DC for your destination window, and use BitBlt() to blit from the created DC to the window's DC.

DirectDraw is pretty straight forward if all you want is a linear full screen framebuffer to manually throw pixels at (that's all I usually use, for compatability with as much hardware as possible). First buy a good book on DirectDraw. Then create a DirectDraw object, switch to Exclusive mode, change the screen mode to whatever you like, acquire the DDSurface object for the Primary surface, create an Off-Screen System Memory surface of the same size and bit depth to be your Back Buffer, then every frame Lock the Back Buffer surface, compose your graphics there in system memory, Unlock the surface, and do a DirectDraw Blit from the off-screen surface to the Primary surface. This works for a lot of things, and gives you the advantage of being able to quickly read pixels back from your back buffer (to do alpha-blending, additive-blending, burn effects, etc.), as reading pixels from a Video Memory surface is SLOW, and dangerous. To get more speed in certian styles of games, you can use Dirty Rectangle updating to only blit the changed parts of the back buffer to the visible primary surface (DX-Ball 2 uses this technique).

Check out the BackBuffer Page for some free source code that handles DirectDraw, CreateDIBSection, and even OpenGL windows!

Copyright 1998-1999 by Seumas McNally.
No reproduction may be made without the author's written consent.

Courtesy Of Longbow Digital Artists
Cancel Save
0 Likes 0 Comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!

Covers the basics of fast graphics in Windows using either DirectDraw or CreateDIBSection().

Advertisement
Advertisement