Upload
-
View
229
Download
0
Embed Size (px)
Citation preview
8/14/2019 DirectX 9
1/41
DirectX
:-:
-DirectX- (SDK)Microsoft Visual Studio.Net-
:-API-DirectX-HAL-DirectX-
:DirectX-DirectD-PresentParameters-Device-
:Onpaint-()Main-
:Microsoft VisualDirectX-
Studio.NetWindows Application-
DirectX-
8/14/2019 DirectX 9
2/41
:- Vertexe
- Position Vertexes
- Transformed Vertexes:
TransformedVertexes-TransformedColored-
:PositionColoredVertexes-Camera-
:Translation-Rotation-
:Scaling-RotationTranslationMatrix-
Scaling:
Vertex Math-Vertex Buffer-
:Texture-Vertex-
:Lighting-Mesh-
Font-
8/14/2019 DirectX 9
3/41
:
-
- - DirectX (SDK)- Microsoft Visual Studio.Net
:
,
,,
, )(
( .(
(
,,, OOP), .
,,,
.
C#,.
.
:
DirectX SDK (Software Development Kit)
Microsoft Visual Studio.Net
8/14/2019 DirectX 9
4/41
SDKDirectX
:html.,news/de.winfuture.www://http
DirectX SDK (dxsdk.exe, KB, englisch).
Install... :
8/14/2019 DirectX 9
5/41
Net.Microsoft Visual Studio
... (Next).
8/14/2019 DirectX 9
6/41
:-- API
- DirectX - HAL- DirectX
----------------------------------------------
:
,
, ,(GraphicsCard, Video Card, Video Board, Video Display Board, Display AdapterVideo Adapter, Graphics Adapter),)(
((Mother Board,
, ,
dfx voodoo
,(Graphics Pressing Units (GPUs((Processor ,
, GPU.
:NVIDIAGeforce
ATI
-------------------------
)API(Application Programming Interface
. ((Operating System
8/14/2019 DirectX 9
7/41
:((textbox, *****, font, color, button,(Createwindow, SetwindowText((Functions
ExitWindow, TextOut, Copyfile)
((User, Gdi.dll, Kernel ((FontData Structure
.
:: win Bit
: win Bit ((User, Gdi.dll, Kernel,
: win Bit win
, Window Serverwindows XP
: Winfix ) windows Vista) Garbage.Net
Collector System (GLR) )~( Destructor,
GUI Avalon ,),(
.,
------------------------------
DirectX
8/14/2019 DirectX 9
8/41
(Graphics Language), DirectX OpenGl
GDI QuickDrow .
DirectXAPI, DirectX,DOS,
, ViewPoint ObjectTransformationLightingTexture (
( ,Low Level API
DirectX BitGamma Support, .Net C# VB.Net.
------------------------------
)HAL(Hardware Abstraction Layer
(DirectX) Hardware (
( Software ().
8/14/2019 DirectX 9
9/41
....
DirectX.
, DirectX.
DirectX .
:
()
,((DirectX
.
---------------------------- DirectX
(Name Space) .,
DirectD : .(D()(
DirectDraw : DirectD.(D(
DirectSound :.DirectPlay :
Network.(Client - Server).DirectInput :
Joystick.AudioVideoPlayback : Multimedia
.
8/14/2019 DirectX 9
10/41
:
- DirectX- DirectD
- PresentParameters- Device
----------------------------------------------------------------------------------
DirectX
: C++"You Game Programmer"
Coutiostreaminclude . iostream Cout.
C# DirectX,Microsoftusing
Namespace (DirectD, DirectPlay, DirectSound,..etc).:
, ,..
8/14/2019 DirectX 9
11/41
using Microsoft DirectX Direct3D DirectSound .. Classes ( ) Properties ().
Direct3D
DirectX ,
:: DirectX Direct3D
:
using Microsoft.DirectX.Direct3D;using Microsoft.DirectX;
: DirectX . Direct3D Class PresentParameters Class Device.
Class : PresentParameters
Class (Property) :Windowed : )( Windows Application , true. false fullscreen
SwapEffect : , :
Page Flipping: :SwapEffect.Flip ;
.((Tow Screen
x ) x x = )
8/14/2019 DirectX 9
12/41
)((a(,((
,(b(.
Page Copying: :SwapEffect.Copy ;
)((a(,((
((Copy,(b(
.
8/14/2019 DirectX 9
13/41
Discarding :SwapEffect.Discard;
,
. (, .(
(AutoDepthStencilFormat ,EnableAutoDepthStencil)
Depth Buffer Z Buffer W Buffer
:,
8/14/2019 DirectX 9
14/41
(BackBufferCount, BackBufferFormat , BackBufferWidth,
BackBufferHeight )
) Buffer)
.
, DirectX Buffer RAM
,(a(
((Buffer ( ,(b (Buffer)(RAM) ....
8/14/2019 DirectX 9
15/41
BackBufferCount Buffer , Buffer
. BackBufferCount
BackBufferFormat Buffer (Full screen)
Buffer BackBufferWidth BackBufferHeight
: Class Device.
Class DirectX :
: , ,
(ID Number),
DirectX .:
:Device (0, , , , )
:, : Software (
( (CPU). Hardware (GPU). Reference Debugging SDK DirectX
Hardware CPU.
:
Device (0, DeviceType.Hardware ,, , )
8/14/2019 DirectX 9
16/41
: DirectX ,
(this) . :
Device (0, DeviceType.Hardware , this, , )
: Vectors ( ) :
SoftwareVertexProcessing Vectors Central Processing Unite (CPU). HardwareVertexProcessing Vectors (GPU), .
MixedVertexProcessing : CPU GPU.
HardwareVertexProcessing MixedVertexProcessing , Vectors , SoftwareVertexProcessing .
:Device (0, DeviceType.Hardware , this, SoftwareVertexProcessing , )
: Class PresentParameters Class Device PresentParameters Device ( OOP).
:Device (0, DeviceType.Hardware , this, SoftwareVertexProcessing ,
Object- PresentParameters )
------------ --- ------------------------ --- ------------
:
:public void ondevice()
{
8/14/2019 DirectX 9
17/41
PresentParameters pp = new
PresentParameters();
pp.Windowed=true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16;
device = new Device(0, DeviceType.Hardware,
this, CreateFlags.SoftwareVertexProcessing, pp);
}
... ..
((function ondevice() PresentParameters device
8/14/2019 DirectX 9
18/41
:
Onpaint-()Main-
()OnPaint
:, ,
, ((Scan
. ,
Buffer SwapEffect ClassPresentParameters.()
OnPaint() ClassWindows Form(Built In).
,(Event) PaintEventArgs
::
protected override void OnPaint(System.Windows.Forms.PaintEventArgs
e)
{
....
....
}
:
.. ((OnPaint((parameter Buffer
.:
)) seconds .. ... .., ....
seconds..,
(Function)(OnPaint) .
8/14/2019 DirectX 9
19/41
.......)(
...).. ( , Clear.
.
((Clear Buffer :
:device.Clear (.. , .., ..,..)
Clear((function(parameter) :
((Clear:
:device.Clear (ClearFlags.Target , .., ..,..)
ClearFlags.Target : Back Buffer( SwapEffect
(((Back Buffer((Front Buffer
ClearFlags.ZBuffer: Z Buffer (.(
ClearFlags.Stencil : Z Buffer ((
((Effects Pixel.
,: Buffer
Color,.(...,,,(
:device.Clear (ClearFlags.Target ,Color.Red , ..,..)
: Buffer
8/14/2019 DirectX 9
20/41
:device.Clear (ClearFlags.Target ,Color.Red , ,..)
: Pixels
:device.Clear (ClearFlags.Target ,Color.Red , )
,,, :
:protected override void OnPaint(System.Windows.Forms.PaintEventArgs
e)
{
device.Clear (ClearFlags.Target ,Color.Red , )
}
((Draft() Present((Function
:
:protected override void OnPaint(System.Windows.Forms.PaintEventArgs
e)
{
device.Clear (ClearFlags.Target ,Color.Red , )device.Present ();
}
device ((object Device DirectX. ().
-----------
()Main
.... (AccessPoint) (Entry Point),
.
:static void Main()
{
}
8/14/2019 DirectX 9
21/41
((Object((function,
ondevice Device DirectX.
()OnPaint . ((Built In
:
:static void Main()
{
Form xx = new Form();
{
xx.ondeivce (); }
}
,
Object(xx),
:Application.Run (xx);
:
:static void Main()
{
Form xx = new Form();
{
xx.ondeivce ();
Application.Run (xx);}
}
------------------------------
8/14/2019 DirectX 9
22/41
:
- DirectX Microsoft Visual Studio.NetWindows Application-
- DirectX DirectX Net.sual StudioMicrosoft Vi
Microsoft Visual Studio.Net New Project,
Visual C# Projects
Windows ApplicationDirectX Ok
8/14/2019 DirectX 9
23/41
AddProject,Reference
8/14/2019 DirectX 9
24/41
, DirectX,Select
8/14/2019 DirectX 9
25/41
DirectXSelect
Components,, Ok
8/14/2019 DirectX 9
26/41
DirectX
Solution Explorer
DirectX
Windows Application
((Right Click .((View Code,
8/14/2019 DirectX 9
27/41
, (On,Self Generated).
8/14/2019 DirectX 9
28/41
: (, )
:using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
,
:using System.Drawing;
.
:using System.Windows.Forms;
8/14/2019 DirectX 9
29/41
paint
:
public class Form1 : System.Windows.Forms.Form
(Inheritance) (Form1) Form,
.
:
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after
InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
, ( .,)
.
:static void Main()
8/14/2019 DirectX 9
30/41
{
Application.Run(new Form1());
}
... )( .
DirectX:
(
.( : DirectX :
:using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
: Device Direct3d
Device device3d;
: ondevice() Device PresentParameters
:public void ondevice()
{
PresentParameters pp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device3d = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
: OnPaint() :
8/14/2019 DirectX 9
31/41
:protected override void OnPaint (System.Windows.Forms.PaintEventArgs
e)
{
device3d.Clear (ClearFlags.Target ,Color.Red
,1,0);device3d.Present ();
}
: :
:
static void Main()
{using (Form1 xx = new Form1 ())
{
xx.ondevice ();
Application.Run(xx);
}
}
DirectXRUN (F ),
,
DirectX, .
:
8/14/2019 DirectX 9
32/41
:using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX9
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
Device device3d;
///
/// Required designer variable.
///
private System.ComponentModel.Container components =
null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after
InitializeComponent call
//
}
public void ondevice()
{
PresentParameters pp = new PresentParameters
();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device3d = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
protected override void OnPaint
(System.Windows.Forms.PaintEventArgs e)
{
device3d.Clear (ClearFlags.Target ,Color.Red
,1,0);
device3d.Present ();
8/14/2019 DirectX 9
33/41
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do notmodify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
/// /// The main entry point for the application.
///
[STAThread]
static void Main()
{
using (Form1 xx = new Form1 ())
{
xx.ondevice ();
Application.Run(xx);
}
}
}}
DirectX (Full Screen) windowed :
:Format current = Manager.Adapters[0].CurrentDisplayMode.Format;
8/14/2019 DirectX 9
34/41
pp.Windowed = false;
pp.BackBufferFormat = current;
pp.BackBufferCount = 1;
pp.BackBufferWidth = 800;
pp.BackBufferHeight = 600
Class Manager IDNumber Adapters[0] , (Format) ScreenResolution ( x769) Color Quality ( Bit).. CurrentDisplayMode.Format
:
:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX9
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
Device device3d;
///
/// Required designer variable.
///
private System.ComponentModel.Container components =
null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after
InitializeComponent call
//
8/14/2019 DirectX 9
35/41
}
public void ondevice()
{
PresentParameters pp = new PresentParameters
();
pp.SwapEffect = SwapEffect.Discard;
Format current =
Manager.Adapters[0].CurrentDisplayMode.Format;
pp.Windowed = false;
pp.BackBufferFormat = current;
pp.BackBufferCount = 1;
pp.BackBufferWidth = 800;
pp.BackBufferHeight = 600;
device3d = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
protected override void OnPaint
(System.Windows.Forms.PaintEventArgs e)
{
device3d.Clear (ClearFlags.Target ,Color.Red
,1,0);
device3d.Present ();
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
8/14/2019 DirectX 9
36/41
this.Text = "Form1";
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
using (Form1 xx = new Form1 ())
{
xx.ondevice ();
Application.Run(xx);
}
}
}
}
------
... (On SelfGenerated), ... :
:
using System.Drawing;using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;
public class DX: Form
{
Device device;
public void ondeivce()
{
PresentParameters pp = new PresentParameters ();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16 ;
device = new Device (0,DeviceType.Hardware
,this,CreateFlags.SoftwareVertexProcessing ,pp);
}
8/14/2019 DirectX 9
37/41
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
device.Clear (ClearFlags.Target ,Color.SkyBlue
,1,1);
device.Present ();
}
static void Main()
{
using (DX xx = new DX ())
{
xx.ondeivce ();
Application.Run (xx);
}}
}
8/14/2019 DirectX 9
38/41
:
- Vertexes- Position Vertexes
- Transformed Vertexes
Vertexes
( xyz), ((Object object Vertexes, Vertexes
DirectX . DirectX(Rectangle)
...
DirectX Namespace DirectD ClassCustomVertex
8/14/2019 DirectX 9
39/41
Vertex Position Vertexes TransformedVertexes
------------------------
:Position Vertexes
(Vertex)(x,y,z)((
:
Position Vertexes:
PositionOnly:.PositionColored:.PositionTextured:.
PositionNormal:.
8/14/2019 DirectX 9
40/41
8/14/2019 DirectX 9
41/41
Transformed Vertexes:
Transformed :.TransformedColored:.
TransformedTextured:. TransformedColoredTextured:.
------------------------
((Color/ .,((Texture/
.
Vertex
com.yahoo@Hasa