*Experts* Volte Posted August 3, 2003 *Experts* Posted August 3, 2003 Also, I edited your code, to change it so that it only draws in the form's Paint event (as it should be), made it so that instead of calling draw() it calls this.Invalidate(), and also turned on the UserPaint, AllPaintingInWmPaint, and DoubleBuffer styles for the form, and the FPS shot up to about 181. Still went down to about 13 at fullscreen (1600x1200). It also updated the tiles when you resize the form more smoothly; there's no "jumpy" effect. Quote
SysRq2000 Posted August 10, 2003 Posted August 10, 2003 I've just started using DirectX for my 2d games and I actually found Direct3D to be better (faster) to use than DirectDraw. The 2 most important objects are: DirectX.Direct3D.Surface and DirectX.Direct3D.Sprite. Be sure to reference both Direct3D and Direct3DX, because the Direct3D.Sprite object is a part of Direct3DX. - SysRq Quote
AndreRyan Posted August 11, 2003 Posted August 11, 2003 They're discussing whether GDI+ 1.0 or GDI+ 1.1 is faster. Everyone knows DirectX is faster but they're discussing normal Windows drawing without DirectX. Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
samsmithnz Posted August 12, 2003 Posted August 12, 2003 Is Bltbit in .NET? In my VB.NET upgrade script (I have about 50 tasks, so theres a lot of work yet to do), i seem to remember that it was one of the things it flagged as not being able to upgrade. Maybe I'm totally confused with something else... Quote Thanks Sam http://www.samsmith.co.nz
*Experts* mutant Posted August 12, 2003 *Experts* Posted August 12, 2003 Yes, you can use it. You just have to declare the api. Quote
wyrd Posted August 12, 2003 Author Posted August 12, 2003 Well, it's not part of .NET, it's part of the Windows API. It's the same 'ol BitBlt that you used with VB6. Quote Gamer extraordinaire. Programmer wannabe.
samsmithnz Posted August 12, 2003 Posted August 12, 2003 oh right I get it, and that is why it won;'t be upgraded, its unmanaged code. So is GDI the next in line? Or is this only good for drawing lines? :) Quote Thanks Sam http://www.samsmith.co.nz
*Experts* mutant Posted August 12, 2003 *Experts* Posted August 12, 2003 It has many more uses then drawing lines :). You can show images with it, draw custom controls, and all kinds of things like that. Its also good for games that dont require a lot of reources and dont have a huge number of objects to draw. Quote
aewarnick Posted August 25, 2003 Posted August 25, 2003 Here is an example of something I did, with some help from guys here: [DllImport("gdi32.dll")] //Included in 95 and later. static extern bool BitBlt( IntPtr hDest, // handle to destination DC int XDest, // x-coord of destination upper-left corner int YDest, // y-coord of destination upper-left corner int WDest, // width of destination rectangle int HDest, // height of destination rectangle IntPtr hDCSrc, // handle to source DC int XStart, // x-coordinate of source upper-left corner int YStart, // y-coordinate of source upper-left corner int RasterOpCode // raster operation code ); //------------------------------ public static void DrawBitBlt(Graphics g, Bitmap bmp, ref Rectangle destRec) { IntPtr hDC= g.GetHdc(); IntPtr hBmp = bmp.GetHbitmap(); IntPtr ImageDC= a.Api.CreateCompatibleDC(hDC); IntPtr offscreenDC= a.Api.CreateCompatibleDC(hDC); IntPtr drawBmp= a.Api.CreateCompatibleBitmap(hDC, destRec.Size.Width, destRec.Size.Height); IntPtr oldBmp= a.Api.SelectObject(ImageDC, hBmp); IntPtr oldDrawBmp= a.Api.SelectObject(offscreenDC, drawBmp); if(bmp.Size.Equals(destRec.Size)) { a.Api.BitBlt(offscreenDC, 0, 0, destRec.Width, destRec.Height, ImageDC, 0, 0, SrcCopy); } else a.Api.StretchBlt(offscreenDC, 0, 0, destRec.Width, destRec.Height, ImageDC, 0, 0, bmp.Width, bmp.Height, SrcCopy); a.Api.BitBlt(hDC, destRec.X, destRec.Y, destRec.Width, destRec.Height, offscreenDC, 0, 0, SrcCopy); a.Api.SelectObject(ImageDC, oldBmp); a.Api.DeleteObject(hBmp); a.Api.SelectObject(offscreenDC, oldDrawBmp); a.Api.DeleteObject(drawBmp); a.Api.DeleteDC(ImageDC); a.Api.DeleteDC(offscreenDC); g.ReleaseHdc(hDC); } Quote C#
OnErr0r Posted August 31, 2003 Posted August 31, 2003 I just thought I'd throw this out there. It's an example of using GDI+ CachedBitmap, which is about 3x faster than DrawImage. But probably not faster than BitBlt. CachedBitmap is really only handy when the bitmap that it is based upon is not going to change. If the base were to change, you'd have to Destroy the old and create a new CachedBitmap. And that is not very efficient.cachedbitmap.zip Quote
aewarnick Posted September 2, 2003 Posted September 2, 2003 Boy is that helpful!! I have been looking for a way to avoid using the api. Will this technique draw the image with ImageAttributes so that I can have a semi transparent image? Quote C#
OnErr0r Posted September 3, 2003 Posted September 3, 2003 I didn't test that, but hopefully the CachedBitmap inherits the transparent properties of the bitmap from which it is based. Quote
OnErr0r Posted September 6, 2003 Posted September 6, 2003 I did go ahead and test that. I just added: bmp.MakeTransparent(System.Drawing.Color.Black) And it does make the background transparent. (unfortunately my image is not an entirely black background, but oh well) So this method would work well for drawing sprites quickly too. Quote
aewarnick Posted September 6, 2003 Posted September 6, 2003 Actually I meant the whole image being semi-transparent to transparent using ImageAttributes. public static ImageAttributes TrasparentImage(int percent) { if(percent <= 100 && percent >= 0) { float matrixEl= a.Numbers.PercentToDec(percent); matrixEl= 1*matrixEl; ImageAttributes IA = new ImageAttributes(); ColorMatrix wmColorMatrix = new ColorMatrix(); wmColorMatrix.Matrix33= matrixEl; IA.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); return IA; } else return null; } This returns ImageAttributes that must be used as an argument to DrawImage. Does the CatchedBitmap have that? Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.