36
Introduction to XNA and Visual Studio Giuseppe Maggiore

Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Embed Size (px)

Citation preview

Page 1: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Introduction to XNA and

Visual Studio

Giuseppe Maggiore

Page 2: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

Page 3: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

Page 4: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA Architecture

XNA Library

C#

.Net CF

XBOX 360

.Net

WIN PC

DirectX 9 Ex

Video Hardware

Page 5: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

C#

Managed language

Heavily JIT’ed

Designed to be similar to

Delphi

C++

Java

Generics

Lambdas/Monadic containers (LINQ)

Page 6: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

.Net

Virtual machine for MSIL assembly

Is not just “ C# bytecode”

Visual Basic .Net

C++/CLI

F#

About a hundred more…

Plays nice with native C++ (but not on the

XBOX )

Page 7: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

Page 8: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA

Allows full control of the graphics hardware

(DirectX 9 level)

Is a full game dev API

Audio

Input

Networking

Content management

Does algebra for us

Page 9: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA - Math

Page 10: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA - Input

Page 11: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA - Input

Page 12: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA - Audio

Page 13: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA - Networking

Page 14: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

Page 15: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA Game

Page 16: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Step 1 - XNA Game Creation

Page 17: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA Game Creation

Page 18: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA Game Creation

Page 19: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA Game Creation

Page 20: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA Game Creation

Page 21: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA Game Creation

static void Main(string[] args){

using (Game1 game = new Game1()){

game.Run();}

}

Page 22: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA Game Creation

Page 23: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA Game Creation

public class Game1 : Microsoft.Xna.Framework.Game{

GraphicsDeviceManager graphics;SpriteBatch spriteBatch;public Game1()protected override void Initialize()protected override void LoadContent()protected override void UnloadContent()protected override void Update(GameTime gameTime)protected override void Draw(GameTime gameTime)

}

Page 24: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

XNA Game Creation

To Run the program press CTRL+F5

Or “DebugLaunch Without Debugging”

Page 25: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

Page 26: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Step 2 – Drawing Stuff

Drawing some geometry:

Create a VertexPositionColor[]

Create a writeonly VertexBuffer with

VertexPositionColor.SizeInBytes x NumVertices

Copy the array into the buffer

COPY INTO

Page 27: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Step 2 – Drawing Stuff

Create a VertexDeclaration with

VertexPositionColor.VertexElements

COPY INTO

Page 28: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

Page 29: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Step 2 – Drawing Stuff

Create a BasicEffect

Set World as Identity

Set View as CreateLookAt

Set Projection as CreatePerspectiveFOV

Page 30: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Step 2 – Drawing Stuff

Inside Draw method

Start rendering with BasicEffect.Begin() and BasicEffect.CurrentTechnique.Passes[0].Begin()

Set VertexDeclaration to GraphicsDevice.VertexDeclaration

Set VertexBuffer with GraphicsDevice.Vertices[0].SetSource

Call Effect.CommitChanges

Call GraphicsDevice.DrawIndexedPrimitives

End rendering with matching End()

Page 31: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

Page 32: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Step 3 – Custom Drawing

Add a custom effect to Content project

Page 33: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Step 3 – Custom Drawing

The effect can be loaded with Content.Load

It is not a BasicEffect, just an Effect

Page 34: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Step 3 – Custom Drawing

The effect contains:

A vertex shader which defines how vertices are

transformed

A pixel shader which defines how transformed

vertices are colored

Experiment

Page 35: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

Step 3 – Custom Drawing

World, View and Projection can be set with

Effect.Parameters[*].SetValue

The remaining host code is identical

Page 36: Introduction to XNA and Visual Studio - dsi.unive.itgrafica/esercitazione1/CG_2010_Lab_0.pdf · Add a custom effect to Content project. Step 3

GOOD LUCK!