wyrd
Well-known member
After pain staking hours figuring out how all this lovely GDI+ and Win32 GDI stuff worked and interacted together, I finally came up with a basic class library which you can just plug-n-play for faster drawing. Obviously theres room for improvement as it only implements a few basic Win32 functions for drawing, but its already proved useful in the game Im creating. If you find any bugs let me know.
Before getting to how to use the class library (its really a no-brainer), heres my initial tests on my 800mhz athlon, G2 MX, 256mb of RAM rig (yeah, nothin special).
Draw Area: 640x480
Images Drawn Per Frame: 336
Size Of Images: 32x32
FPS: 43
Increase Over GDI+: ~14 FPS
Draw Area: 480x360
Images Drawn Per Frame: 176
Size Of Images: 32x32
FPS: 74
Increase Over GDI+: ~25 FPS
I originally tried w/ letting .NET handle the backbuffer and all that with SetStyles. Unfortunately I didnt quite as good of a FPS boost. It seems like in this case youre better off doing your own backbuffer.
Okay, so heres how to use it.
Just as easy as GDI+ (well, maybe not, you need to create your own backbuffer), and gives more speed. Ohhh yeah!
Ah, and one thing of note; not sure if I should of created a new thread for this, but it didnt exactly fit the topic of my other two posts (one was asking for help and the other was about speeding up GDI+). If this should of been posted in one of my other two threads then I apologize for wasting space. That wasnt my intention.
Before getting to how to use the class library (its really a no-brainer), heres my initial tests on my 800mhz athlon, G2 MX, 256mb of RAM rig (yeah, nothin special).
Draw Area: 640x480
Images Drawn Per Frame: 336
Size Of Images: 32x32
FPS: 43
Increase Over GDI+: ~14 FPS
Draw Area: 480x360
Images Drawn Per Frame: 176
Size Of Images: 32x32
FPS: 74
Increase Over GDI+: ~25 FPS
I originally tried w/ letting .NET handle the backbuffer and all that with SetStyles. Unfortunately I didnt quite as good of a FPS boost. It seems like in this case youre better off doing your own backbuffer.
Okay, so heres how to use it.
C#:
GDIBitmap _image;
GDIBitmap _buffer;
Graphics _main;
public Constructor()
{
// Load images.
_image = new GDIBitmap("hi.bmp");
// Create buffer.
_buffer = new GDIBitmap(this.Width, this.Height);
// Create main drawing area.
_main = this.CreateGraphics();
}
// Pretend this is a dispose pattern.
public void Dispose() {
_image.Dispose();
_buffer.Dispose();
_main.Dispose();
}
// Some event to start the loop.
public void Event()
{
while (true) {
_drawBuffer();
_drawMain();
this.DoEvents();
}
}
private void _drawBuffer()
{
GDIDraw.BitBtl(_buffer.DeviceContext, 0, 0, _image.Width, _image.Height,
_image.DeviceContext, 0, 0, RasterOperations.SrcCopy);
}
private void _drawMain()
{
IntPtr dcMain = _main.GetHdc();
GDIDraw.BitBlt(dcMain, 0, 0, _buffer.Width, _buffer.Height,
_buffer.DeviceContext, 0, 0, RasterOperations.SrcCopy);
_main.ReleaseHdc(dcMain);
}
Just as easy as GDI+ (well, maybe not, you need to create your own backbuffer), and gives more speed. Ohhh yeah!
Ah, and one thing of note; not sure if I should of created a new thread for this, but it didnt exactly fit the topic of my other two posts (one was asking for help and the other was about speeding up GDI+). If this should of been posted in one of my other two threads then I apologize for wasting space. That wasnt my intention.
Attachments
Last edited by a moderator: