SetPixel is too slow!!!
In Win32 programming is there a faster way to change i specific pixel of a DC than SetPixel? Thx
-----------------------------------------------
Here comes the Thnikkaman!
How fast do you need to be able to change that pixel? The only way it would be too slow is if you are going to change a lot of pixels. If you want to make larger changes to an image, then work out a double buffering scheme for your program: Draw to an array and then use SetDIBitstoDevice.
The DIBBits version, in plain VB. Remember to declare the API function calls and the BITMAP definition (use the API Text Viewer tool).
For C/++... you need to allocate the memory and keep a BITMAP structure handy. The BITMAP structure only describes the drawing surface, it doesn''t hold the pixel data. Call GetBitmapBits only once to initialize the array and fill the BITMAP structure. Then call SetBitmapBits and send a message to (I think) the default WM_PAINT handler to redraw (Not sure on that bit, it''s been a while).
Public Function GetBitmapArray(ByVal bDC As Long, bBytes() As Byte) As BITMAP Dim tBitmap As BITMAP, nWd1 As Long, nHt1 As Long Call GetObjectAPI(bDC, Len(tBitmap), tBitmap) nWd1 = tBitmap.bmWidthBytes nHt1 = tBitmap.bmHeight ReDim bBytes(0 To nWd1 - 1, 0 To nHt1 - 1) Call GetBitmapBits(bDC, nWd1 * nHt1, bBytes(0, 0)) GetBitmapArray = tBitmapEnd FunctionPublic Sub SetBitmapArray(ByVal bDC As Long, bBytes() As Byte, tBitmap As BITMAP) Call SetBitmapBits(bDC, tBitmap.bmWidthBytes * tBitmap.bmHeight, bBytes(0, 0))End Sub
For C/++... you need to allocate the memory and keep a BITMAP structure handy. The BITMAP structure only describes the drawing surface, it doesn''t hold the pixel data. Call GetBitmapBits only once to initialize the array and fill the BITMAP structure. Then call SetBitmapBits and send a message to (I think) the default WM_PAINT handler to redraw (Not sure on that bit, it''s been a while).
HRESULT GetBitmapBits( HDC hdc, BITMAP * bm, BYTE * pixmap ) { GetObjectAPI( hdc, sizeof(BITMAP), bm); return GetBitmapBits( hdc, bm.bmWidthBytes * bm.bmHeight, pixmap );};HRESULT SetBitmapBits( HDC hdc, BITMAP * bm, BYTE * pixmap ) { return SetBitmapBits( hdc, bm.bmWidthBytes * bm.bmHeight, pixmap ); };
Or you could just use DirectDraw or something instead of GDI, which just plain isn''t fast enough to write games in.
There is no good way of drawing pixels in GDI. Windows was not designed with game making in mind. If you want to get decent frame rates you''ll need a API such as DirectX or SDL(see my signature).
--------------------------------------------------------------------------------
[C++ Reference | Java API | SDL Home Page | Lua Scripting Language | Python Scripting Language |
Chris Taylor''s Design Document (Downloadabe MS-Word Only) | Blitz Basic Homepage ]
--------------------------------------------------------------------------------
[C++ Reference | Java API | SDL Home Page | Lua Scripting Language | Python Scripting Language |
Chris Taylor''s Design Document (Downloadabe MS-Word Only) | Blitz Basic Homepage ]
Check out that link for SDL in Onemind''s sig. It''s sexay, and politically correct!!! (and by politically correct I mean easy to use and works on Linux AND Windows).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement