Direct3D 10 Introduction – The sdk tutorials

Дата канвертавання19.04.2016
Памер15.53 Kb.

Direct3D 10

Introduction – The SDK Tutorials

This exercise does not count towards the Lab Assignments
In this lab you will work through the first three “official” Direct3D tutorials from the DirectX SDK. You will use the walkthroughs in the DirectX documentation and the notes below.

WARNING: DirectX is complex. The tutorial code is intricate & more advanced than any first year material. However, this is just an introduction to get the feel of DirectX programs. We will look at everything in more detail later – Don’t Panic!

Getting Started

  • Go to the module (CO2409) page and download the Direct3D Tutorials 1 zip file. Unzip it to your work folder. Ensure to keep the folder structure (use ‘Extract Here’).

  • Open the ‘Tutorial00’ project and run it, you should get a white window. Close it

  • In the “Windows” menu, “All Programs”, find the “Microsoft DirectX SDK” folder. In this folder open the “DirectX Documentation for C++”

  • In the documentation contents, browse to “Samples and Tutorials >> Direct3D 10 >> Tutorials >> Basic Tutorials >> Tutorial 0: Win32 Basics”

  • This will lead you to a summary of the project you just ran.

  • First read my notes below and then have a look at the tutorial documentation page (there’s not much to say about the first exercise).

Tutorial 0 – Creating a Window

The first tutorial does not concern DirectX; it just shows the minimum needed to create a window. This is required for all DirectX programs, but we will rarely work with this code.

This program is a traditional Windows application and quite different to a console program. The main function becomes WWinMain and contains various calls to create and initialise a window. The InitWindow function sets the title and size of the window amongst other details. The MsgProc function handles Windows messages. These messages can communicate such things as the closing, resizing or minimising of the window. They can also be used for simple mouse and keyboard input if necessary. However, this example does very little message processing.
This is actually a very old style of creating a Windows program. If we were developing a full windows application (like the recent 2D labs), then we would use a visual editor and the resulting code would be different. However, when creating a 3D application we generally perform the minimum possible Windows programming before launching the 3D API code, so this older simple style is favoured (even by Microsoft).
Tutorial 0 - Exercises

  1. Change the title of the window (make sure it works!)

  2. Work out how to change the initial size of the window

Tutorial 1 – Creating a Direct3D 10 Application

  1. Open the “Tutorial01” project. Run it, you should see a blue screen this time.

  2. Go to the documentation for this tutorial (“Direct3D 10 Basics”). However, read my notes below first.

This tutorial shows how to setup & shutdown Direct3D. Although this is a very basic operation it involves some intricate detail, which is typical of DirectX programming. When learning DirectX you must learn to identify the elements of the code that are important to the task at hand and to ignore the large amount of less relevant detail. Do not expect to understand every line of a DirectX program until you are a complete master.

Program Structure

All the tutorials use the same basic code structure as this tutorial:

Include Files

Global Variables

Forward declarations
InitDevice: Function to setup Direct3D and setup geometry etc.

CleanupDevice: Function to shutdown Direct3D

Render: Function to draw the current scene
wWinMain: The ‘main’ function for a Windows program – where the program starts

InitWindow: Creates the window into which we render

WndProc: A function to handle Windows messages

Overview / Terminology

The windows code from the last tutorial has been updated:

- When the window is first created, the function InitDevice is called to prepare D3D.

- Whilst the window is active, the function Render is called repeatedly

- When the window is shutdown, the function CleanupDevice is called
The key concept for this tutorial is the back buffer. Direct3D does not draw directly to the screen – when D3D is initialised, an off-screen buffer (effectively a bitmap) is also created to hold what we are currently drawing. When you clear the window or draw polygons or lines etc., they are actually drawn in the off-screen buffer. Then, when the drawing is finished, we instruct Direct3D to present (Microsoft word) the off-screen buffer to the screen. The off-screen buffer is called a back buffer, the screen itself is sometimes called the front-buffer. The pairing and swapping of back and front buffer is called a swap-chain. We will discuss these concepts in more depth later.

Code Walkthrough

  • The code has been annotated from the original tutorial. Step through it carefully reading the comments and seeing how the associated code relates. Recall that you are not expected to understand much of the detail at this point. Ask your tutor for clarification as required.

  • Next read the SDK documentation associated with the tutorial, it provides extra detail, although it occasionally goes into too much depth.

Tutorial 1 Exercises

  1. Change the colour rendered to the window to grey

  2. Explain what advantages might there be in using a back buffer

  3. Get the D3D device to be created full-screen

  4. Can you change the refresh rate? Can you tell if you did it? What issues are there here?

  5. Experiment with changing the viewport size (not the window size)

Tutorial 2 – Working with Vertices - Drawing a Triangle

  • Open the “Tutorial02” project. Run it, you should see a yellow triangle.

  • Go to the documentation for this tutorial (“Rendering a Triangle”) - don’t read it yet

  • Again walk through the code reading the comments carefully. Skip comments you have already read in the previous tutorial, but note that there is a lot of new material in this tutorial and getting to grips with it is key to the rest of the module.

  • The comments refer you to the documentation in places. After you have read the code, read the SDK documentation in more detail, but feel free to skip some areas that go into too much detail.

Tutorial 2 Exercises

  1. Change the vertex data to draw a right-angled triangle.

  2. Update the program to draw two triangles

  • Try to form have the triangles form a square

  1. Can you draw your square using a triangle strip? Refer to the SDK documentation to see the data you will need. Be careful, this is tricky.

  2. Open Tutorial02.fx, these are the shaders used for rendering. We haven’t covered shaders, but see if you can change the colour of the triangle.

  3. Can you do anything in the vertex shader?

CO2409 - Computer, Week 5

Lab Worksheet 1-

База данных защищена авторским правом © 2016
звярнуцца да адміністрацыі

    Галоўная старонка