Sign in to follow this  
adprice

Best way to do animation

Recommended Posts

This isn't a game question per se, but this place seemed like a good place to ask about this. I'm doing an application where I get streaming image data (16 bits per pixel, grayscale). I package the data into frames and then want to display those frames at some frame rate. Right now I have a timer and every time it times out I display a new frame in my window. I've looked at various DirectX and GDI stuff but I can't figure out how to take existing data and display it. Anyone have any suggestions on an easy way to do this? The data is just in a WORD array. I feel like I should just be able to pass a pointer to some function but my understanding of graphics programming is pretty naive... Thanks, Andrew

Share this post


Link to post
Share on other sites
For GDI, you want to look at CreateDIBSection, which creates a Device-Independent Bitmap or DIB that you can write to. You'll need to ensure that your data is in a GDI-appropriate data format; DIBs use a BITMAPINFO structure and its associated BITMAPINFOHEADER to specify image format.

For DirectX, you'll want to create a texture, specifying the correct format (probably D3DFMT_X1R5G5B5), lock it, and then write to the data pointer of the corresponding D3DLOCKED_RECT structure. (Don't forget to unlock before rendering again.)

Let us know how it goes.

Share this post


Link to post
Share on other sites
Thanks for the quick reply. I'm still a little confused though.

Say I'm using GDI...
In my BITMAPINFOHEADER I define the following
biHeight = 400
biWidth = 400
biBitCount = 16
biCompression = BI_RGB (I want uncompressed even though my image is grayscale)
biClrUsed = 0 (little confused about what this does...)

But, the MSDN docs say that if you use 16 bits with BI_RGB compression then the bmiColors value in the BITMAPINFO structure must be NULL. This is where I get lost because I thought that I had to define my own palette using the bmiColors value so that my image would be displayed as grayscale. In other words, how do I get 2^16 shades of gray color?

Thanks,
Andrew

Share this post


Link to post
Share on other sites
Quote:
Original post by adprice
Hah, the Google-fu isn't so weak, I just don't want to pay for the answer.


Hi, try this:
Search for "How can I create a 8bit grayscale bitmap?". You'll see the same link... now click to see the cached version instead. Then, just scroll to the bottom.

Hope it helps ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by adprice
Hah, the Google-fu isn't so weak, I just don't want to pay for the answer.

Scroll down. Experts Exchange is hilarious in that they put up all this for-pay stuff, but the answers are completely exposed at the bottom of the page. Yes, even outside the Google cache.

Edit: Hmm. It appears it's just the Google link that busts through their money grubbing. Here. I wonder how long that will last.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this