[.net] C# DirectDraw Tutorials?
DirectDraw ended at 7.0 simply because there was no need to upgrade it anymore. I came across a good site for you get started. I'd learn 2d before I get into 3d. Plus it teaches the fundlamentals to what DirectX is all about.
Good luck,
Phil
Click
Good luck,
Phil
Click
Using DirectDraw should be fine if you don't need any modern capabilities.
Here's a simple tutorial:
1) Open references and add Microsoft.DirectX and Microsoft.DirectDraw.
2) Add "using" statements to the top of your program for these (i.e., 'using Microsoft.DirectX')
3) Example Init code:
4) Example load sprite code:
5) Example main routine: (you probably already know this one)
6) Getting the backbuffer (requires primary surface from step 3, you will draw to this):
7) Drawing sprite (requires primary surface, sprite, and backbuffer from steps 3, 4, and 6)
8) Paint routine -- override the form's method(depends upon variables created in previous steps)
Put all those steps together and you have yourself a C# DirectDraw app.
Here's a simple tutorial:
1) Open references and add Microsoft.DirectX and Microsoft.DirectDraw.
2) Add "using" statements to the top of your program for these (i.e., 'using Microsoft.DirectX')
3) Example Init code:
//Init deviceDevice device = new Device();device.SetCooperativeLevel(this, CooperativeLevelFlags.FullscreenExclusive); // or whatever mode you want.. 'this' refers to parent form. device.SetDisplayMode(800, 600, 16, 0, false); // or whatever... 800x600, 16 bit//describe surfaceSurfaceDescription description = new SurfaceDescription();description.SurfaceCaps.PrimarySurface = true;description.SurfaceCaps.Flip = true;description.SurfaceCaps.Complex = true;description.BackBufferCount = 1;//create primary surfaceSurface primary = new Surface(description, device);
4) Example load sprite code:
Surface sprite = new Surface("whatever.bmp", new SurfaceDescription(), device);ColorKey ck = new ColorKey(); // if you want a color key for transparency.sprite.SetColorKey(ColorKeyFlags.SourceDraw, ck);
5) Example main routine: (you probably already know this one)
static void Main(){ using (Form1 form = new Form1()) { form.Show(); form.Init(); // calls step 3 and probably then step 4 Application.Run(form); }}
6) Getting the backbuffer (requires primary surface from step 3, you will draw to this):
SurfaceCaps caps = new SurfaceCaps();caps.BackBuffer = true;Surface backBuffer = primarySurface.GetAttachedSurface(caps);
7) Drawing sprite (requires primary surface, sprite, and backbuffer from steps 3, 4, and 6)
//below: use whatever size and positions are necessary.backBuffer.DrawFast(xPosition, yPosition, spriteSurface, spriteSize, DrawFastFlags.DoNotWait | DrawFastFlags.SourceColorKey);
8) Paint routine -- override the form's method(depends upon variables created in previous steps)
protected override void OnPaint(Forms.PaintEventArgs e){ backBuffer.ColorFill(0); // fill your background //Draw Sprite here (previous step) primarySurface.Flip(backBuffer, FlipFlags.DoNoWait); // flips the backbuffer to the primary surface this.Invalidate();}
Put all those steps together and you have yourself a C# DirectDraw app.
Quote:Original post by philvaira
DirectDraw ended at 7.0 simply because there was no need to upgrade it anymore. I came across a good site for you get started. I'd learn 2d before I get into 3d. Plus it teaches the fundlamentals to what DirectX is all about.
Good luck,
Phil
Click
Thanks! I was looking for tutorials like the per pixel detection and more advanced DDraw topics.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement