Phoenix13nl
2009-04-12 09:52:56
Hi, I've got a bit of a problem here. I'm creating a engine for 2D games (Without Xna or DirectX or anything like that).
After some testing I found that the best update interval was 17ms, it gave only 5% CPU usage, and a framerate of 32FPS, the max FPS was 62, but CPU usage was 100% then. the interval seems very sensitive though, just by changing it with 1ms can make up to 80% difference on the CPU, so I might need to make it auto-adjustable in some way, but that's not the problem why I'm here.
Now to display everything on the screen, im using two Graphics objects and a bitmap, in the Draw call of my engine, everything will be draw the Graphics object of the bitmap, after the drawing is done, I draw the bitmap onto the other Graphics object, which is the Graphics object of my viewport.
All of this drawing however, is done by using the Graphics.DrawImage and Graphics.DrawImageUnscaled methods. knowing the most GDI methods are slow, I'm asking, is there any faster way of drawing bitmaps, or displaying just a color onto the screen? On the internet I found that alot of people are using the GDI32 BitBlt function, when i tried this, it took 15ms, while GDI took under 1ms, I also found something about (double)BufferedGraphics, but it seemed to me that it was only used to prevent 'flickering', which I already did, and in some cases it looks like BitBlt is used for that too. Are there any faster ways???
Another problem I have, is that I want to be able to change the bitmap's color, I tried with a loop trough the bitmaps ColorPalette, but that doesnt work, and even though I can use the unmanaged way for bitmap GetPixel and SetPixel I prefer not doing so, as that has to be done for any pixel for any texture I want to draw. Anyone has a solution or should I just try my GetPixel and SetPixel functions? (Im not talking about my own methods, not the slow GDI ones).
oh, and just to show of, I also included some pixtures rendered by my Ray-Tracer im creating, the plan is to make it real-time but I guess I'll never manage :) I can rotate, scale(Not with Quaternion), and translate(Not with Matrix3 or Quaternion) the cube, and all other triangle-based primitives with my Matrix3, Matrix4, Quaternion and Vector3 classes, pretty cool xD
btw, they're in a .Zip because of the size, though I resized the're format, changing the ImageFormat f*cks up the images,
After some testing I found that the best update interval was 17ms, it gave only 5% CPU usage, and a framerate of 32FPS, the max FPS was 62, but CPU usage was 100% then. the interval seems very sensitive though, just by changing it with 1ms can make up to 80% difference on the CPU, so I might need to make it auto-adjustable in some way, but that's not the problem why I'm here.
Now to display everything on the screen, im using two Graphics objects and a bitmap, in the Draw call of my engine, everything will be draw the Graphics object of the bitmap, after the drawing is done, I draw the bitmap onto the other Graphics object, which is the Graphics object of my viewport.
All of this drawing however, is done by using the Graphics.DrawImage and Graphics.DrawImageUnscaled methods. knowing the most GDI methods are slow, I'm asking, is there any faster way of drawing bitmaps, or displaying just a color onto the screen? On the internet I found that alot of people are using the GDI32 BitBlt function, when i tried this, it took 15ms, while GDI took under 1ms, I also found something about (double)BufferedGraphics, but it seemed to me that it was only used to prevent 'flickering', which I already did, and in some cases it looks like BitBlt is used for that too. Are there any faster ways???
Another problem I have, is that I want to be able to change the bitmap's color, I tried with a loop trough the bitmaps ColorPalette, but that doesnt work, and even though I can use the unmanaged way for bitmap GetPixel and SetPixel I prefer not doing so, as that has to be done for any pixel for any texture I want to draw. Anyone has a solution or should I just try my GetPixel and SetPixel functions? (Im not talking about my own methods, not the slow GDI ones).
oh, and just to show of, I also included some pixtures rendered by my Ray-Tracer im creating, the plan is to make it real-time but I guess I'll never manage :) I can rotate, scale(Not with Quaternion), and translate(Not with Matrix3 or Quaternion) the cube, and all other triangle-based primitives with my Matrix3, Matrix4, Quaternion and Vector3 classes, pretty cool xD
btw, they're in a .Zip because of the size, though I resized the're format, changing the ImageFormat f*cks up the images,