DirectDraw Directly Surface Pixel Write

Im developing a aplication where I need to paint a bitmap (320x240) on the window a lot of times per second. I was using the drawdib function because I receive a pointer to a RGB 24 Bitmap [Byte  Pixels[240*320*3]; ) Now I want to make my application do this work using DirectDraw. The way I found to do that was getting a DC to the DirectDraw surface and paint the bitmap on the DC using StrechDIBits which is a very slow function. Im wondering If there is a way to do that copying directly the bits into the surface, like some examples that I saw that lock the surface and use the LpSurface pointer to manipulate pixels. I tried do to that but a did not get a working code. Help me please.
MauricioMaiaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chofreitherCommented:
Well, it's pretty much as you said: you lock the surface (though, if I recall correctly, this isn't strictly necessary in windowed mode, but it can't hurt), get the pointer to the pixels and start writing to it; and of course unlock the surface again when you're done.

What kind of problem did you have trying to do that? One thing to note is that the width of the pixel buffer is sometimes not the visible width, but rather surfacedesc.lPitch. Another problem might be that depending on the buffer format, you might have to do pixel format conversion (eg from 24 bits to 16 bits, or whatever).

For a tutorial on writing pixels to a DD surface, look here: http://www.gamedev.net/reference/articles/article588.asp

Clemens
MauricioMaiaAuthor Commented:
Thanks chofreither,

I'm having just one problem now, I think Its a simple thing to solve but I never had to do that and the examples that I found did not work. My surfaces are created with 16 bits and I need to make then 24 bits. How do I create a 24 bits surface?
chofreitherCommented:
The surfaces you create in windowed mode always have the same depth as the current desktop display mode, so you have to write conversion routines for different pixel depths. This article should help you greatly: http://www.gamedev.net/reference/articles/article538.asp

Also look at this tutorial, especially the "Running windowed" section: http://www.gamedev.net/reference/articles/article608.asp.

Hope that helps,
Clemens

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.