Archived

This topic is now archived and is closed to further replies.

rowbot

DDRAW newbie question

Recommended Posts

hi I''ve created my Surface and got my Device Context and now I''m not sure what to do with them. I want to draw whole frames with individual pixels. Right now i''m using SetPixelV but its goin so slow I can see it drawing, even in 320x200. What''s the right way to write to screen memory and the best way to handle colors? correct me if I''m wrong but I expected to get a speed *increase* by switching to windows from dos. ro

Share this post


Link to post
Share on other sites
As better way to draw each individual pixel (By the way I know about this because I''m building a game which has one of those mini-maps, and I was doing the same thing, you could watch it drawing!), is to lock your back buffer. Then use the address returned to set each pixel. For example:
If your using 16bpp you would place one word in memory for every pixel you want to set. Now I only program in assembler so I can''t give you any code, but look around for some examples of this. Basically you want to:
1.) Lock backbuffer
2.) Draw every pixel
3.) Unlock backbuffer
4.) Flip to primary

Hope this helps!
- Ben

Share this post


Link to post
Share on other sites
yeah, you definitely don''t want to use GDI with the DC you can get from the surface if at all possible.
call ddsurface->Lock and use the lpSurface member of the DDSURFACEDESC (or DDSURFACEDESC2) structure to access the video memory, then unlock when done. don''t forget to use the pitch as the width of the memory.
not sure on this, but it may even be faster to do this operation on an offscreen surface then blit to the primary instead of drawing directly to primary.

have fun,
crazy166

some people think i'm crazy, some people know it

Share this post


Link to post
Share on other sites
ooh, sorry. if you''re drawing the entire screen a pixel at a time, definitely lock the backbuffer and flip. my offscreen surface comment was meant for if you were only using single pixels to draw a single object or something.

crazy166

some people think i'm crazy, some people know it

Share this post


Link to post
Share on other sites
Hi

Maybe you don''t need it, but in the case you do :
If you need to draw one background, and then some Objects on to that Background, create one surface with the Background, and blit that to the Backbuffer, and only draw smaller Objects on an PerPixel Basis (The way the others mentioned).
You always have an advantage, if you copy a whole Block of Pixels to an Surface (Back or Frontbuffer).

Lars

Share this post


Link to post
Share on other sites