-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualizer.cpp
More file actions
70 lines (58 loc) · 1.46 KB
/
visualizer.cpp
File metadata and controls
70 lines (58 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <d2d1.h>
#include <d2d1helper.h>
#include <dwrite.h>
#include "audio.h"
#include "visualizer.h"
Visualizer::Visualizer()
: m_hWnd(NULL), m_pCurrentAfd(NULL), m_pDirect2dFactory(NULL), m_pRenderTarget(NULL), m_pBuffer1(NULL),
m_pBuffer2(NULL)
{
}
Visualizer::~Visualizer()
{
DiscardDeviceResources();
SafeRelease(&m_pDirect2dFactory);
}
HRESULT Visualizer::CreateDeviceIndependentResources()
{
HRESULT hr;
// Create a Direct2D factory.
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pDirect2dFactory);
return hr;
}
HRESULT Visualizer::CreateDeviceResources()
{
HRESULT hr;
RECT rc;
int width, height;
GetClientRect(m_hWnd, &rc);
width = rc.right - rc.left;
height = rc.bottom - rc.top;
D2D1_SIZE_U size = D2D1::SizeU(width, height);
// Create a Direct2D render target.
hr = m_pDirect2dFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(m_hWnd, size),
&m_pRenderTarget);
if (FAILED(hr)) {
return hr;
}
hr = m_pRenderTarget->CreateCompatibleRenderTarget(&m_pBuffer1);
if (FAILED(hr)) {
return hr;
}
hr = m_pRenderTarget->CreateCompatibleRenderTarget(&m_pBuffer2);
if (FAILED(hr)) {
return hr;
}
return hr;
}
VOID Visualizer::DiscardDeviceResources()
{
SafeRelease(&m_pBuffer1);
SafeRelease(&m_pBuffer2);
SafeRelease(&m_pRenderTarget);
}