Advertisement

Memory buffer to Surface?

Started by November 19, 2000 10:23 AM
9 comments, last by vbisme 24 years, 2 months ago
Let''s say I load a bitmap file and read the data into "Buffer". Then let''s say I have a DirectDrawSurface, "mySurface". Could I blit the buffer onto the surface directly? What about using memcry()? Or what do I need to do?
No, DirectDraw blit only works between surfaces. For a GDI blit, you would need to select your bitmap into a device context, and then blit to a DC taken from the surface.
Alternatively you could lock your surface and write the pixels directly.
Advertisement
with dx7 when you lock a surface you can get a pointer to the linear frame buffer. As long as the surface & bmp formats are exactly the same, you could pass that pointer to the bmp loader and load the bmp directly to the surface.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:
with dx7 when you lock a surface you can get a pointer to the linear frame buffer. As long as the surface & bmp formats are exactly the same, you could pass that pointer to the bmp loader and load the bmp directly to the surface.


In the unlikely event that the pixel formats are the same, you still cannot guarantee that the surface has the same pitch as the bitmap, so I would avoid using this method.
TwoFlower, what method do you then recommend?

Oh by the way, how do you convert bitmaps between different bpp(8, 16, 24, 32, etc.)?
If you''re using DirectX 7, then use the utility library texture functions to load your bitmap.
If not, use LoadImage and then blit from a DC to the DC of the surface.

Both methods will do the conversion for you (as well as scaling - The former will also do filtering and mipmaps if you ask nicely)
Advertisement
Well actually, I''m not loading the bitmap from a ".bmp" file. I''ve packed all my ".bmp" files into a custom file I''ve created.
IIRC the utiltility library functions will accept bitmaps in memory as well as from files, other than that, you can still create a DIB section and blit it to the surface using GDI.
Just lock the surface and memcpy each line from your buffer into the surface. Its not as nice as doing one memcpy for the whole thing but this way you can adjust for different surface pitches.
For converting between formats youre gonna have to do each pixel individually, well you could use mmx and do packed operations to process a few pixels at once but why waste the time coding it this is only going to be done at load time.

Josh
Sorry, how do you memcry line by line? I''ve heard of pitch, but don''t know exactly what or how to manipulate around them.

This topic is closed to new replies.

Advertisement