SlideShare una empresa de Scribd logo
1 de 23
Beginning Direct3D Game Programming:
5. Basics
jintaeks@gmail.com
Division of Digital Contents, DongSeo University.
April 2016
Compiling the Tutorial
 C:DxSdk_200806SamplesC++Direct3DTutorialsTut01_
CreateDevice
– CreateDevice_2008.sln
2
Fix error : identifier '__RPC__out_xcount_part'
 error C2061: syntax error : identifier '__RPC__out_xcount_part'
3
Open Property Manager
 Open property manager for Microsoft.Cpp.Win32.user
4
Include Directory
 C:DxSdk_200806Include; must be located at last of include
directory string.
– $(VC_IncludePath);$(WindowsSDK_IncludePath);C:DxSdk_200806Incl
ude;
5
Library Directory
 C:DxSdk_200806Libx86; must be located at last of library
directory string.
– $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);C:DxSdk_2008
06Libx86;
6
Tutorial 02: Rendering Vertices
 The Vertices sample project creates the simplest shape, a
triangle, and renders it to the display.
– Step 1 - Defining a Custom Vertex Type
– Step 2 - Setting Up the Vertex Buffer
– Step 3 - Rendering the Display
7
Step 1 – Defining a Custom Vertex Type
 The Vertices sample project renders a 2D triangle by using
three vertices.
– struct CUSTOMVERTEX
– {
– FLOAT x, y, z, rhw; // The transformed position for the vertex.
– DWORD color; // The vertex color.
– };
 The next step is to define the FVF that describes the contents
of the vertices in the vertex buffer.
– #define D3DFVF_CUSTOMVERTEX
(D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
8
Step 2 – Setting Up the Vertex Buffer
 The following code fragment initializes the values for three
custom vertices.
– CUSTOMVERTEX vertices[] =
– {
– { 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
– { 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, },
– { 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },
– };
 The next step is to call IDirect3DDevice9::CreateVertexBuffer to
create a vertex buffer as shown in the following code
fragment.
– if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
– 0 /*Usage*/, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) )
)
– return E_FAIL;
9
 After creating a vertex buffer, it is filled with data from the
custom vertices.
– VOID* pVertices;
– if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
– return E_FAIL;
– memcpy( pVertices, vertices, sizeof(vertices) );
– g_pVB->Unlock();
10
Step 3 – Rendering the Display
 Rendering the display starts by clearing the back buffer to a
blue color and then calling BeginScene.
– g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f,
0L );
– g_pd3dDevice->BeginScene();
 You need to set the stream source; in this case, use stream 0.
– g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
 The next step is to call IDirect3DDevice9::SetFVF to identify
the fixed function vertex shader.
– g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
 The next step is to use IDirect3DDevice9::DrawPrimitive to
render the vertices in the vertex buffer.
– g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
11
 The last steps are to end the scene and then present the back
buffer to the front buffer.
– g_pd3dDevice->EndScene();
– g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
12
Primitives in Direct3D 9
 A 3D primitive is a collection of vertices that form a single 3D
entity.
– The simplest primitive is a collection of points in a 3D coordinate
system, which is called a point list.
 Direct3D devices can create and manipulate the following
types of primitives.
– Point Lists (Direct3D 9)
– Line Lists (Direct3D 9)
– Line Strips (Direct3D 9)
– Triangle Lists (Direct3D 9)
– Triangle Strips (Direct3D 9)
– Triangle Fans (Direct3D 9)
13
Point Lists
struct CUSTOMVERTEX
{
float x,y,z;
};
CUSTOMVERTEX Vertices[] =
{
{-5.0, -5.0, 0.0},
{ 0.0, 5.0, 0.0},
{ 5.0, -5.0, 0.0},
{10.0, 5.0, 0.0},
{15.0, -5.0, 0.0},
{20.0, 5.0, 0.0}
};
d3dDevice->DrawPrimitive( D3DPT_POINTLIST, 0, 3 );
14
Line Lists
CUSTOMVERTEX Vertices[] =
{
{-5.0, -5.0, 0.0},
{ 0.0, 5.0, 0.0},
{ 5.0, -5.0, 0.0},
{10.0, 5.0, 0.0},
{15.0, -5.0, 0.0},
{20.0, 5.0, 0.0}
};
 The code example below shows how to use
IDirect3DDevice9::DrawPrimitive to render this line list.
//
// It is assumed that d3dDevice is a valid
// pointer to a IDirect3DDevice9 interface.
//
d3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, 3 );
15
Line Strips
CUSTOMVERTEX Vertices[] =
{
{-5.0, -5.0, 0.0},
{ 0.0, 5.0, 0.0},
{ 5.0, -5.0, 0.0},
{10.0, 5.0, 0.0},
{15.0, -5.0, 0.0},
{20.0, 5.0, 0.0}
};
 The code example below shows how to use
IDirect3DDevice9::DrawPrimitive to render this line strip.
d3dDevice->DrawPrimitive( D3DPT_LINESTRIP, 0, 5 );
16
Triangle Lists
CUSTOMVERTEX Vertices[] =
{
{-5.0, -5.0, 0.0},
{ 0.0, 5.0, 0.0},
{ 5.0, -5.0, 0.0},
{10.0, 5.0, 0.0},
{15.0, -5.0, 0.0},
{20.0, 5.0, 0.0}
};
 The code example below shows how to use
IDirect3DDevice9::DrawPrimitive to render this triangle list.
//
// It is assumed that d3dDevice is a valid
// pointer to a IDirect3DDevice9 interface.
//
d3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
17
Triangle Strips
 A triangle strip is a series of connected triangles.
– Because the triangles are connected, the application does not need to
repeatedly specify all three vertices for each triangle.
 The system uses vertices v1, v2, and v3 to draw the first
triangle; v2, v4, and v3 to draw the second triangle.
18
CUSTOMVERTEX Vertices[] =
{
{-5.0, -5.0, 0.0},
{ 0.0, 5.0, 0.0},
{ 5.0, -5.0, 0.0},
{10.0, 5.0, 0.0},
{15.0, -5.0, 0.0},
{20.0, 5.0, 0.0}
};
 The code example below shows how to use
IDirect3DDevice9::DrawPrimitive to render this triangle strip.
d3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 4);
19
Triangle Fans
 A triangle fan is similar to a triangle strip, except that all the
triangles share one vertex.
20
CUSTOMVERTEX Vertices[] =
{
{ 0.0, 0.0, 0.0},
{-5.0, 5.0, 0.0},
{-3.0, 7.0, 0.0},
{ 0.0, 10.0, 0.0},
{ 3.0, 7.0, 0.0},
{ 5.0, 5.0, 0.0},
};
 The code example below shows how to use
IDirect3DDevice9::DrawPrimitive to render this triangle fan.
d3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 4 );
21
References
22
Beginning direct3d gameprogramming05_thebasics_20160421_jintaeks

Más contenido relacionado

La actualidad más candente

Program for hamming code using c
Program for hamming code using cProgram for hamming code using c
Program for hamming code using c
snsanth
 

La actualidad más candente (20)

C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
Include
IncludeInclude
Include
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
 
Implementing string
Implementing stringImplementing string
Implementing string
 
Static and const members
Static and const membersStatic and const members
Static and const members
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
 
Cquestions
Cquestions Cquestions
Cquestions
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
New presentation oop
New presentation oopNew presentation oop
New presentation oop
 
2. Базовый синтаксис Java
2. Базовый синтаксис Java2. Базовый синтаксис Java
2. Базовый синтаксис Java
 
C questions
C questionsC questions
C questions
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Conditional Statementfinal PHP 02
Conditional Statementfinal PHP 02Conditional Statementfinal PHP 02
Conditional Statementfinal PHP 02
 
Program for hamming code using c
Program for hamming code using cProgram for hamming code using c
Program for hamming code using c
 
Pegomock, a mocking framework for Go
Pegomock, a mocking framework for GoPegomock, a mocking framework for Go
Pegomock, a mocking framework for Go
 
Railwaynew
RailwaynewRailwaynew
Railwaynew
 
Container adapters
Container adaptersContainer adapters
Container adapters
 

Destacado

Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeksBeginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
JinTaek Seo
 

Destacado (16)

Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeksBeginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
 
Beginning direct3d gameprogramming01_20161102_jintaeks
Beginning direct3d gameprogramming01_20161102_jintaeksBeginning direct3d gameprogramming01_20161102_jintaeks
Beginning direct3d gameprogramming01_20161102_jintaeks
 
Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks
Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeksBeginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks
Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks
 
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
 
Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks
Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeksBeginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks
Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks
 
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeksBeginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
 
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeksBeginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
 
Beginning direct3d gameprogramming04_3dfundamentals_20160414_jintaeks
Beginning direct3d gameprogramming04_3dfundamentals_20160414_jintaeksBeginning direct3d gameprogramming04_3dfundamentals_20160414_jintaeks
Beginning direct3d gameprogramming04_3dfundamentals_20160414_jintaeks
 
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeksBeginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
 
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeksBeginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
 
Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks
Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeksBeginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks
Beginning direct3d gameprogrammingmath02_logarithm_20160324_jintaeks
 
Beginning direct3d gameprogrammingcpp02_20160324_jintaeks
Beginning direct3d gameprogrammingcpp02_20160324_jintaeksBeginning direct3d gameprogrammingcpp02_20160324_jintaeks
Beginning direct3d gameprogrammingcpp02_20160324_jintaeks
 
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeksBeginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
 
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeksBeginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
 

Similar a Beginning direct3d gameprogramming05_thebasics_20160421_jintaeks

Programming using opengl in visual c++
Programming   using opengl in visual c++Programming   using opengl in visual c++
Programming using opengl in visual c++
Ta Nam
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
AOE
 

Similar a Beginning direct3d gameprogramming05_thebasics_20160421_jintaeks (20)

Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answers
 
Anomalies in X-Ray Engine
Anomalies in X-Ray EngineAnomalies in X-Ray Engine
Anomalies in X-Ray Engine
 
Programming using opengl in visual c++
Programming   using opengl in visual c++Programming   using opengl in visual c++
Programming using opengl in visual c++
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
Boosting Developer Productivity with Clang
Boosting Developer Productivity with ClangBoosting Developer Productivity with Clang
Boosting Developer Productivity with Clang
 
05-Debug.pdf
05-Debug.pdf05-Debug.pdf
05-Debug.pdf
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2
 
Zone IDA Proc
Zone IDA ProcZone IDA Proc
Zone IDA Proc
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
 
ERTS UNIT 3.ppt
ERTS UNIT 3.pptERTS UNIT 3.ppt
ERTS UNIT 3.ppt
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...
 
Hello, Is That FreeSWITCH? Then We're Coming to Check You!
Hello, Is That FreeSWITCH? Then We're Coming to Check You!Hello, Is That FreeSWITCH? Then We're Coming to Check You!
Hello, Is That FreeSWITCH? Then We're Coming to Check You!
 
Live deployment, ci, drupal
Live deployment, ci, drupalLive deployment, ci, drupal
Live deployment, ci, drupal
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 

Más de JinTaek Seo

Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks
Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeksBeginning direct3d gameprogrammingmath01_primer_20160324_jintaeks
Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks
JinTaek Seo
 

Más de JinTaek Seo (14)

Neural network 20161210_jintaekseo
Neural network 20161210_jintaekseoNeural network 20161210_jintaekseo
Neural network 20161210_jintaekseo
 
05 heap 20161110_jintaeks
05 heap 20161110_jintaeks05 heap 20161110_jintaeks
05 heap 20161110_jintaeks
 
02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseo02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseo
 
Hermite spline english_20161201_jintaeks
Hermite spline english_20161201_jintaeksHermite spline english_20161201_jintaeks
Hermite spline english_20161201_jintaeks
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
 
03 fsm how_toimplementai_state_20161006_jintaeks
03 fsm how_toimplementai_state_20161006_jintaeks03 fsm how_toimplementai_state_20161006_jintaeks
03 fsm how_toimplementai_state_20161006_jintaeks
 
Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks
Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeksBeginning direct3d gameprogrammingmath01_primer_20160324_jintaeks
Beginning direct3d gameprogrammingmath01_primer_20160324_jintaeks
 
Boost pp 20091102_서진택
Boost pp 20091102_서진택Boost pp 20091102_서진택
Boost pp 20091102_서진택
 
아직도가야할길 훈련 20090722_서진택
아직도가야할길 훈련 20090722_서진택아직도가야할길 훈련 20090722_서진택
아직도가야할길 훈련 20090722_서진택
 
3ds maxscript 튜토리얼_20151206_서진택
3ds maxscript 튜토리얼_20151206_서진택3ds maxscript 튜토리얼_20151206_서진택
3ds maxscript 튜토리얼_20151206_서진택
 
Multithread programming 20151206_서진택
Multithread programming 20151206_서진택Multithread programming 20151206_서진택
Multithread programming 20151206_서진택
 
03동물 로봇그리고사람 public_20151125_서진택
03동물 로봇그리고사람 public_20151125_서진택03동물 로봇그리고사람 public_20151125_서진택
03동물 로봇그리고사람 public_20151125_서진택
 
20150605 홀트입양예비부모모임 서진택
20150605 홀트입양예비부모모임 서진택20150605 홀트입양예비부모모임 서진택
20150605 홀트입양예비부모모임 서진택
 
Boost라이브러리의내부구조 20151111 서진택
Boost라이브러리의내부구조 20151111 서진택Boost라이브러리의내부구조 20151111 서진택
Boost라이브러리의내부구조 20151111 서진택
 

Último

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 

Último (20)

S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 

Beginning direct3d gameprogramming05_thebasics_20160421_jintaeks

  • 1. Beginning Direct3D Game Programming: 5. Basics jintaeks@gmail.com Division of Digital Contents, DongSeo University. April 2016
  • 2. Compiling the Tutorial  C:DxSdk_200806SamplesC++Direct3DTutorialsTut01_ CreateDevice – CreateDevice_2008.sln 2
  • 3. Fix error : identifier '__RPC__out_xcount_part'  error C2061: syntax error : identifier '__RPC__out_xcount_part' 3
  • 4. Open Property Manager  Open property manager for Microsoft.Cpp.Win32.user 4
  • 5. Include Directory  C:DxSdk_200806Include; must be located at last of include directory string. – $(VC_IncludePath);$(WindowsSDK_IncludePath);C:DxSdk_200806Incl ude; 5
  • 6. Library Directory  C:DxSdk_200806Libx86; must be located at last of library directory string. – $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);C:DxSdk_2008 06Libx86; 6
  • 7. Tutorial 02: Rendering Vertices  The Vertices sample project creates the simplest shape, a triangle, and renders it to the display. – Step 1 - Defining a Custom Vertex Type – Step 2 - Setting Up the Vertex Buffer – Step 3 - Rendering the Display 7
  • 8. Step 1 – Defining a Custom Vertex Type  The Vertices sample project renders a 2D triangle by using three vertices. – struct CUSTOMVERTEX – { – FLOAT x, y, z, rhw; // The transformed position for the vertex. – DWORD color; // The vertex color. – };  The next step is to define the FVF that describes the contents of the vertices in the vertex buffer. – #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE) 8
  • 9. Step 2 – Setting Up the Vertex Buffer  The following code fragment initializes the values for three custom vertices. – CUSTOMVERTEX vertices[] = – { – { 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color – { 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, }, – { 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, }, – };  The next step is to call IDirect3DDevice9::CreateVertexBuffer to create a vertex buffer as shown in the following code fragment. – if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX), – 0 /*Usage*/, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) – return E_FAIL; 9
  • 10.  After creating a vertex buffer, it is filled with data from the custom vertices. – VOID* pVertices; – if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) ) – return E_FAIL; – memcpy( pVertices, vertices, sizeof(vertices) ); – g_pVB->Unlock(); 10
  • 11. Step 3 – Rendering the Display  Rendering the display starts by clearing the back buffer to a blue color and then calling BeginScene. – g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0L ); – g_pd3dDevice->BeginScene();  You need to set the stream source; in this case, use stream 0. – g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );  The next step is to call IDirect3DDevice9::SetFVF to identify the fixed function vertex shader. – g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );  The next step is to use IDirect3DDevice9::DrawPrimitive to render the vertices in the vertex buffer. – g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 ); 11
  • 12.  The last steps are to end the scene and then present the back buffer to the front buffer. – g_pd3dDevice->EndScene(); – g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); 12
  • 13. Primitives in Direct3D 9  A 3D primitive is a collection of vertices that form a single 3D entity. – The simplest primitive is a collection of points in a 3D coordinate system, which is called a point list.  Direct3D devices can create and manipulate the following types of primitives. – Point Lists (Direct3D 9) – Line Lists (Direct3D 9) – Line Strips (Direct3D 9) – Triangle Lists (Direct3D 9) – Triangle Strips (Direct3D 9) – Triangle Fans (Direct3D 9) 13
  • 14. Point Lists struct CUSTOMVERTEX { float x,y,z; }; CUSTOMVERTEX Vertices[] = { {-5.0, -5.0, 0.0}, { 0.0, 5.0, 0.0}, { 5.0, -5.0, 0.0}, {10.0, 5.0, 0.0}, {15.0, -5.0, 0.0}, {20.0, 5.0, 0.0} }; d3dDevice->DrawPrimitive( D3DPT_POINTLIST, 0, 3 ); 14
  • 15. Line Lists CUSTOMVERTEX Vertices[] = { {-5.0, -5.0, 0.0}, { 0.0, 5.0, 0.0}, { 5.0, -5.0, 0.0}, {10.0, 5.0, 0.0}, {15.0, -5.0, 0.0}, {20.0, 5.0, 0.0} };  The code example below shows how to use IDirect3DDevice9::DrawPrimitive to render this line list. // // It is assumed that d3dDevice is a valid // pointer to a IDirect3DDevice9 interface. // d3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, 3 ); 15
  • 16. Line Strips CUSTOMVERTEX Vertices[] = { {-5.0, -5.0, 0.0}, { 0.0, 5.0, 0.0}, { 5.0, -5.0, 0.0}, {10.0, 5.0, 0.0}, {15.0, -5.0, 0.0}, {20.0, 5.0, 0.0} };  The code example below shows how to use IDirect3DDevice9::DrawPrimitive to render this line strip. d3dDevice->DrawPrimitive( D3DPT_LINESTRIP, 0, 5 ); 16
  • 17. Triangle Lists CUSTOMVERTEX Vertices[] = { {-5.0, -5.0, 0.0}, { 0.0, 5.0, 0.0}, { 5.0, -5.0, 0.0}, {10.0, 5.0, 0.0}, {15.0, -5.0, 0.0}, {20.0, 5.0, 0.0} };  The code example below shows how to use IDirect3DDevice9::DrawPrimitive to render this triangle list. // // It is assumed that d3dDevice is a valid // pointer to a IDirect3DDevice9 interface. // d3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 ); 17
  • 18. Triangle Strips  A triangle strip is a series of connected triangles. – Because the triangles are connected, the application does not need to repeatedly specify all three vertices for each triangle.  The system uses vertices v1, v2, and v3 to draw the first triangle; v2, v4, and v3 to draw the second triangle. 18
  • 19. CUSTOMVERTEX Vertices[] = { {-5.0, -5.0, 0.0}, { 0.0, 5.0, 0.0}, { 5.0, -5.0, 0.0}, {10.0, 5.0, 0.0}, {15.0, -5.0, 0.0}, {20.0, 5.0, 0.0} };  The code example below shows how to use IDirect3DDevice9::DrawPrimitive to render this triangle strip. d3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 4); 19
  • 20. Triangle Fans  A triangle fan is similar to a triangle strip, except that all the triangles share one vertex. 20
  • 21. CUSTOMVERTEX Vertices[] = { { 0.0, 0.0, 0.0}, {-5.0, 5.0, 0.0}, {-3.0, 7.0, 0.0}, { 0.0, 10.0, 0.0}, { 3.0, 7.0, 0.0}, { 5.0, 5.0, 0.0}, };  The code example below shows how to use IDirect3DDevice9::DrawPrimitive to render this triangle fan. d3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 4 ); 21