commit f14b733bd0d988effd4ea85f057ab5a64e9ce296 Author: sippeangelo Date: Tue Jan 28 21:01:37 2014 +0100 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e58a2d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +# Build Folders (you can keep bin if you'd like, to store dlls and pdbs) +bin +obj + +# Visual Studio files +*.[Oo]bj +*.user +*.aps +*.pch +*.vspscc +*.vssscc +*_i.c +*_p.c +*.ncb +*.suo +*.tlb +*.tlh +*.bak +*.[Cc]ache +*.ilk +*.log +*.lib +*.sbr +*.sdf +*.opensdf +*.unsuccessfulbuild +ipch/ +obj/ +[Bb]in +[Dd]ebug*/ +[Rr]elease*/ +Ankh.NoLoad + +# Resharper +_ReSharper*/ +*.resharper + +# mstest test results +TestResults \ No newline at end of file diff --git a/Escape-the-Dawn.sln b/Escape-the-Dawn.sln new file mode 100644 index 0000000..8827c46 --- /dev/null +++ b/Escape-the-Dawn.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Escape-the-Dawn", "Escape-the-Dawn\Escape-the-Dawn.vcxproj", "{FE405CFA-8FCE-4867-92CF-797E73B36482}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FE405CFA-8FCE-4867-92CF-797E73B36482}.Debug|Win32.ActiveCfg = Debug|Win32 + {FE405CFA-8FCE-4867-92CF-797E73B36482}.Debug|Win32.Build.0 = Debug|Win32 + {FE405CFA-8FCE-4867-92CF-797E73B36482}.Release|Win32.ActiveCfg = Release|Win32 + {FE405CFA-8FCE-4867-92CF-797E73B36482}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Escape-the-Dawn/Direct3D.cpp b/Escape-the-Dawn/Direct3D.cpp new file mode 100644 index 0000000..5e2a0c0 --- /dev/null +++ b/Escape-the-Dawn/Direct3D.cpp @@ -0,0 +1,76 @@ +#include "Direct3D.h" + +void Direct3D::Initialize(Window* window) +{ + m_Window = window; + + DXGI_SWAP_CHAIN_DESC scd = { 0 }; + scd.BufferCount = 1; + scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + scd.OutputWindow = window->GetHandle(); + scd.SampleDesc.Count = 4; + scd.Windowed = TRUE; + scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + + D3D11CreateDeviceAndSwapChain( + NULL, + D3D_DRIVER_TYPE_HARDWARE, + NULL, + NULL, + NULL, + NULL, + D3D11_SDK_VERSION, + &scd, + &SwapChain, + &Device, + NULL, + &DeviceContext); + + // Set the back buffer render target + ID3D11Texture2D* pBackBuffer; + SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer); + Device->CreateRenderTargetView(pBackBuffer, NULL, &BackBuffer); + pBackBuffer->Release(); + DeviceContext->OMSetRenderTargets(1, &BackBuffer, NULL); + + // Set the viewport + D3D11_VIEWPORT viewport = { 0 }; + viewport.TopLeftX = 0; + viewport.TopLeftY = 0; + viewport.Width = window->GetWidth(); + viewport.Height = window->GetHeight(); + DeviceContext->RSSetViewports(1, &viewport); +} + +void Direct3D::Resize(int width, int height) +{ + DeviceContext->OMSetRenderTargets(0, 0, 0); + BackBuffer->Release(); + + HRESULT hr; // TODO: Error handling + // Preserve the existing buffer count and format. + hr = SwapChain->ResizeBuffers(0, width, height, DXGI_FORMAT_UNKNOWN, 0); + + ID3D11Texture2D* pBuffer; + hr = SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBuffer); + hr = Device->CreateRenderTargetView(pBuffer, NULL, &BackBuffer); + pBuffer->Release(); + DeviceContext->OMSetRenderTargets(1, &BackBuffer, NULL); + + // Set the viewport + D3D11_VIEWPORT viewport = { 0 }; + viewport.TopLeftX = 0; + viewport.TopLeftY = 0; + viewport.Width = width; + viewport.Height = height; + DeviceContext->RSSetViewports(1, &viewport); +} + +Direct3D::~Direct3D() +{ + SwapChain->Release(); + BackBuffer->Release(); + Device->Release(); + DeviceContext->Release(); +} \ No newline at end of file diff --git a/Escape-the-Dawn/Direct3D.h b/Escape-the-Dawn/Direct3D.h new file mode 100644 index 0000000..b2338bd --- /dev/null +++ b/Escape-the-Dawn/Direct3D.h @@ -0,0 +1,31 @@ +#ifndef Direct3D_h__ +#define Direct3D_h__ + +#include +#include +#include +#pragma comment (lib, "d3d11.lib") +#pragma comment (lib, "d3dx11.lib") +#pragma comment (lib, "d3dx10.lib") + +#include "Window.h" + +class Direct3D +{ +public: + Direct3D() { } + ~Direct3D(); + + IDXGISwapChain* SwapChain; + ID3D11Device* Device; + ID3D11DeviceContext* DeviceContext; + ID3D11RenderTargetView* BackBuffer; + + void Initialize(Window* window); + void Resize(int width, int height); + +private: + Window* m_Window; +}; + +#endif // Direct3D_h__ \ No newline at end of file diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj b/Escape-the-Dawn/Escape-the-Dawn.vcxproj new file mode 100644 index 0000000..6dcf58e --- /dev/null +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj @@ -0,0 +1,86 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {FE405CFA-8FCE-4867-92CF-797E73B36482} + EscapetheDawn + + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath) + + + C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;$(LibraryPath) + + + C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath) + + + C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;$(LibraryPath) + + + + Level3 + Disabled + + + true + Console + + + + + Level3 + MaxSpeed + true + true + + + true + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters new file mode 100644 index 0000000..8ab4e70 --- /dev/null +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/Escape-the-Dawn/Window.cpp b/Escape-the-Dawn/Window.cpp new file mode 100644 index 0000000..745198a --- /dev/null +++ b/Escape-the-Dawn/Window.cpp @@ -0,0 +1,69 @@ +#include "Window.h" + +LRESULT CALLBACK Window::MsgRouter(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (msg == WM_CREATE) + SetWindowLong(hWnd, GWL_USERDATA, reinterpret_cast(LPCREATESTRUCT(lParam)->lpCreateParams)); + + Window* wnd = reinterpret_cast(GetWindowLong(hWnd, GWL_USERDATA)); + + if (wnd) + return wnd->WndProc(msg, wParam, lParam); + else + return DefWindowProc(hWnd, msg, wParam, lParam); +} + +void Window::Create(std::string title, int width, int height) +{ + m_Width = width; + m_Height = height; + + WNDCLASSEX wc = { 0 }; + wc.cbSize = sizeof(WNDCLASSEX); + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = Window::MsgRouter; + wc.hInstance = m_hInstance; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)COLOR_WINDOW; + wc.lpszClassName = "WindowClass1"; + + // register the window class + RegisterClassEx(&wc); + + // create the window and use the result as the handle + m_hWnd = CreateWindowEx( + NULL, + "WindowClass1", + title.c_str(), + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, + CW_USEDEFAULT, + width, + height, + NULL, + NULL, + m_hInstance, + reinterpret_cast(this)); +} + +void Window::Show(int nCmdShow /*= SW_SHOW*/) +{ + ShowWindow(m_hWnd, nCmdShow); +} + +LRESULT CALLBACK Window::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_CREATE: + OutputDebugString("WM_CREATE\n"); + case WM_CLOSE: + DestroyWindow(m_hWnd); + return 0; + case WM_DESTROY: + PostQuitMessage(0); + return 0; + default: + return DefWindowProc(m_hWnd, msg, wParam, lParam); + } +} \ No newline at end of file diff --git a/Escape-the-Dawn/Window.h b/Escape-the-Dawn/Window.h new file mode 100644 index 0000000..d738dec --- /dev/null +++ b/Escape-the-Dawn/Window.h @@ -0,0 +1,32 @@ +#ifndef Window_h__ +#define Window_h__ + +#include + +#include + +class Window +{ +public: + Window(HINSTANCE hInstance) + : m_hInstance(hInstance) { } + + HWND GetHandle() { return m_hWnd; } + int GetWidth() { return m_Width; } + int GetHeight() { return m_Height; } + + void Create(std::string title, int width, int height); + void Show(int nCmdShow = SW_SHOW); + + static LRESULT CALLBACK MsgRouter(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + +protected: + HWND m_hWnd; + HINSTANCE m_hInstance; + int m_Width; + int m_Height; + + virtual LRESULT CALLBACK WndProc(UINT msg, WPARAM wParam, LPARAM lParam); +}; + +#endif // Window_h__ \ No newline at end of file diff --git a/Escape-the-Dawn/main.cpp b/Escape-the-Dawn/main.cpp new file mode 100644 index 0000000..499906a --- /dev/null +++ b/Escape-the-Dawn/main.cpp @@ -0,0 +1,57 @@ +#include +#include + +#include "Direct3D.h" +#include "Window.h" + +Direct3D* d3d; + +void Update(); +void Draw(); + +//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +int main(int argc, char* argv[]) +{ + HINSTANCE hInstance = GetModuleHandle(NULL); + + d3d = new Direct3D(); + + Window wnd(hInstance); + wnd.Create("Escape the Dawn", 1280, 720); + d3d->Initialize(&wnd); + wnd.Show(); + + MSG msg = { 0 }; + while (true) + { + // Check to see if any messages are waiting in the queue + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + + if (msg.message == WM_QUIT) + break; + } + else + { + Update(); + Draw(); + } + } + + // return this part of the WM_QUIT message to Windows + return msg.wParam; +} + +void Update() +{ + +} + +void Draw() +{ + d3d->DeviceContext->ClearRenderTargetView(d3d->BackBuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f)); + + d3d->SwapChain->Present(0, 0); +} \ No newline at end of file