Apparently we're doing OpenGL now
This commit is contained in:
+8
-2
@@ -1,18 +1,24 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
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
|
||||
MinSizeRel|Win32 = MinSizeRel|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
RelWithDebInfo|Win32 = RelWithDebInfo|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}.MinSizeRel|Win32.ActiveCfg = Release|Win32
|
||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.MinSizeRel|Win32.Build.0 = Release|Win32
|
||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.Release|Win32.Build.0 = Release|Win32
|
||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32
|
||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.RelWithDebInfo|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
#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();
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef Direct3D_h__
|
||||
#define Direct3D_h__
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <d3dx11.h>
|
||||
#include <d3dx10.h>
|
||||
#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__
|
||||
@@ -19,12 +19,14 @@
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
@@ -72,13 +74,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Direct3D.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Window.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Direct3D.h" />
|
||||
<ClInclude Include="Window.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
||||
@@ -18,19 +18,5 @@
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Direct3D.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Window.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Direct3D.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Window.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,69 +0,0 @@
|
||||
#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<long>(LPCREATESTRUCT(lParam)->lpCreateParams));
|
||||
|
||||
Window* wnd = reinterpret_cast<Window*>(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<void*>(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);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef Window_h__
|
||||
#define Window_h__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
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__
|
||||
@@ -1,57 +1,4 @@
|
||||
#include <Windows.h>
|
||||
#include <WindowsX.h>
|
||||
|
||||
#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);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user