Sign in to follow this  
Krisc

[.net] C# DirectDraw Tutorials?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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 device
Device 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 surface
SurfaceDescription description = new SurfaceDescription();

description.SurfaceCaps.PrimarySurface = true;
description.SurfaceCaps.Flip = true;
description.SurfaceCaps.Complex = true;
description.BackBufferCount = 1;

//create primary surface
Surface 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this