• Advertisement

Archived

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

Windows GDI SetPixelV function

This topic is 5127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am programming a full-screen game for windows. Now I have a window with opens in full-screen and it sets the resolution to 1024x768 etc. If I want to draw something I use the SetPixelV function, but it is EXTREMELY slow. Does anyone know how to put a pixel on the screen a lot faster?

Share this post


Link to post
Share on other sites
Advertisement
Thanks for your replies. If I unlock the memory, can I use VESA as in DOS? And how do I unlock the memmory or draw pixels using hardware acceleration?

Share this post


Link to post
Share on other sites
Despite appearances, my post was actually very unhelpful, as the GDI does not support hardware acceleration. You''d have to use SDL or DirectDraw for that, which would give you an increase of speed by orders of magnitude, but of course that''s not what you''re looking for.

I don''t know how to directly lock GDI pixel data... is that even possible?

professional web hosting at great prices

Share this post


Link to post
Share on other sites
<< I don't know how to directly lock GDI pixel data... is that even possible? >>

I don't think that's needed. I wrote an asteroids using Win GDI only and it runs fine (30 frames per second) on any machine I've tried it on (from Pent 2 300 Mhz to latest). Goes full screen.

Might be the resolution. Change game to 800 x 600 and see if SetPixel (vs. SetPixelV) is faster. I have zillions of (white) pixels flying around for explosions and no problems with speed in GDI. Recently added easy and hard game modes, and figured out how to compile in Release (so EXE is now 250 K vs. 450 K).

Vazteroids.cpp | EXE

Phil P

[edited by - PhilVaz on February 8, 2004 5:06:14 PM]

Share this post


Link to post
Share on other sites
The fast way to do pixel-by-pixel drawing with the Windows GDI is to use DIB''s (Device Independent Bitmaps) & DIB Sections.

These give you direct access to graphics data and can be selected into or blitted directly to DC''s.

Share this post


Link to post
Share on other sites
<< These give you direct access to graphics data >>

Yeah, I assumed he wanted to just plot pixels. If he is trying to draw a bitmap by plotting each pixel that will be extremely slow in GDI. If he is using bitmaps he should go with LoadImage into hbmp, then copying that into a bmp_dc, then blit bmp_dc to main_dc or whatever his bmp and screen dc are called. Example:

GDI bitmap demo | EXE

Phil P

Share this post


Link to post
Share on other sites
Yes, I just only want to plot pixels, not drawing bitmaps. I would try to plot pixels using SDL this week. Thank you all for your replies!

Share this post


Link to post
Share on other sites
I have not worked with the gdi forever, but if i recall, dib is a lot better than setpixels.
what you need to do is use DIBs like arm said. what this allows you to do is grab ur entire image, write directly to that memory, not plotting pixels to the screen (slow), but changing the color data in memory, and then you can draw the image to the screen with a blt. this is uber fast because you can do all of your color changing by messing directly with the image memory, and then you can draw and display it all at once.

look up setdibits and getdibits, i think these functions are now obsolete, but u should be able to find links to the modern ones on msdn.

Share this post


Link to post
Share on other sites

  • Advertisement