





















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A record of practical works done by a student in the college laboratory for the course GAME PROGRAMMING for the partial fulfillment of Fifth Semester of BSc CS during the academic year 2023-2024. It includes a list of topics covered, code snippets, and outputs for each practical work. The document can be useful for students studying game programming in BSc CS and interested in DirectX 11 and C# programming.
Typology: Study Guides, Projects, Research
1 / 93
This page cannot be seen from the preview
Don't miss anything!






















































































(Subject-In-Charge)
Sr. No. Date Topic Sign 1 03/07/2023 Setup DirectX 11, Window Framework and Initialize Direct3D Device 2 03/07/2023 Buffers, Shaders and HLSL (Draw a triangle using Direct3D 11) 3 28/07/2023 Texturing^ (Texture^ the^ Triangle^ using^ Direct 3D^ 11) 4 28/07/2023 Lightning (Programmable Diffuse^ Lightning using Direct3D 11 - Triangle) 5 31/07/2023 Loading^ models^ into^ DirectX 11^ and^ rendering. 6 14/08/2023 Programmable Diffuse Lightning on Rectangle using Direct3D 11 7 14/08/2023 Texture^ the Rectangle using^ Direct^ 3D^11 8 14/08/2023 Draw^ a^ Rectangle^ using^ Direct3D 11 9 21/08/2023 Implementing 2D UFO 10 28/08/2023 Implementing Space Shooter 11 11/09/2023 Implementing Roll Ball
Right Click on properties Click on open click on build Select Platform Target and Select x86. Step 2:- Click on View Code of Form 1.
Step 3:- Go to Solution Explorer, right click on project name, and select Add Reference, Click on Browser and select the given .dll files which are "Microsoft.DirectX.Direct3D", and "Microsoft.DirectX.DirectX3DX".
Step 5: Code: 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 prac_ { public partial class Form1 : Form { Microsoft.DirectX.Direct3D.Device device; public Form1() { InitializeComponent(); InitDevice(); } public 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() { device.Clear(ClearFlags.Target, Color.Orange, 0, 1); device.Present(); } private void Form1_Paint(object sender, PaintEventArgs e) { Render(); } } }
Output:-
device.EndScene(); device.Present(); } private void Form1_Paint(object sender, PaintEventArgs e) { Render(); } } } Output:-
Practical 3 Aim:- Programmable Diffuse Lightning using Direct 3D 11. Code: 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; using System.Drawing.Design; namespace Pract { public partial class Form1 : Form { private Microsoft.DirectX.Direct3D.Device device; private CustomVertex.PositionTextured[] vertex = new CustomVertex.PositionTextured[3]; private Texture texture; public Form1() { InitializeComponent(); InitDevice(); } public void InitDevice() { PresentParameters pp = 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.Transform.View = Matrix.LookAtLH(new Vector3(0,0,20), new Vector3(),new Vector3(0,1,0)); device.RenderState.Lighting = false; vertex[0] = new CustomVertex.PositionTextured(new Vector3(0,0,0),0,0); vertex[1] = new CustomVertex.PositionTextured(new Vector3(5,0,0),0,1); vertex[2] = new CustomVertex.PositionTextured(new Vector3(0,5,0),1,-1);
Practical 4 Aim:- Implement Diffusion. Code:- 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 Pract { public partial class Form1 : Form { Microsoft.DirectX.Direct3D.Device device; private CustomVertex.PositionNormalColored[] vertex = new CustomVertex.PositionNormalColored[3]; public Form1() { InitializeComponent(); InitDevice(); } public void InitDevice() { PresentParameters pp = 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.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 10), new Vector3(), new Vector3(0, 1, 0)); vertex[0] = new CustomVertex.PositionNormalColored(new Vector3(0, 1, 1), new Vector3(1, 0, 1), Color.Red.ToArgb()); vertex[1] = new CustomVertex.PositionNormalColored(new Vector3(-1, - 1, 1), new Vector3(1, 0, 1), Color.Red.ToArgb()); vertex[2] = new CustomVertex.PositionNormalColored(new Vector3(1, - 1, 1), new Vector3(-1, 0, 1), Color.Red.ToArgb());
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; } private void Render() { device.Clear(ClearFlags.Target, Color.CornflowerBlue, 0, 1); device.BeginScene(); device.VertexFormat = CustomVertex.PositionNormalColored.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, vertex.Length / 3, vertex); device.EndScene(); device.Present(); } private void Form1_Paint(object sender, PaintEventArgs e) { Render(); } } } Output:-
device.Clear(ClearFlags.Target, Color.CornflowerBlue, 0, 1); device.BeginScene(); using (Sprite s = new Sprite(device)) { s.Begin(SpriteFlags.AlphaBlend); s.Draw2D(texture, new Rectangle(0, 0, 0, 0), new Rectangle(0, 0, device.Viewport.Width, device.Viewport.Height), new Point(0, 0), 0f, new Point(0,0), Color.Blue); font.DrawText(s, "nagindas Khandwala Shantanu 522", new Point(0, 0), Color.White); s.End(); } device.EndScene(); device.Present(); } private void Form1_Paint(object sender, PaintEventArgs e) { Render(); } } } Output:-
Practical 6 Aim:- Draw a Rectangle Using DirectX3D 11. Code:- 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 Pract { public partial class Form1 : Form { Microsoft.DirectX.Direct3D.Device device; public Form1() { InitializeComponent(); InitDevice(); } public 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[6]; vertexes[0].Position = new Vector4(100, 100, 0, 1); vertexes[0].Color = System.Drawing.Color.FromArgb(255, 0, 0).ToArgb(); vertexes[1].Position = new Vector4(400, 100, 0, 1); vertexes[1].Color = System.Drawing.Color.FromArgb(0, 255, 1).ToArgb(); vertexes[2].Position = new Vector4(400, 300, 0, 1); vertexes[2].Color = System.Drawing.Color.FromArgb(1, 0, 255).ToArgb(); vertexes[3].Position = new Vector4(400, 300, 0, 1); vertexes[3].Color = System.Drawing.Color.FromArgb(255, 0, 0).ToArgb(); vertexes[4].Position = new Vector4(100, 300, 0, 1); vertexes[4].Color = System.Drawing.Color.FromArgb(20, 255, 0).ToArgb(); vertexes[5].Position = new Vector4(100, 100, 0, 1); vertexes[5].Color = System.Drawing.Color.FromArgb(255, 0, 255).ToArgb();
Practical 7 Aim:- Texturing the Rectangle using DirectX 3D. Code:- using System.Collections.Generic; using System.ComponentModel; using System.Data; using System; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; using System.Drawing.Design; namespace Pract { public partial class Form1 : Form { private Microsoft.DirectX.Direct3D.Device device; private CustomVertex.PositionTextured[] vertex = new CustomVertex.PositionTextured[6]; private Texture texture; public Form1() { InitializeComponent(); InitDevice(); } public void InitDevice() { PresentParameters pp = 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.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 20), new Vector3(), new Vector3(0, 1, 0)); device.RenderState.Lighting = false; } private void Render() { vertex[0] = new CustomVertex.PositionTextured(new Vector3(0, 2, 1), 0, 0); vertex[1] = new CustomVertex.PositionTextured(new Vector3(0, - 2, 1), 0, 1); vertex[2] = new CustomVertex.PositionTextured(new Vector3(2, - 2, 1), - 1, 1);
vertex[3] = new CustomVertex.PositionTextured(new Vector3(2, - 2, 1), 0, 0); vertex[4] = new CustomVertex.PositionTextured(new Vector3(2, 2, 1), 0, 1); vertex[5] = new CustomVertex.PositionTextured(new Vector3(0, 2, 1), - 1, 1); texture = new Texture(device, new Bitmap("D:\ 522 \GP\GP\practical5\3Dimage.jpg") , 0, Pool.Managed); device.Clear(ClearFlags.Target, Color.Orange, 0, 1); device.BeginScene(); device.SetTexture(0, texture); device.VertexFormat = CustomVertex.PositionTextured.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, vertex.Length / 3, vertex); device.EndScene(); device.Present(); } private void Form1_Paint(object sender, PaintEventArgs e) { Render(); } } } Output:-