GP Pract Doc
GP Pract Doc
GP Pract Doc
com
Prerequisites:
Install visual studio 2019 or 2017 community
Unity 3d
Steps:
Download DirectX SDK from the link given in the description.
https://www.microsoft.com/en-in/download/details.aspx?id=6812
Open control panel:
If you don’t Follow the above steps you will get an "ERROR
NO:S103"
Practical No. 1:
1
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
Step 4:
Go to Properties Section of Form, select Paint in the Event List and
enter as Form1_Paint.
Step 5:
Edit the Form’s C# code file. Namespace must be as same as your
project name.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GP_P1
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
public Form1()
{
InitializeComponent();
2
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
InitDevice();
}
3
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
4
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
Practical No. 2:
Solution:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GPRACT2
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
public Form1()
{
InitializeComponent();
InitDevice();
}
private void InitDevice()
{
PresentParameters pp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing, pp);
}
private void Render()
{
CustomVertex.TransformedColored[] vertexes = new
CustomVertex.TransformedColored[3];
5
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
Note: Go to Properties Section of Form, select Paint in the Event List and
enter as Form1_Paint.
Output:
6
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
Practical No. 3:
Solution:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GPPRACT3
{
public partial class Form1 : Form
{
private Microsoft.DirectX.Direct3D.Device device;
privateCustomVertex.PositionTextured[] vertex = new
CustomVertex.PositionTextured[3];
private Texture texture;
public Form1()
{
InitializeComponent();
InitDevice();
}
private void InitDevice()
{
PresentParameterspp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0,DeviceType .Hardware ,this,
CreateFlags.HardwareVertexProcessing, pp);
device.Transform.Projection = Matrix.PerspectiveFovLH(3.14f / 4,
device.Viewport.Width / device.Viewport.Height, 1f, 1000f);
device.RenderState.Lighting = false;
7
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
Output:
NOTE: don’t forget to add image into your solution with proper path
specified
8
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
Practical No. 4:
Solution:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GPPRACT4
{
public partial class Form1 : Form
{
device.Transform.Projection = Matrix.PerspectiveFovLH(3.14f / 4,
device.Viewport.Width / device.Viewport.Height, 1f, 1000f);
device.RenderState.Lighting = false;
9
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
device.RenderState.Lighting = true;
device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = Color.Plum;
device.Lights[0].Direction = new Vector3(0.8f, 0, -1);
device.Lights[0].Enabled = true;
}
}
}
Output:
10
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
-------------------------------------------------------------------------------------
Practical No. 5:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GPPRACT5
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
Microsoft.DirectX.Direct3D.Texture texture;
Microsoft.DirectX.Direct3D.Font font;
public Form1()
{
InitializeComponent();
InitDevice();
InitFont();
LoadTexture();
}
12
T.Y.B.Sc.(C.S.) Game Programming www.profajaypashankar.com
Output:
13