程序代写代做代考 android c# GPU flex 1 Introduction to Graphics Programming

1 Introduction to Graphics Programming

ITP4710

2D/3D Graphics Programming
01
Introduction to Graphics Programming

On completion of the module, students are expected to be able to: 
analysis the differences in different graphics programming environment;
develop 2D and 3D graphics programs for general gaming purposes;
apply animation effects in developing 2D graphics and/or game programs;
apply lighting, texturing and other effects in 3D graphics and/or programs; and
identify and apply appropriate user input methods for graphics and/or game programs.

© VTC 2016
2
Module Intended Learning Outcomes

At the very beginning, application developers had to write separate coding to handle different brands of hardware (e.g. video cards)
Windows provided hardware abstractions that allows developers to target a single set of APIs for devices
Graphics Device Interface (GDI)
However, this kind of abstractions was extremely slow when it came to game development
Nowadays, we still use GDI+ (successor of GDI) under .NET class library via System.Drawing namespace.
Microsoft’s first attempt to address the performance needs of game developers was WinG (under Win 3.x)
© VTC 2016
3
A Brief History of Windows Programming

DirectX is a set of API developed by Microsoft that provides direct access to hardware in Windows environment
if no hardware exists, the API will provide hardware emulation
DirectX gives you hardware control over almost all hardware devices
Direct3D is the part of DirectX that is designed for hardware 3D acceleration on Windows Platform
Current versions of DirectX:
9.0c for XP and Windows Phone 8
11 for Windows 7
11.2 for Windows 8
12 for Windows 10

© VTC 2016
4
DirectX

© VTC 2016
5
DirectX Architecture

HEL Hardware Emulation Layer
Windows Win32 Application
GDI
Windows DDI
Device Driver Interface

Direct Draw

Direct 3D

Direct Input

Direct Play

Direct Setup

Direct Sound

Direct Sound 3D
HAL Hardware Abstraction Layer

Hardware: Video, Audio, Input, Storage…

Low Level Drivers
GDI/DirectX
Interface
DirectX Sub-systems
Software Emulation

Direct Music
Direct Show

Integrated into DirectX audio
Integrated into DirectX graphics

Hardware

Released with Windows 95, Windows Game SDK (aka DirectX 1.0) allowed Windows to access to video cards, keyboards, mice, sound devices, and all other parts of the system
These parts are all in the Windows’ protected memory model.
Replacement of WinG (Windows 3.1)
Initial adoption of DirectX by game developers was slow.
Fears that DirectX could be replaced as WinG had been.
Performance penalty in using Windows over DOS.
© VTC 2016
6
Brief History of DirectX

DirectX 8.0 was the first version to include programmable shaders – a script language for runtime control of graphics rendering.
DirectX 9.0 was the first release of DirectX that can work with Common Language Runtime (CLR).
This produces the Managed DirectX, which later became the basis of XNA.
Current Versions
Windows 7 are using DirectX 11
Windows 8 are using DirectX 11.1 and Windows 8.1 are using DirectX 11.2
DirectX 12 supports Windows 10 and Xbox One

© VTC 2016
7
Brief History of DirectX

OpenGL (Open Graphics Library) is a cross-language, multi-platform application programming interface (API) for rendering 2D and 3D computer graphics.
interact with a Graphics processing unit (GPU) to achieve hardware-accelerated rendering.
OpenGL was developed by Silicon Graphics Inc. (SGI) from 1991 and released in January 1992.
Widely used in CAD, virtual reality, scientific visualization, information visualization, flight simulation, and video games.

© VTC 2016
8
OpenGL

Current OpenGL versions:
OpenGL 4.5 is the newest and supported by Nvidia GeForce 400 series and newer, as well as the Tegra K1 and Tegra X1.
OpenGL ES 3.1 API and shader compatibility
OpenGL 4.2 – 4,4 – supported by: Nvidia GeForce 400 series and newer, ATI Radeon HD 5000 Series and newer, Intel HD Graphics in Intel Haswell processors and newer
Version 4.3 or above are fully compatible with OpenGL ES 3.0 APIs
OpenGL 4.0 and 4.1 – Direct3D 11 class hardware
OpenGL 3.3 – Compatible to deprecated fixed-function APIs
© VTC 2016
9
OpenGL Versions

OpenGL mainly acts as a state machine – a collection of states that tell OpenGL what to do
such as color, lighting, blending and etc.
The OpenGL specification describes an abstract API for drawing 2D and 3D graphics.
Although it’s possible for the API to be implemented entirely in software, it’s designed to be implemented in hardware.
In addition to being language-independent, OpenGL is also platform-independent.
The specification says nothing on the subject of obtaining, and managing an OpenGL context, leaving this as a detail of the underlying windowing system.
© VTC 2016
10
OpenGL Design

Availability
Direct3D application development generally targets the Microsoft Windows platform.
The OpenGL API is an open standard, and implementations exist for a wide variety of platforms.
E.g., Microsoft Windows, UNIX-based systems such as Mac OS X, Linux, Android, BlackBerry, iOS. Nintendo and Sony also has similar implementation.
© VTC 2016
11
Comparison of OpenGL and Direct3D

Implementation
OpenGL and Direct3D are both implemented in the display driver.
Direct3D implements the API in a common runtime (supplied by Microsoft), which in turn talks to a low-level Device Driver Interface (DDI).
With OpenGL, every vendor implements the entire API in the driver itself. This means that some API functions may have slightly different behaviors from one vendor to another.
© VTC 2016
12
Comparison of OpenGL and Direct3D

Ease of Use
Early version of Direct3D required the creation and submission of objects for nearly every operations
In contrast, in OpenGL most state changes can be performed with single function calls
However, the recent Direct3D is at least comparable to OpenGL in terms of capabilities and ease of use
Even high-profile game developer John Carmack, who once was antagonistic against Direct3D, thought DirectX 9 is probably the best graphics API as far as a sensibly designed thing that he has worked with (Source: CES 2007: John Carmack And Todd Hollenshead Speak)
© VTC 2016
13
Comparison of OpenGL and Direct3D

Functional Differences
Direct3D expects the application to manage hardware resources; OpenGL makes the implementation do it.
OpenGL thus decreases difficulty in developing for the API, while at the same time increasing the complexity of creating an implementation (or driver) that performs well
With Direct3D, the developer must manage hardware resources independently – however, the implementation is simpler, and developers have the flexibility to allocate resources in the most efficient way possible for their application
© VTC 2016
14
Comparison of OpenGL and Direct3D

Professional graphics (e.g. animation and CAD)
OpenGL has always seen more use in the professional graphics market than DirectX
Many professional graphics applications were originally written in IRIS GL for high-end SGI workstations, then ported to OpenGL.
At one point many professional graphics cards only supported OpenGL
DirectX is a set of APIs that were not marketed towards professional graphics applications. Indeed, they were not even designed with those applications in mind.
Now, virtually all professional cards which work on the Windows platform will also support Direct3D – as professional graphics market shifts to less expensive PC-based systems, while at the same time providing a new market for OpenGL software in Unix-based consumer systems running Linux or Apple OS X.
© VTC 2016
15
Comparison of OpenGL and Direct3D

Gaming Market (Early days)
In the earliest days of 3D accelerated gaming, software was written specifically for a particular brand of graphics card.
Over the years, OpenGL and Direct3D emerged as cross-hardware software layers above the hardware.
In the early days of 3D accelerated gaming, most vendors did not actually supply a full OpenGL driver.
Most graphics card did not implement enough functionality to properly accelerate OpenGL.
Vendors struggled to implement a full OpenGL driver with good performance and compatibility.
Instead, they wrote MiniGL drivers, which only implemented a subset of OpenGL.
Proper OpenGL drivers became more prevalent as the hardware evolved, around the time of DirectX 6 or DirectX 7.

© VTC 2016
16
Comparison of OpenGL and Direct3D

Gaming Market (PC Gaming Market)
In the 1990s, OpenGL dominated due to a better design.
But with the improvements in Direct3D 7.0, developers began to favor Direct3D because of the dominance of the Windows operating system in the desktop gaming market.
Gaming Market (Console Gaming Market)
In the console world proprietary native APIs are dominant.
Some consoles (e.g. the PS3) providing an OpenGL wrapper around its native API.
The original Xbox supported Direct3D 8.1 as its native API while the Xbox 360 supports a modified version of Direct3D 9.0c as its native API.
© VTC 2016
17
Comparison of OpenGL and Direct3D

Microsoft XNA is a freeware set of tools with a managed runtime environment provided that facilitates video game development and management.
XNA is based on the .NET Framework, with versions that run on Windows, Windows Phone and the Xbox 360.
XNA content is built with the XNA Game Studio, and played using the XNA Framework (for Windows games), or published as native executables (for Xbox 360, Windows Phone and Zune).
XNA can be thought of as a .NET analog to DirectX, but it is aimed at developers primarily interested in writing lightweight games that run on a variety of Microsoft platforms.
XNA is the basic platform for Xbox Live Indie Games.
18
Introduction of XNA
© VTC 2016

XNA Framework includes a set of managed libraries that provides access to advanced graphics processes handled by hardware
Graphics hardware offloaded the graphics processing from CPU to GPU
DirectX provides a set of unmanaged APIs to access the drivers for these graphics devices
DirectX also provides input and audio support through XINPUT (DirectInput in DirectX 9.0c or before) and XACT (DirectSound/DirectMusic in DirectX 9.0c or before)
XNA provides managed wrappers for developer to use the functions

© VTC 2016
19
Role of XNA

20
Windows Game Architecture
Native (Unmanaged) Windows Game
Windows APIs
Windows
Kernel
Device
Drivers
With DirectX
DirectX APIs
DirectX
Drivers
Common Language Runtime
.NET Framework APIs
XNA Framework APIs

Windows-Based XNA Game
© VTC 2016

The XNA toolset was announced March 24, 2004.
A first Community Technology Preview of XNA Build was released on March 14, 2006.
XNA Game Studio 2.0 was released in December 2007.
XNA Game Studio 3.0 on October 30, 2008.
XNA Game Studio 4.0 was released on September 16, 2010 along with the Windows Phone Development Tools.
According to an email sent on 31 January 2013, XNA is no longer actively being developed, and it is not supported under the new “Metro interface” layers of Windows 8 nor on the Windows RT platform.
An open source cross platform version of the Microsoft XNA 4 Application programming interface called MonoGame is actively being developed.
© VTC 2016
21
XNA History

MonoGame is the evolution of XNA started by Jose Antonio Farias and Silver Sprite by Bill Reiss.
Since mid-2013, the framework has begun to be extended beyond XNA4 with the addition of new features like RenderTarget3D, support for multiple GameWindows, and a new cross-platform command line content building tool.
Support multi-platform including
MonoGame attempts to fully implement the XNA 4 API.
It accomplishes this across Microsoft platforms using SharpDX and DirectX.
When targeting non-Microsoft platforms, platform specific capabilities are utilized by way of the OpenTK library.
OpenTK (The Open Toolkit library), is a C# graphics library which provides access to graphics tools contained in OpenGL, OpenCL, and OpenAL to a variety of CLR-based languages (C#, F#, etc.).
© VTC 2016
22
MonoGame

To make full use of the MonoGame environment, including its Content Pipeline Tools, you should install your MonoGame in a 64-bit Windows environment
Theoretically, you can also install MonoGame in other platforms, but we focus on Windows platform in this module.
Install the Software
Visual Studio 2015 (Community Edition – It’s FREE)
Downloadable from www.visualstudio.com
Visual C# is installed by default.
You need to run the visual studio once and login/register the software so to finish the installation.
You may also need to install Universal Windows App Development Tools in Custom option to work on Windows application.
MonoGame 3.5 for Visual Studio
It’s also free.
Downloadable from www.monogame.net
© VTC 2016
23
Setup a MonoGame
Development Environment

Reference
Wikipedia topics
DirectX (http://en.wikipedia.org/wiki/DirectX)
OpenGL (http://en.wikipedia.org/wiki/OpenGL)
Comparison of OpenGL and Direct3D (http://en.wikipedia.org/wiki/Comparison_of_OpenGL_and_Direct3D)
Microsoft XNA (http://en.wikipedia.org/wiki/Microsoft_XNA)
MonoGame (http://en.wikipedia.org/wiki/MonoGame)
Tom Miller and Dean Johnson,
XNA Game Studio 4.0 Programming –
Developing for Windows Phone 7 and Xbox 360,
Addison-Wesley, 2011.
Appendix G
24
© VTC 2016

/docProps/thumbnail.jpeg