Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
831380f6
Commit
831380f6
authored
Jan 14, 2019
by
chili
Browse files
graphics twerking, doing a thing
parent
73eda06a
Changes
7
Hide whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
831380f6
...
@@ -21,5 +21,5 @@ int App::Go()
...
@@ -21,5 +21,5 @@ int App::Go()
void
App
::
DoFrame
()
void
App
::
DoFrame
()
{
{
wnd
.
Gfx
().
EndFrame
();
}
}
\ No newline at end of file
hw3d/Graphics.cpp
0 → 100644
View file @
831380f6
#include "Graphics.h"
#pragma comment(lib,"d3d11.lib")
Graphics
::
Graphics
(
HWND
hWnd
)
{
DXGI_SWAP_CHAIN_DESC
sd
=
{};
sd
.
BufferDesc
.
Width
=
0
;
sd
.
BufferDesc
.
Height
=
0
;
sd
.
BufferDesc
.
Format
=
DXGI_FORMAT_B8G8R8A8_UNORM
;
sd
.
BufferDesc
.
RefreshRate
.
Numerator
=
0
;
sd
.
BufferDesc
.
RefreshRate
.
Denominator
=
0
;
sd
.
BufferDesc
.
Scaling
=
DXGI_MODE_SCALING_UNSPECIFIED
;
sd
.
BufferDesc
.
ScanlineOrdering
=
DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED
;
sd
.
SampleDesc
.
Count
=
1
;
sd
.
SampleDesc
.
Quality
=
0
;
sd
.
BufferUsage
=
DXGI_USAGE_RENDER_TARGET_OUTPUT
;
sd
.
BufferCount
=
1
;
sd
.
OutputWindow
=
hWnd
;
sd
.
Windowed
=
TRUE
;
sd
.
SwapEffect
=
DXGI_SWAP_EFFECT_DISCARD
;
sd
.
Flags
=
0
;
// create device and front/back buffers, and swap chain and rendering context
D3D11CreateDeviceAndSwapChain
(
nullptr
,
D3D_DRIVER_TYPE_HARDWARE
,
nullptr
,
0
,
nullptr
,
0
,
D3D11_SDK_VERSION
,
&
sd
,
&
pSwap
,
&
pDevice
,
nullptr
,
&
pContext
);
}
Graphics
::~
Graphics
()
{
if
(
pContext
!=
nullptr
)
{
pContext
->
Release
();
}
if
(
pSwap
!=
nullptr
)
{
pSwap
->
Release
();
}
if
(
pDevice
!=
nullptr
)
{
pDevice
->
Release
();
}
}
void
Graphics
::
EndFrame
()
{
pSwap
->
Present
(
1u
,
0u
);
}
hw3d/Graphics.h
0 → 100644
View file @
831380f6
#pragma once
#include "ChiliWin.h"
#include <d3d11.h>
class
Graphics
{
public:
Graphics
(
HWND
hWnd
);
Graphics
(
const
Graphics
&
)
=
delete
;
Graphics
&
operator
=
(
const
Graphics
&
)
=
delete
;
~
Graphics
();
void
EndFrame
();
private:
ID3D11Device
*
pDevice
=
nullptr
;
IDXGISwapChain
*
pSwap
=
nullptr
;
ID3D11DeviceContext
*
pContext
=
nullptr
;
};
\ No newline at end of file
hw3d/Window.cpp
View file @
831380f6
...
@@ -95,8 +95,10 @@ Window::Window( int width,int height,const char* name )
...
@@ -95,8 +95,10 @@ Window::Window( int width,int height,const char* name )
{
{
throw
CHWND_LAST_EXCEPT
();
throw
CHWND_LAST_EXCEPT
();
}
}
//
show window
//
newly created windows start off as hidden
ShowWindow
(
hWnd
,
SW_SHOWDEFAULT
);
ShowWindow
(
hWnd
,
SW_SHOWDEFAULT
);
// create graphics object
pGfx
=
std
::
make_unique
<
Graphics
>
(
hWnd
);
}
}
Window
::~
Window
()
Window
::~
Window
()
...
@@ -134,6 +136,11 @@ std::optional<int> Window::ProcessMessages()
...
@@ -134,6 +136,11 @@ std::optional<int> Window::ProcessMessages()
return
{};
return
{};
}
}
Graphics
&
Window
::
Gfx
()
{
return
*
pGfx
;
}
LRESULT
CALLBACK
Window
::
HandleMsgSetup
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
LRESULT
CALLBACK
Window
::
HandleMsgSetup
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
{
{
// use create parameter passed in from CreateWindow() to store window class pointer at WinAPI side
// use create parameter passed in from CreateWindow() to store window class pointer at WinAPI side
...
...
hw3d/Window.h
View file @
831380f6
...
@@ -22,7 +22,9 @@
...
@@ -22,7 +22,9 @@
#include "ChiliException.h"
#include "ChiliException.h"
#include "Keyboard.h"
#include "Keyboard.h"
#include "Mouse.h"
#include "Mouse.h"
#include "Graphics.h"
#include <optional>
#include <optional>
#include <memory>
class
Window
class
Window
...
@@ -63,6 +65,7 @@ public:
...
@@ -63,6 +65,7 @@ public:
Window
&
operator
=
(
const
Window
&
)
=
delete
;
Window
&
operator
=
(
const
Window
&
)
=
delete
;
void
SetTitle
(
const
std
::
string
&
title
);
void
SetTitle
(
const
std
::
string
&
title
);
static
std
::
optional
<
int
>
ProcessMessages
();
static
std
::
optional
<
int
>
ProcessMessages
();
Graphics
&
Gfx
();
private:
private:
static
LRESULT
CALLBACK
HandleMsgSetup
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
;
static
LRESULT
CALLBACK
HandleMsgSetup
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
;
static
LRESULT
CALLBACK
HandleMsgThunk
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
;
static
LRESULT
CALLBACK
HandleMsgThunk
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
;
...
@@ -74,6 +77,7 @@ private:
...
@@ -74,6 +77,7 @@ private:
int
width
;
int
width
;
int
height
;
int
height
;
HWND
hWnd
;
HWND
hWnd
;
std
::
unique_ptr
<
Graphics
>
pGfx
;
};
};
...
...
hw3d/hw3d.vcxproj
View file @
831380f6
...
@@ -148,6 +148,7 @@
...
@@ -148,6 +148,7 @@
<ClCompile
Include=
"App.cpp"
/>
<ClCompile
Include=
"App.cpp"
/>
<ClCompile
Include=
"ChiliException.cpp"
/>
<ClCompile
Include=
"ChiliException.cpp"
/>
<ClCompile
Include=
"ChiliTimer.cpp"
/>
<ClCompile
Include=
"ChiliTimer.cpp"
/>
<ClCompile
Include=
"Graphics.cpp"
/>
<ClCompile
Include=
"Keyboard.cpp"
/>
<ClCompile
Include=
"Keyboard.cpp"
/>
<ClCompile
Include=
"Mouse.cpp"
/>
<ClCompile
Include=
"Mouse.cpp"
/>
<ClCompile
Include=
"Window.cpp"
/>
<ClCompile
Include=
"Window.cpp"
/>
...
@@ -159,6 +160,7 @@
...
@@ -159,6 +160,7 @@
<ClInclude
Include=
"ChiliException.h"
/>
<ClInclude
Include=
"ChiliException.h"
/>
<ClInclude
Include=
"ChiliTimer.h"
/>
<ClInclude
Include=
"ChiliTimer.h"
/>
<ClInclude
Include=
"ChiliWin.h"
/>
<ClInclude
Include=
"ChiliWin.h"
/>
<ClInclude
Include=
"Graphics.h"
/>
<ClInclude
Include=
"Keyboard.h"
/>
<ClInclude
Include=
"Keyboard.h"
/>
<ClInclude
Include=
"Mouse.h"
/>
<ClInclude
Include=
"Mouse.h"
/>
<ClInclude
Include=
"resource.h"
/>
<ClInclude
Include=
"resource.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
831380f6
...
@@ -39,6 +39,9 @@
...
@@ -39,6 +39,9 @@
<ClCompile
Include=
"ChiliTimer.cpp"
>
<ClCompile
Include=
"ChiliTimer.cpp"
>
<Filter>
Source Files
</Filter>
<Filter>
Source Files
</Filter>
</ClCompile>
</ClCompile>
<ClCompile
Include=
"Graphics.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ClInclude
Include=
"WindowsMessageMap.h"
>
<ClInclude
Include=
"WindowsMessageMap.h"
>
...
@@ -68,6 +71,9 @@
...
@@ -68,6 +71,9 @@
<ClInclude
Include=
"ChiliTimer.h"
>
<ClInclude
Include=
"ChiliTimer.h"
>
<Filter>
Header Files
</Filter>
<Filter>
Header Files
</Filter>
</ClInclude>
</ClInclude>
<ClInclude
Include=
"Graphics.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ResourceCompile
Include=
"hw3d.rc"
>
<ResourceCompile
Include=
"hw3d.rc"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment