GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes...

24
GAM531 DPS931 – Week 1 Introduction

Transcript of GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes...

Page 1: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

GAM531DPS931 – Week 1Introduction

Page 2: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Professors

Joseph Hughes

Info:

• scs.senecac.on.ca/~jp.hughes

• T2104

[email protected]

Roles:

• Primary Lecturer

• Modern API Wizard

Chris Szalwinski

Info:

• scs.senecac.on.ca/~chris.szalwinski

• T2093

[email protected]

Roles:

• Mathematical Genius

• DPS931 Overlord

Page 3: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

So what does this course teach you?

Not This This

Page 4: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

So we will be making 3D games?

Not Games…Game Engines

Page 5: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

What is an game engine?• Think of a car…

Gam

e L

ogic HP = 10;DMG = 20;Player.attack();LoadLevel(10);Enemy.Spawn();RenderScene();

Gam

e

Engin

e glEnable(GL_BLEND);glBindBuffer(bufferID);glBindTexture(textureID);glDrawElements(size, data);

Gam

e

Outp

ut

• And now for some code…

Page 6: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Some Examples…

???Engine

Game

Logic

Page 7: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

How is an engine structured?

Engine

Core

Client Interfac

e

Operating

System API

Device API

Page 8: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Separation of concepts

HARDWARE

FIRMWARE

OS API DEVICE API

APPLICATION

CPUGPUCHIPSET

DRIVERS

Window CreationConsole WriteInput detection Your Program

Open GL 4.3DirectX 11

Page 9: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Why do we need Device APIs?• OS APIs are slow

• Indirect, limited functionality

• Unable to harness true potential of hardware

• Device APIs are fast!

• Give nearly direct control over the device

• Specialized to fit to fit programmer’s needs

Page 10: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

What devices are we using?• We will be making use of the Graphics Processing Units (GPU)

• GPUs are highly parallelized processing units made for graphical processing

• GPUs can come as discrete Graphics Cards or Integrated Chips with your mother board or CPU (APUs)

Page 11: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

To recap…

Application

Device APIs

Firmware

Hardware

// Set up the description of the static index buffer.indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount;indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;indexBufferDesc.CPUAccessFlags = 0;indexBufferDesc.MiscFlags = 0;indexBufferDesc.StructureByteStride = 0;

// Give the subresource structure a pointer to the index data.indexData.pSysMem = indices;

// Create the index buffer.result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);

// Set the depth buffer to be entirely cleared to 1.0 values.glClearDepth(1.0f);

// Enable depth testing.glEnable(GL_DEPTH_TEST);

// Set the polygon winding to front facing for the left handed system.glFrontFace(GL_CW);

// Enable back face culling.glEnable(GL_CULL_FACE);glCullFace(GL_BACK);

// Initialize the world/model matrix to the identity matrix.BuildIdentityMatrix(m_worldMatrix);

The ultimate goal –

To render a 3D world to the screen

Page 12: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Engine recap

Engine

Core

Client Interfac

e

Operating

System API

Device API

Page 13: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Into the Emperor Engine

Engine

DX11 Devic

e

GL 4.3

Device

Controller

Manager

Model

DX11 Objec

t

GL 4.3

Object

DX 11 API

GL 4.3 API

DX 11 API

GL 4.3 API

1 m

1 m

1 m

1 1 or1

1 or 1

1

iEngine

iController iModel

Page 14: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Stepping into the Engine

iEngine.hpp

namespace Emperor { class iEngine {…}; }

Engine.hpp

namespace Emperor { template <RenderSystem RS> class Engine : public iEngine, public Singleton<Engine<RS>> {…}; }

Page 15: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Reviewing Namespaces

struct Foo { int a;};

namespace Bar { struct Foo { ::Foo a; }; namespace Derp { struct Foo { Bar::Foo a; }; }}

int main() { Foo a; Bar::Foo b; Bar::Derp::Foo c;}

or

using namespace Bar;int main() { ::Foo a; Bar::Foo b; Derp::Foo c;}

Page 16: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Reviewing Pure Virtual Classes (Interfaces) virtual

void doStuff()

= 0;

• Interface

virtual void

doStuff() {…}

• Derived Class

void doStuff()

{…}

• Most Derived Class

class iThing { virtual void doStuff() = 0;};class Thing : public iThing { virtual void doStuff() { std::cin << “Thing”; }};class BigThing : pulic Thing { void doStuff() { std::cin << “BigThing”; }};

int main() { Thing* a = new Thing(); a->doStuff();};

int main() { Thing* a = new BigThing(); a->doStuff();};

int main() { //iThing* a = new iThing(); iThing* a = new BigThing(); a->doStuff();};

Page 17: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

The Engine Interface class iEngine { private: friend iEngine* createEngine(RenderSystem); friend void releaseEngine(iEngine*); protected: virtual ~iEngine() {} public: virtual void initialize() = 0; virtual void release() = 0; virtual void setFullScreen(bool) = 0; virtual bool isFullScreen() = 0; virtual void activateDevice(iWindow*) = 0; virtual iResourceController* getResourceController() = 0; virtual iSceneController* getSceneController() = 0; virtual void render() = 0; };

Create & Destroy Engine (Friends

for Dynamic Linking)

Retrieve Controllers

Activates Device for rendering

Render a Single Frame

Initialize and Release Engine Assets

Page 18: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Back to the Engine

iEngine.hpp

namespace Emperor { class iEngine {…}; }

Engine.hpp

namespace Emperor { template <RenderSystem RS> class Engine : public iEngine, public Singleton<Engine<RS>> {…}; }

Page 19: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Template Reviewtemplate <class T>class Foo { T a; public: Foo() {a = 0;} void doStuff();};

int main() {

}

Foo<int> a; Foo<float> b; Foo<char*> c;

class Foo_of_int { int a; public: Foo() {a = 0;} void doStuff() { std::cout << “Foo”; }};class Foo_of_float { float a; public: Foo() {a = 0;} void doStuff() { std::cout << “Foo”; }};

template <>void Foo<char*>::doStuff() { std::cout << “Char* Foo”;};

template <class T>void Foo<T>::doStuff() { std::cout << “Foo”;};

class Foo_of_char_ptr { char* a; public: Foo() {a = 0;} void doStuff() { std::cout << “Char* Foo”; }};

Page 20: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Template Specialization Review…template <RenderSystem RS>class Device{};template <>class Device<RS_DX11> { private: IDXGISwapChain* swap; ID3D11Device* dev; ID3D11DeviceContext* con; …};

template<>class Device<RS_GL43> { private: HGLRC context; HDC hdc; …};

int main() {

}

Device<RS_DX11> a; Device<RS_GL43> b; Device<RS_GL43 + 1> c;

Page 21: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Template Misc. Reviewtemplate <class T = int, int N = 4>class Foo { T a[N];};

int main() {

}

Foo<int, 4> a; Foo<int> b; Foo<> c;

All three are the same!

file.hpp

template <class T>class Foo { T a; public: void doStuff();};

file.cpp

template <class T>void Foo<T>::doStuff() { std::cout << “Foo”;};

Compiler does

nothing!Linker can’t

find function!

template class Foo<int>;template class Foo<float>;

Compiles for int and float, can only be

bound to those!

Page 22: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Finishing Recap• This course is all about engine development!

• An engine is framework that enables programmers to accomplish complex tasks with relative ease

• A system API is an interface that exposes a set of functions to provide programmers with control and functionality that would otherwise be out of grasp

• Device APIs like DirectX 11 and OpenGL 4.3 allow a more direct and more efficient method interfacing with the firmware controlling the hardware

• The GPU is a highly parallelized processing unit designed for 3D graphic rendering

• You got a glimpse of the Emperor Engine’s design

Page 23: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

Course Breakdown• Please read the course outline on the ICT website!

• Mark breakdown:

• Labs are worth 2% each, if a lab is not complete by the end of the day the highest mark achievable on the lab is ½.

• You are expected to know how to use git and Visual Studio 2013, there will be a review of them next class

• A laptop or desktop computer with a modern GPU is highly recommended

Labs (10) 20%

Assignment (1) 30%

Mid-term 20%

Exam 30%

Page 24: GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Jp.hughes@senecacollege.ca Roles: Primary Lecturer.

To Do• Install Visual Studio 2013 on your personal computers

• Install most recent DirectX SDK on your personal computers

• Update the graphics drivers of you personal computer (must support OpenGL 4.3)

• Create a BitBucket account if you don’t already have one