• Advertisement
Sign in to follow this  

[.net] C# DirectDraw Tutorials?

This topic is 4751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Are there any good C# and DirectX resource sites out there that teach DirectDraw? Thanks!

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement