Skip to main content
gamedev.net
🔒 Locked

Fast Pixel Operations

Started by FrancoisSoft Dec 14, 2002 at 4:45 PM 2 replies 500+ views
Original Post
FrancoisSoft
FrancoisSoft
I just finished making my "Chrome Machine" object. I ran it and it seems to work pretty well except it''s TOO SLOW! In writing this object I used the GetPixel() and SetPixel() operations but later I found out that they''re too slow. I then used SetPixelV() because it''s supposedly faster and it was when I tested it! However, it wasn''t fast enough to be implemented in a game. I would like to know if there are any libraries that provide fast pixel operations. I don''t want things that deal with buffers. I want to deal with the pixels directly from the device context. I don''t know assembly so I wouldn''t be able to write a super fast pixel function or even a decent one. I would appreciate it if you could help.
rotos
rotos
You should check out CreateDIBSection(), it will allow you to create a bitmap that you can access as an array. Then you can use BitBlt to draw to the screen. Any GetPixel or SetPixel type function will be way to slow for just about anything.
JonnyQuest
JonnyQuest
You could just put image data into your own dynamically allocated memory and simply use pointers to modify the contents. When you''re done, just copy it all to where you''Re going to use it - directdraw surface, direct3d/opengl texture, GDI bitmap.

- JQ
Full Speed Games. Are back.
~phil
Burning_Ice
Burning_Ice
i agree with the others. there''s just no way around working with buffers when you want speed.
the way i do it for my software engine under win32 (and i heard from someone doing winamp plugins the same way) is by creating a memory dc compatible with your screen, and select an empty bitmap into it (which you get with CreateCompatibleBitmap).
now you can access this memory dc like a backbuffer and copy your internal buffer with SetDiBits to it(but remember that it uses BGR format and not RGB, and is bottom-up) and then happily BitBlt this to any visible DC

of course you can just roll your own SetPixel function which sets individual pixels on your internal buffer. This will be a lot faster then the windows SetPixel function, but if you need realtime speed you''d be better of by accessing the buffer directly since you wouldn''t have the overhead of calculating the buffer position for each pixel individually each time even if you are accessing it sequentially.



Runicsoft -- home of my open source Function Parser and more

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.