Commits

Vertexwahn committed 833bc1c

Added D3D create device demo.

Comments (0)

Files changed (4)

D3D11CreateDevice/CMakeLists.txt

+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+PROJECT(D3D11Demo)
+
+SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
+
+FIND_PACKAGE(DirectX REQUIRED)
+
+SET(SOURCES
+  src/main.cpp)
+
+SET(HEADERS
+  )
+
+INCLUDE_DIRECTORIES(
+  ${DirectX_INCLUDE_DIR}
+  include)
+
+SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
+
+SOURCE_GROUP(Source FILES ${SOURCES})
+SOURCE_GROUP(Headers FILES ${HEADERS})
+
+ADD_EXECUTABLE(D3D11Demo ${SOURCES})
+TARGET_LINK_LIBRARIES(D3D11Demo
+  ${DirectX_LIBRARY_DIR}/d3d11.lib)

D3D11CreateDevice/cmake/FindDirectX.cmake

+#-------------------------------------------------------------------
+# This file is part of the CMake build system for OGRE
+#     (Object-oriented Graphics Rendering Engine)
+# For the latest info, see http://www.ogre3d.org/
+#
+# The contents of this file are placed in the public domain. Feel
+# free to make use of it in any way you like.
+#-------------------------------------------------------------------
+
+# -----------------------------------------------------------------------------
+# Find DirectX SDK
+# Define:
+# DirectX_FOUND
+# DirectX_INCLUDE_DIR
+# DirectX_LIBRARY
+# DirectX_ROOT_DIR
+
+if(WIN32) # The only platform it makes sense to check for DirectX SDK
+  include(FindPkgMacros)
+  findpkg_begin(DirectX)
+  
+  # Get path, convert backslashes as ${ENV_DXSDK_DIR}
+  getenv_path(DXSDK_DIR)
+  getenv_path(DIRECTX_HOME)
+  getenv_path(DIRECTX_ROOT)
+  getenv_path(DIRECTX_BASE)
+  
+  # construct search paths
+  set(DirectX_PREFIX_PATH 
+    "${DXSDK_DIR}" "${ENV_DXSDK_DIR}"
+    "${DIRECTX_HOME}" "${ENV_DIRECTX_HOME}"
+    "${DIRECTX_ROOT}" "${ENV_DIRECTX_ROOT}"
+    "${DIRECTX_BASE}" "${ENV_DIRECTX_BASE}"
+    "C:/apps_x86/Microsoft DirectX SDK*"
+    "C:/Program Files (x86)/Microsoft DirectX SDK*"
+    "C:/apps/Microsoft DirectX SDK*"
+    "C:/Program Files/Microsoft DirectX SDK*"
+	"$ENV{ProgramFiles}/Microsoft DirectX SDK*"
+  )
+
+  # Windows 8 SDK has custom layout
+  set(DirectX_INC_SEARCH_PATH 
+	"C:/Program Files (x86)/Windows Kits/8.0/Include/um"
+  )
+  set(DirectX_LIB_SEARCH_PATH 
+    "C:/Program Files (x86)/Windows Kits/8.0/Lib/win8/um"
+  )
+
+  create_search_paths(DirectX)
+  # redo search if prefix path changed
+  clear_if_changed(DirectX_PREFIX_PATH
+    DirectX_LIBRARY
+	DirectX_INCLUDE_DIR
+  )
+  set(DirectX_INCLUDE_DIR 	"C:/Program Files (x86)/Windows Kits/8.0/Include/um"
+							"C:/Program Files (x86)/Windows Kits/8.0/Include/shared")
+  find_path(DirectX_INCLUDE_DIR NAMES d3d9.h HINTS ${DirectX_INC_SEARCH_PATH}) # does not work - so i set the path manually above
+  
+  message(STATUS "DirectX_INCLUDE_DIR: ${DirectX_INCLUDE_DIR}")
+ 
+  
+  # dlls are in DirectX_ROOT_DIR/Developer Runtime/x64|x86
+  # lib files are in DirectX_ROOT_DIR/Lib/x64|x86
+  if(CMAKE_CL_64)
+    set(DirectX_LIBPATH_SUFFIX "x64")
+  else(CMAKE_CL_64)
+    set(DirectX_LIBPATH_SUFFIX "x86")
+  endif(CMAKE_CL_64)
+  find_library(DirectX_LIBRARY NAMES d3d9 HINTS ${DirectX_LIB_SEARCH_PATH} PATH_SUFFIXES ${DirectX_LIBPATH_SUFFIX})
+  find_library(DirectX_D3DX9_LIBRARY NAMES d3dx9 HINTS ${DirectX_LIB_SEARCH_PATH} PATH_SUFFIXES ${DirectX_LIBPATH_SUFFIX})
+  find_library(DirectX_DXERR_LIBRARY NAMES DxErr HINTS ${DirectX_LIB_SEARCH_PATH} PATH_SUFFIXES ${DirectX_LIBPATH_SUFFIX})
+  find_library(DirectX_DXGUID_LIBRARY NAMES dxguid HINTS ${DirectX_LIB_SEARCH_PATH} PATH_SUFFIXES ${DirectX_LIBPATH_SUFFIX})
+  
+
+  # look for dxgi (needed by both 10 and 11)
+  find_library(DirectX_DXGI_LIBRARY NAMES dxgi HINTS ${DirectX_LIB_SEARCH_PATH} PATH_SUFFIXES ${DirectX_LIBPATH_SUFFIX})
+  
+  # look for d3dcompiler (needed by 11)
+  find_library(DirectX_D3DCOMPILER_LIBRARY NAMES d3dcompiler HINTS ${DirectX_LIB_SEARCH_PATH} PATH_SUFFIXES ${DirectX_LIBPATH_SUFFIX})
+
+  findpkg_finish(DirectX)
+  set(DirectX_LIBRARIES ${DirectX_LIBRARIES} 
+    ${DirectX_D3DX9_LIBRARY}
+    ${DirectX_DXERR_LIBRARY}
+    ${DirectX_DXGUID_LIBRARY}
+  )
+  
+  mark_as_advanced(DirectX_D3DX9_LIBRARY DirectX_DXERR_LIBRARY DirectX_DXGUID_LIBRARY
+    DirectX_DXGI_LIBRARY DirectX_D3DCOMPILER_LIBRARY)
+  
+
+  # look for D3D11 components
+  if (DirectX_FOUND)
+    find_path(DirectX_D3D11_INCLUDE_DIR NAMES D3D11Shader.h HINTS ${DirectX_INC_SEARCH_PATH})
+	get_filename_component(DirectX_LIBRARY_DIR "${DirectX_LIBRARY}" PATH)
+	message(STATUS "DX lib dir: ${DirectX_LIBRARY_DIR}")
+    find_library(DirectX_D3D11_LIBRARY NAMES d3d11 HINTS ${DirectX_LIB_SEARCH_PATH} PATH_SUFFIXES ${DirectX_LIBPATH_SUFFIX})
+    find_library(DirectX_D3DX11_LIBRARY NAMES d3dx11 HINTS ${DirectX_LIB_SEARCH_PATH} PATH_SUFFIXES ${DirectX_LIBPATH_SUFFIX})	
+	if (DirectX_D3D11_INCLUDE_DIR AND DirectX_D3D11_LIBRARY)
+	  set(DirectX_D3D11_FOUND TRUE)
+	  set(DirectX_D3D11_INCLUDE_DIR ${DirectX_D3D11_INCLUDE_DIR})
+	  set(DirectX_D3D11_LIBRARIES ${DirectX_D3D11_LIBRARIES}
+	    ${DirectX_D3D11_LIBRARY}
+	    ${DirectX_DXGI_LIBRARY}
+        ${DirectX_DXGUID_LIBRARY}
+        ${DirectX_D3DCOMPILER_LIBRARY}        	  
+      )	
+    endif ()
+    if (DirectX_D3DX11_LIBRARY)
+        set(DirectX_D3D11_LIBRARIES ${DirectX_D3D11_LIBRARIES} ${DirectX_D3DX11_LIBRARY})
+    endif ()
+    if (DirectX_DXERR_LIBRARY)
+        set(DirectX_D3D11_LIBRARIES ${DirectX_D3D11_LIBRARIES} ${DirectX_DXERR_LIBRARY})
+    endif ()
+	mark_as_advanced(DirectX_D3D11_INCLUDE_DIR DirectX_D3D11_LIBRARY DirectX_D3DX11_LIBRARY)
+  endif ()
+  
+endif(WIN32)

D3D11CreateDevice/cmake/FindPkgMacros.cmake

+#-------------------------------------------------------------------
+# This file is part of the CMake build system for OGRE
+#     (Object-oriented Graphics Rendering Engine)
+# For the latest info, see http://www.ogre3d.org/
+#
+# The contents of this file are placed in the public domain. Feel
+# free to make use of it in any way you like.
+#-------------------------------------------------------------------
+
+##################################################################
+# Provides some common functionality for the FindPackage modules
+##################################################################
+
+# Begin processing of package
+macro(findpkg_begin PREFIX)
+  if (NOT ${PREFIX}_FIND_QUIETLY)
+    message(STATUS "Looking for ${PREFIX}...")
+  endif ()
+endmacro(findpkg_begin)
+
+# Display a status message unless FIND_QUIETLY is set
+macro(pkg_message PREFIX)
+  if (NOT ${PREFIX}_FIND_QUIETLY)
+    message(STATUS ${ARGN})
+  endif ()
+endmacro(pkg_message)
+
+# Get environment variable, define it as ENV_$var and make sure backslashes are converted to forward slashes
+macro(getenv_path VAR)
+   set(ENV_${VAR} $ENV{${VAR}})
+   # replace won't work if var is blank
+   if (ENV_${VAR})
+     string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} )
+   endif ()
+endmacro(getenv_path)
+
+# Construct search paths for includes and libraries from a PREFIX_PATH
+macro(create_search_paths PREFIX)
+  foreach(dir ${${PREFIX}_PREFIX_PATH})
+    set(${PREFIX}_INC_SEARCH_PATH ${${PREFIX}_INC_SEARCH_PATH}
+      ${dir}/include ${dir}/Include ${dir}/include/${PREFIX} ${dir}/Headers)
+    set(${PREFIX}_LIB_SEARCH_PATH ${${PREFIX}_LIB_SEARCH_PATH}
+      ${dir}/lib ${dir}/Lib ${dir}/lib/${PREFIX} ${dir}/Libs)
+    set(${PREFIX}_BIN_SEARCH_PATH ${${PREFIX}_BIN_SEARCH_PATH}
+      ${dir}/bin)
+  endforeach(dir)
+  set(${PREFIX}_FRAMEWORK_SEARCH_PATH ${${PREFIX}_PREFIX_PATH})
+endmacro(create_search_paths)
+
+# clear cache variables if a certain variable changed
+macro(clear_if_changed TESTVAR)
+  # test against internal check variable
+  # HACK: Apparently, adding a variable to the cache cleans up the list
+  # a bit. We need to also remove any empty strings from the list, but
+  # at the same time ensure that we are actually dealing with a list.
+  list(APPEND ${TESTVAR} "")
+  list(REMOVE_ITEM ${TESTVAR} "")
+  if (NOT "${${TESTVAR}}" STREQUAL "${${TESTVAR}_INT_CHECK}")
+    message(STATUS "${TESTVAR} changed.")
+    foreach(var ${ARGN})
+      set(${var} "NOTFOUND" CACHE STRING "x" FORCE)
+    endforeach(var)
+  endif ()
+  set(${TESTVAR}_INT_CHECK ${${TESTVAR}} CACHE INTERNAL "x" FORCE)
+endmacro(clear_if_changed)
+
+# Try to get some hints from pkg-config, if available
+macro(use_pkgconfig PREFIX PKGNAME)
+  find_package(PkgConfig)
+  if (PKG_CONFIG_FOUND)
+    pkg_check_modules(${PREFIX} ${PKGNAME})
+  endif ()
+endmacro (use_pkgconfig)
+
+# Couple a set of release AND debug libraries (or frameworks)
+macro(make_library_set PREFIX)
+  if (${PREFIX}_FWK)
+    set(${PREFIX} ${${PREFIX}_FWK})
+  elseif (${PREFIX}_REL AND ${PREFIX}_DBG)
+    set(${PREFIX} optimized ${${PREFIX}_REL} debug ${${PREFIX}_DBG})
+  elseif (${PREFIX}_REL)
+    set(${PREFIX} ${${PREFIX}_REL})
+  elseif (${PREFIX}_DBG)
+    set(${PREFIX} ${${PREFIX}_DBG})
+  endif ()
+endmacro(make_library_set)
+
+# Generate debug names from given release names
+macro(get_debug_names PREFIX)
+  foreach(i ${${PREFIX}})
+    set(${PREFIX}_DBG ${${PREFIX}_DBG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i})
+  endforeach(i)
+endmacro(get_debug_names)
+
+# Add the parent dir from DIR to VAR 
+macro(add_parent_dir VAR DIR)
+  get_filename_component(${DIR}_TEMP "${${DIR}}/.." ABSOLUTE)
+  set(${VAR} ${${VAR}} ${${DIR}_TEMP})
+endmacro(add_parent_dir)
+
+# Do the final processing for the package find.
+macro(findpkg_finish PREFIX)
+  # skip if already processed during this run
+  if (NOT ${PREFIX}_FOUND)
+    if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
+      set(${PREFIX}_FOUND TRUE)
+      set(${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
+      set(${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
+      if (NOT ${PREFIX}_FIND_QUIETLY)
+        message(STATUS "Found ${PREFIX}: ${${PREFIX}_LIBRARIES}")
+      endif ()
+    else ()
+      if (NOT ${PREFIX}_FIND_QUIETLY)
+        message(STATUS "Could not locate ${PREFIX}")
+      endif ()
+      if (${PREFIX}_FIND_REQUIRED)
+        message(FATAL_ERROR "Required library ${PREFIX} not found! Install the library (including dev packages) and try again. If the library is already installed, set the missing variables manually in cmake.")
+      endif ()
+    endif ()
+
+    mark_as_advanced(${PREFIX}_INCLUDE_DIR ${PREFIX}_LIBRARY ${PREFIX}_LIBRARY_REL ${PREFIX}_LIBRARY_DBG ${PREFIX}_LIBRARY_FWK)
+  endif ()
+endmacro(findpkg_finish)
+
+
+# Slightly customised framework finder
+macro(findpkg_framework fwk)
+  if(APPLE)
+    set(${fwk}_FRAMEWORK_PATH
+      ${${fwk}_FRAMEWORK_SEARCH_PATH}
+      ${CMAKE_FRAMEWORK_PATH}
+      ~/Library/Frameworks
+      /Library/Frameworks
+      /System/Library/Frameworks
+      /Network/Library/Frameworks
+      ${CMAKE_CURRENT_SOURCE_DIR}/lib/Release
+      ${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug
+    )
+    # These could be arrays of paths, add each individually to the search paths
+    foreach(i ${OGRE_PREFIX_PATH})
+      set(${fwk}_FRAMEWORK_PATH ${${fwk}_FRAMEWORK_PATH} ${i}/lib/Release ${i}/lib/Debug)
+    endforeach(i)
+
+    foreach(i ${OGRE_PREFIX_BUILD})
+      set(${fwk}_FRAMEWORK_PATH ${${fwk}_FRAMEWORK_PATH} ${i}/lib/Release ${i}/lib/Debug)
+    endforeach(i)
+
+    foreach(dir ${${fwk}_FRAMEWORK_PATH})
+      set(fwkpath ${dir}/${fwk}.framework)
+      if(EXISTS ${fwkpath})
+        set(${fwk}_FRAMEWORK_INCLUDES ${${fwk}_FRAMEWORK_INCLUDES}
+          ${fwkpath}/Headers ${fwkpath}/PrivateHeaders)
+        set(${fwk}_FRAMEWORK_PATH ${dir})
+        if (NOT ${fwk}_LIBRARY_FWK)
+          set(${fwk}_LIBRARY_FWK "-framework ${fwk}")
+        endif ()
+      endif(EXISTS ${fwkpath})
+    endforeach(dir)
+  endif(APPLE)
+endmacro(findpkg_framework)

D3D11CreateDevice/src/main.cpp

+#define UNICODE
+#include <windows.h>
+#include <d3d11.h>
+#include <iostream>
+
+// link D3D libraries with linker
+#pragma comment (lib, "dxgi.lib")
+#pragma comment (lib, "d3d11.lib")
+
+//--------------------------------------------------------------------------------------
+// Global Variables
+//--------------------------------------------------------------------------------------
+HINSTANCE               g_hInst = NULL;
+HWND                    g_hWnd = NULL;
+D3D_DRIVER_TYPE         g_driverType = D3D_DRIVER_TYPE_NULL;
+D3D_FEATURE_LEVEL       g_featureLevel = D3D_FEATURE_LEVEL_11_0;
+ID3D11Device*           g_pd3dDevice = NULL;
+ID3D11DeviceContext*    g_pImmediateContext = NULL;
+IDXGISwapChain*         g_pSwapChain = NULL;
+ID3D11RenderTargetView* g_pRenderTargetView = NULL;
+
+
+//--------------------------------------------------------------------------------------
+// Forward declarations
+//--------------------------------------------------------------------------------------
+HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow );
+HRESULT InitDevice();
+void CleanupDevice();
+LRESULT CALLBACK    WndProc( HWND, UINT, WPARAM, LPARAM );
+void Render();
+
+
+//--------------------------------------------------------------------------------------
+// Entry point to the program. Initializes everything and goes into a message processing 
+// loop. Idle time is used to render the scene.
+//--------------------------------------------------------------------------------------
+int main()
+{
+	auto hInstance = GetModuleHandle (0);
+	if( FAILED( InitWindow( hInstance, SW_SHOW ) ) )
+		return 0;
+
+	if( FAILED( InitDevice() ) )
+	{
+		CleanupDevice();
+		return 0;
+	}
+
+	// Main message loop
+	MSG msg = {0};
+	while( WM_QUIT != msg.message )
+	{
+		if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
+		{
+			TranslateMessage( &msg );
+			DispatchMessage( &msg );
+		}
+		else
+		{
+			Render();
+		}
+	}
+
+	CleanupDevice();
+
+	return ( int )msg.wParam;
+}
+
+
+//--------------------------------------------------------------------------------------
+// Register class and create window
+//--------------------------------------------------------------------------------------
+HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow )
+{
+    // Register class
+    WNDCLASSEX wcex;
+    wcex.cbSize = sizeof( WNDCLASSEX );
+    wcex.style = CS_HREDRAW | CS_VREDRAW;
+    wcex.lpfnWndProc = WndProc;
+    wcex.cbClsExtra = 0;
+    wcex.cbWndExtra = 0;
+    wcex.hInstance = hInstance;
+    wcex.hIcon = 0;
+    wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
+    wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
+    wcex.lpszMenuName = NULL;
+    wcex.lpszClassName = L"TutorialWindowClass";
+    wcex.hIconSm = 0;
+    if( !RegisterClassEx( &wcex ) )
+        return E_FAIL;
+
+    // Create window
+    g_hInst = hInstance;
+    RECT rc = { 0, 0, 640, 480 };
+    AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
+    g_hWnd = CreateWindow( L"TutorialWindowClass", L"Direct3D 11 Tutorial 1: Direct3D 11 Basics", WS_OVERLAPPEDWINDOW,
+                           CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance,
+                           NULL );
+    if( !g_hWnd )
+        return E_FAIL;
+
+    ShowWindow( g_hWnd, nCmdShow );
+
+    return S_OK;
+}
+
+
+//--------------------------------------------------------------------------------------
+// Called every time the application receives a message
+//--------------------------------------------------------------------------------------
+LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
+{
+    PAINTSTRUCT ps;
+    HDC hdc;
+
+    switch( message )
+    {
+        case WM_PAINT:
+            hdc = BeginPaint( hWnd, &ps );
+            EndPaint( hWnd, &ps );
+            break;
+
+        case WM_DESTROY:
+            PostQuitMessage( 0 );
+            break;
+
+        default:
+            return DefWindowProc( hWnd, message, wParam, lParam );
+    }
+
+    return 0;
+}
+
+
+//--------------------------------------------------------------------------------------
+// Create Direct3D device and swap chain
+//--------------------------------------------------------------------------------------
+HRESULT InitDevice()
+{
+    HRESULT hr = S_OK;
+
+    RECT rc;
+    GetClientRect( g_hWnd, &rc );
+    UINT width = rc.right - rc.left;
+    UINT height = rc.bottom - rc.top;
+
+    UINT createDeviceFlags = 0;
+   
+	IDXGIFactory1* mpDXGIFactory = nullptr;
+	hr = CreateDXGIFactory1( __uuidof(IDXGIFactory1), (void**)&mpDXGIFactory );
+	if( FAILED(hr) )
+	{
+		std::cout << "Failed to create Direct3D11 DXGIFactoryN" << std::endl;
+	}
+
+	UINT deviceFlags = 0;
+
+	//----------------------------------------------
+	// 1. Create a device
+	//----------------------------------------------
+
+	D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_NULL;
+	D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
+	D3D_DRIVER_TYPE driverTypes[] =	{ D3D_DRIVER_TYPE_HARDWARE }; // we are only interested in hardware rendering
+	UINT numDriverTypes = ARRAYSIZE( driverTypes );
+	D3D_FEATURE_LEVEL requestedFeatureLevels[1] = {	D3D_FEATURE_LEVEL_11_0	};
+
+	UINT numFeatureLevels = ARRAYSIZE( requestedFeatureLevels );
+
+#ifdef _DEBUG
+		deviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
+#endif
+
+	hr = D3D11CreateDevice(nullptr,
+		driverType,
+		nullptr,
+		deviceFlags, 
+		requestedFeatureLevels, 
+		1,
+		D3D11_SDK_VERSION, 
+		&g_pd3dDevice, 
+		&featureLevel, 
+		0);
+
+	if( FAILED(hr) )
+	{
+		std::cout << "Failed!" << std::endl;
+	}
+
+	g_pd3dDevice->GetImmediateContext(&g_pImmediateContext);
+
+	//----------------------------------------------
+	// 2. Create a swap chain
+	//----------------------------------------------
+
+    DXGI_SWAP_CHAIN_DESC sd;
+    ZeroMemory( &sd, sizeof( sd ) );
+    sd.BufferCount = 1;
+    sd.BufferDesc.Width = width;
+    sd.BufferDesc.Height = height;
+    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+    sd.BufferDesc.RefreshRate.Numerator = 60;
+    sd.BufferDesc.RefreshRate.Denominator = 1;
+    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+    sd.OutputWindow = g_hWnd;
+    sd.SampleDesc.Count = 1;
+    sd.SampleDesc.Quality = 0;
+    sd.Windowed = TRUE;
+
+	// Create swap chain			
+	hr = mpDXGIFactory->CreateSwapChain(g_pd3dDevice, 
+		&sd, &g_pSwapChain);
+
+	if (FAILED(hr))
+	{
+		// Try a second time, may fail the first time due to back buffer count,
+		// which will be corrected by the runtime
+		hr = mpDXGIFactory->CreateSwapChain(g_pd3dDevice, 
+			&sd, &g_pSwapChain);
+	}
+
+
+    if( FAILED( hr ) )
+        return hr;
+
+    // Create a render target view
+    ID3D11Texture2D* pBackBuffer = NULL;
+    hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
+    if( FAILED( hr ) )
+        return hr;
+
+    hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
+    pBackBuffer->Release();
+    if( FAILED( hr ) )
+        return hr;
+
+    g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );
+
+    // Setup the viewport
+    D3D11_VIEWPORT vp;
+    vp.Width = (FLOAT)width;
+    vp.Height = (FLOAT)height;
+    vp.MinDepth = 0.0f;
+    vp.MaxDepth = 1.0f;
+    vp.TopLeftX = 0;
+    vp.TopLeftY = 0;
+    g_pImmediateContext->RSSetViewports( 1, &vp );
+
+    return S_OK;
+}
+
+
+//--------------------------------------------------------------------------------------
+// Render the frame
+//--------------------------------------------------------------------------------------
+void Render()
+{
+    // Just clear the backbuffer
+    float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha
+    g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor );
+    g_pSwapChain->Present( 0, 0 );
+}
+
+
+//--------------------------------------------------------------------------------------
+// Clean up the objects we've created
+//--------------------------------------------------------------------------------------
+void CleanupDevice()
+{
+    if( g_pImmediateContext ) g_pImmediateContext->ClearState();
+
+    if( g_pRenderTargetView ) g_pRenderTargetView->Release();
+    if( g_pSwapChain ) g_pSwapChain->Release();
+    if( g_pImmediateContext ) g_pImmediateContext->Release();
+    if( g_pd3dDevice ) g_pd3dDevice->Release();
+}