Beruflich Dokumente
Kultur Dokumente
Collusion occurs when a student obtains the agreement of another person for a
fraudulent purpose with the intent of obtaining an advantage in submitting an
assignment or other work
Declaration
I certify that the attached work is entirely my own (or where submitted to meet the
requirements of an approved group assignment is the work of the group), except where
work quoted or paraphrased is acknowledged in the text. I also certify that it has not
been submitted for assessment in any other unit or course.
I agree that Deakin University may make and retain copies of this work for the purposes
of marking and review, and may submit this work to an external plagiarism-detection
service who may retain a copy for future plagiarism detection but will not release it or
use it for any other purpose.
DATE: 29/7/2010________________________________
An assignment will not be accepted for assessment if the declaration appearing above
has not been duly completed by the author.
/*
*******************************************************************
******************* READ BEFORE VIEWING ********************
*******************************************************************
THIS TUTORIAL TEACHES A STUDENT HOW TO INITIALIZE THE GRAPHICS
DEVICES FOR DIRECT3D. THEY ARE ASSUMED TO HAVE BASIC KNOWLEDGE
OF C++ AS WELL AS KNOW HOW TO SET UP VISUAL STUDIO DIRECT3D SDK
THANKYOU AND ENJOY
*******************************************************************
*******************************************************************
*/
#include<windows.h>
#include<d3d9.h>
#include<d3dx9.h>
/* These first few lines are used to import the standard libraries
into your winMain.cpp file. It includes the windows.h file, which
has the basic windows functionality as well as the direct9 and
directX9 libraries for doing any directX work. */
#define WINDOW_NAME L"Creating a triangle with DirectX"
#define WINDOW_CLASS L"UPGCLASS"
#define WINDOW_WIDTH 1280
#define WINDOW_HEIGHT 1024
/* These lines define the constant values within the program.
Defining the window name (the name that appears on the taskbar),
the width and height of the window and the base windows class
being used. */
// Create the function that will be called any time the window gets
resized.
void ResizeD3D9Window(int width, int height)
{
if(g_d3dDevice == NULL)
return;
// If there is no direct3d object, jump out of the function.
D3DVIEWPORT9 viewport;
viewport.X = 0;
viewport.Y = 0;
viewport.Width = width;
viewport.Height = height;
viewport.MinZ = 0.0f;
viewport.MaxZ = 1.0f;
/*Create and define a viewport setting the new screen to the top
left hand corner and making it the size of the resized window */
g_d3dDevice->SetViewport(&viewport);
// Set the direct3d object's viewport to the one we just created
ZeroMemory(¶ms, sizeof(params));
g_d3dObject = Direct3DCreate9(D3D_SDK_VERSION);
// Attempts to create a direct3d object
if(g_d3dObject == NULL) // If it can't create the direct3d object,
return false
return false;
HRESULT hr;
hr = g_d3dObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,
&displayMode); // finds out the
graphics cards display mode
if(FAILED(hr))
return false; // if it can't find the display mode, exit.
hr = g_d3dObject->GetDeviceCaps(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL, &caps); // finds the
limitations of the device
if(FAILED(hr))
return false; // if it can't find any, exit.
DWORD flags = 0;
// Use hardware if it was found, else software.
if(caps.VertexProcessingCaps != 0)
flags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
else
flags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
params.Windowed = TRUE;
params.SwapEffect = D3DSWAPEFFECT_DISCARD;
params.BackBufferFormat = displayMode.Format;
params.BackBufferCount = 1;
params.EnableAutoDepthStencil = TRUE;
params.AutoDepthStencilFormat = D3DFMT_D16;
// Just setting up some base values for the parameters
hr = g_d3dObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
g_hwnd, flags, ¶ms, &g_d3dDevice);
// Sets the direct3d object to the device that was just created
if(FAILED(hr) || g_d3dDevice == NULL)
return false; // once again, checking if it's all okay and if not -
exiting.
return true;
}
bool InitializeDemo()
{
// sets the device so that their aren't any light sources
g_d3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
// States that there will be no culling
g_d3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
Vertex obj[] =
{
{-0.3f, -0.3f, 1.0f, D3DCOLOR_XRGB(255, 0, 00)},
{ 0.3f, -0.3f, 1.0f, D3DCOLOR_XRGB(0, 255, 0)},
{ 0.0f, 0.3f, 1.0f, D3DCOLOR_XRGB(0, 0, 255)}
}; // Creates the verticies for our amazing triangle
if(FAILED(hr))
return false;
// copies the verticies over to the memory
memcpy(ptr, obj, sizeof(obj));
g_vertexBuffer->Unlock(); // unlocks the memory
return true;
}
void Update()
{
// This is where any real-time updates to the scene are done
}
g_d3dDevice->SetFVF(D3DFVF_D3DVertex);
ResizeD3D9Window(width, height);
return 0;
break;
default:
break;
}
break;
default:
break;
}
// Describes a window.
WNDCLASSEX windowClass;
memset(&windowClass, 0, sizeof(WNDCLASSEX));
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.lpszClassName = WINDOW_CLASS;
windowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
//just some basic variables for the window
if(!RegisterClassEx(&windowClass))
return 0;
// if the class couldn't be registered, exit.
if(!g_hwnd)
return 0;
// if the window wasn't successfully created, exit
ShowWindow(g_hwnd, SW_SHOW); // Present the window
UpdateWindow(g_hwnd); // Updates the window