Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted
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.
Posted

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

Posted
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.
.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?
Posted
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.
Gamer extraordinaire. Programmer wannabe.
  • *Experts*
Posted

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.

  • 2 weeks later...
Posted

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);
		}

C#
Posted
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

Posted

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?

C#
Posted

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.

Posted

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?

C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...