[.net] C# DirectDraw Tutorials?

Started by
8 comments, last by dohtem 19 years, 2 months ago
Are there any good C# and DirectX resource sites out there that teach DirectDraw? Thanks!
Advertisement
DDraw is deprecated, use D3D. Tutorials on Managed DirectX come with the DX SDK.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

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
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:

//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.
Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.
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.
Doh!
Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.
Sorry mate. I know how to do DirectDraw stuff like setting up the device...I am having trouble with stuff such as restoring surfaces on an alt-tab and such.
I reiterate: doh!
Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.
Ok then! ... erm...yeah...
Here are a few good tutorials.
Text

This topic is closed to new replies.

Advertisement