introduction to xna and visual studio

Post on 09-Feb-2022

22 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Introduction to XNA and

Visual Studio

Giuseppe Maggiore

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

XNA Architecture

XNA Library

C#

.Net CF

XBOX 360

.Net

WIN PC

DirectX 9 Ex

Video Hardware

C#

Managed language

Heavily JIT’ed

Designed to be similar to

Delphi

C++

Java

Generics

Lambdas/Monadic containers (LINQ)

.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 )

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

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

XNA - Math

XNA - Input

XNA - Input

XNA - Audio

XNA - Networking

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

XNA Game

Step 1 - XNA Game Creation

XNA Game Creation

XNA Game Creation

XNA Game Creation

XNA Game Creation

XNA Game Creation

static void Main(string[] args){

using (Game1 game = new Game1()){

game.Run();}

}

XNA Game Creation

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)

}

XNA Game Creation

To Run the program press CTRL+F5

Or “DebugLaunch Without Debugging”

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

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

Step 2 – Drawing Stuff

Create a VertexDeclaration with

VertexPositionColor.VertexElements

COPY INTO

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

Step 2 – Drawing Stuff

Create a BasicEffect

Set World as Identity

Set View as CreateLookAt

Set Projection as CreatePerspectiveFOV

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()

Agenda

XNA Architecture

C#/.Net

XNA

XNA Game

XNA Buffers

XNA Effects

XNA Custom Effects

Step 3 – Custom Drawing

Add a custom effect to Content project

Step 3 – Custom Drawing

The effect can be loaded with Content.Load

It is not a BasicEffect, just an Effect

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

Step 3 – Custom Drawing

World, View and Projection can be set with

Effect.Parameters[*].SetValue

The remaining host code is identical

GOOD LUCK!

top related