Posted By: Pon | Apr 30th, 2006 @ 11:53 PM
page 1 of 1
Comments: 7 | Views: 4070
Pon
Pon

I'm creating a software renderer. Currently, for each and every frame, I use the SetPixel method of the Bitmap class to update the colour, then put that on the form. However, I dislike doing it this way for obvious reasons. How can I set the colour of a pixel on a Form?
Khamul
Khamul
Death by Escape Key

In the OnPaint() event you could use e.Graphics.[whatever] to draw a one pixel rectangle or line.

Khamul
Khamul
Death by Escape Key
Yes.

See, I'm a great lot of help, aren't I? Tongue Out
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
The only really efficient way to draw to the screen in Windows is using DirectX.

Or you could try locking a bitmap and writing directly to its (unmanaged) memory, then displaying the bitmap.
Pon wrote:
 I'm creating a software renderer. Currently, for each and every frame, I use the SetPixel method of the Bitmap class to update the colour, then put that on the form. However, I dislike doing it this way for obvious reasons. How can I set the colour of a pixel on a Form?


What are these obvious reasons? Speed?
If your program runs in full trust you can lock the image and directly paint to the memory using pointers. Besides using DirectX you will not find a faster way to do this:

Bitmap bm = new Bitmap (1000, 1000);
BitmapData data = bm.LockBits (new Rectangle (1000,1000), ImageLockmode.ReadWrite, PixelFormat.Format32bppRgb);

byte* firstByte = (byte*)data.Scan0.ToPointer ();

Don't forget to unlock once you are done...
Pon wrote:

Yeah, speed. For high resolutions (1600x1200), it takes over a second to copy the entire image.


Then use the pointers to directly draw the pixels. In extreme cases this can make your code 20 to 50 times faster...
page 1 of 1
Comments: 7 | Views: 4070
Microsoft Communities