int array to HDC?!

Started by
3 comments, last by RDragon1 18 years, 11 months ago
Howdy ya'll! First off I'd like to apologize if this topic has already been addressed! The search isn't working for me, and the HDC topics I've seen haven't really answered my question! Anywho, my situation is that I'm moving an engine of mine over to work in a window, and I've got an array of ints that store the colors to be displayed. My problem is that I have no idea how to go from an int array to an HDC, or if that's what I'm even supposed to do! I tried using SetPixel and SetPixelV 1024*768 times per frame, and the results weren't that great. (I wasn't expecting much, since that many function calls is never a good thing - I just wanted something to make sure everything up until the display part was working OK) I'm very new to Windows programming, and the places I've looked haven't really answered my question! Thanks bunches! Gorth
Advertisement
Using GDI (the rendering system that HDCs are a part of) for game graphics is a bad idea. Instead, use DirectX, OpenGL, SDL, or Allegro. Any of them will be much faster than GDI for what you are doing, plus some of them do more than just graphics, and all of them will allow you to make a fullscreen application, take advantage of hardware acceleration in some form, etc.. That said, if you really, really want to use GDI, the way I would do it would be to create a bitmap and memcpy() the values from your array to it each frame, then draw it on the window. This will still be very slow, it will just be a lot faster than using SetPixel() (I think...).
I agree Mumpo when it comes to using these libraries.
If you still want to use GDI, you can create an offscreen memory DC from the bitmap and bitblt this on the window's DC.
If you do want to use then you need to keep your bitmap data in a format that GDI works with and then you can use BitBlt and friends instead of copying each pixel one-by-one. Your best bet is probably to use a DIB section.
-Mike
SetDIBitsToDevice is your friend, in this situation... you'll need to set up some kind of BITMAPINFO structure, too.

This topic is closed to new replies.

Advertisement