まだまだ完成に程遠いです。
@@ -39,8 +39,6 @@ | ||
39 | 39 | input::~input() |
40 | 40 | { |
41 | 41 | release(); |
42 | - if(lpDI) | |
43 | - lpDI->Release(); | |
44 | 42 | } |
45 | 43 | |
46 | 44 | ////////////////////////////////////////////////////////////////////////////////// |
@@ -137,15 +135,15 @@ | ||
137 | 135 | { |
138 | 136 | if(lpDIDMouse){ |
139 | 137 | lpDIDMouse->Unacquire(); |
140 | - lpDIDMouse->Release(); | |
138 | + lpDIDMouse.Release(); | |
141 | 139 | } |
142 | 140 | if(lpDIDKeyboard){ |
143 | 141 | lpDIDKeyboard->Unacquire(); |
144 | - lpDIDKeyboard->Release(); | |
142 | + lpDIDKeyboard.Release(); | |
145 | 143 | } |
146 | 144 | if(bJoystick){ |
147 | 145 | lpDIDJoystick->Unacquire(); |
148 | - lpDIDJoystick->Release(); | |
146 | + lpDIDJoystick.Release(); | |
149 | 147 | } |
150 | 148 | } |
151 | 149 |
@@ -83,4 +83,9 @@ | ||
83 | 83 | #include <comdef.h> |
84 | 84 | #include "avrt.h" |
85 | 85 | #include "mmsystem.h" |
86 | +#include <d2d1.h> | |
87 | +#include <d2d1helper.h> | |
88 | +#include <dwrite.h> | |
89 | +#include <wincodec.h> | |
90 | +#include <wincodecsdk.h> | |
86 | 91 |
@@ -50,7 +50,7 @@ | ||
50 | 50 | // // Note: This method can fail, but it's okay to ignore the |
51 | 51 | // // error here -- it will be repeated on the next call to |
52 | 52 | // // EndDraw. |
53 | - // render_target_->Resize(size); | |
53 | + // //render_target_->Resize(size); | |
54 | 54 | //} |
55 | 55 | } |
56 | 56 | case WM_PAINT: |
@@ -101,13 +101,6 @@ | ||
101 | 101 | |
102 | 102 | void base_window::create_device_independent_resources() |
103 | 103 | { |
104 | - // Direct2DFactory の生成 | |
105 | - //EXCEPTION_ON_ERROR(D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, &factory_)); | |
106 | - //EXCEPTION_ON_ERROR(::DWriteCreateFactory( | |
107 | - // DWRITE_FACTORY_TYPE_SHARED, | |
108 | - // __uuidof(IDWriteFactory), | |
109 | - // reinterpret_cast<IUnknown**>(&write_factory_) | |
110 | - //)); | |
111 | 104 | |
112 | 105 | //wic_imaging_factory_.CreateInstance(CLSID_WICImagingFactory); |
113 | 106 |
@@ -161,6 +154,7 @@ | ||
161 | 154 | |
162 | 155 | void base_window::create_device() |
163 | 156 | { |
157 | + | |
164 | 158 | input_.reset(new input(HINST_THISCOMPONENT,hwnd_)); |
165 | 159 | HRESULT hr = S_OK; |
166 | 160 |
@@ -170,7 +164,7 @@ | ||
170 | 164 | UINT width = rc.right - rc.left; |
171 | 165 | UINT height = rc.bottom - rc.top; |
172 | 166 | |
173 | - UINT createDeviceFlags = 0; | |
167 | + UINT createDeviceFlags = D3D10_CREATE_DEVICE_BGRA_SUPPORT; | |
174 | 168 | |
175 | 169 | #ifdef _DEBUG |
176 | 170 | createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG; |
@@ -184,6 +178,15 @@ | ||
184 | 178 | |
185 | 179 | UINT numDriverTypes = sizeof( driverTypes ) / sizeof( driverTypes[0] ); |
186 | 180 | |
181 | + // Direct2DFactory の生成 | |
182 | + EXCEPTION_ON_ERROR(D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, &factory_)); | |
183 | + EXCEPTION_ON_ERROR(::DWriteCreateFactory( | |
184 | + DWRITE_FACTORY_TYPE_SHARED, | |
185 | + __uuidof(IDWriteFactory), | |
186 | + reinterpret_cast<IUnknown**>(&write_factory_) | |
187 | + )); | |
188 | + | |
189 | + | |
187 | 190 | // D3Dデバイスとスワップチェーンの作成 |
188 | 191 | DXGI_SWAP_CHAIN_DESC sd; |
189 | 192 | ZeroMemory( &sd, sizeof( sd ) ); |
@@ -190,7 +193,7 @@ | ||
190 | 193 | sd.BufferCount = 1; |
191 | 194 | sd.BufferDesc.Width = width; |
192 | 195 | sd.BufferDesc.Height = height; |
193 | - sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | |
196 | + sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM ; | |
194 | 197 | sd.BufferDesc.RefreshRate.Numerator = 60; |
195 | 198 | sd.BufferDesc.RefreshRate.Denominator = 1; |
196 | 199 | sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; |
@@ -202,8 +205,8 @@ | ||
202 | 205 | for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ ) |
203 | 206 | { |
204 | 207 | driver_type_ = driverTypes[driverTypeIndex]; |
205 | - hr = D3D10CreateDeviceAndSwapChain( NULL, driver_type_, NULL, createDeviceFlags, | |
206 | - D3D10_SDK_VERSION, &sd, &swap_chain_, &d3d_device_ ); | |
208 | + hr = D3D10CreateDeviceAndSwapChain1( NULL, driver_type_, NULL, createDeviceFlags, | |
209 | + D3D10_FEATURE_LEVEL_10_0,D3D10_1_SDK_VERSION, &sd, &swap_chain_, &d3d_device_ ); | |
207 | 210 | if( SUCCEEDED( hr ) ) |
208 | 211 | break; |
209 | 212 | } |
@@ -210,6 +213,34 @@ | ||
210 | 213 | |
211 | 214 | EXCEPTION_ON_ERROR(hr); |
212 | 215 | |
216 | + { | |
217 | + IDXGISurface* back_buf; | |
218 | + // Get a surface in the swap chain | |
219 | + hr = swap_chain_->GetBuffer( | |
220 | + 0, | |
221 | + IID_PPV_ARGS(&back_buf) | |
222 | + ); | |
223 | + // Create the DXGI Surface Render Target. | |
224 | + FLOAT dpiX; | |
225 | + FLOAT dpiY; | |
226 | + factory_->GetDesktopDpi(&dpiX, &dpiY); | |
227 | + | |
228 | + D2D1_RENDER_TARGET_PROPERTIES props = | |
229 | + D2D1::RenderTargetProperties( | |
230 | + D2D1_RENDER_TARGET_TYPE_DEFAULT, | |
231 | + D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED), | |
232 | + dpiX, | |
233 | + dpiY | |
234 | + ); | |
235 | + // Create a Direct2D render target which can draw into the surface in the swap chain | |
236 | + hr = factory_->CreateDxgiSurfaceRenderTarget( | |
237 | + back_buf, | |
238 | + &props, | |
239 | + &render_target_ | |
240 | + ); | |
241 | + back_buf->Release(); | |
242 | + } | |
243 | + | |
213 | 244 | // Create a render target view |
214 | 245 | { |
215 | 246 | ID3D10Texture2DPtr buffer; |
@@ -219,10 +250,13 @@ | ||
219 | 250 | hr = d3d_device_->CreateRenderTargetView( buffer, NULL, &(render_target_view_.GetInterfacePtr())); |
220 | 251 | EXCEPTION_ON_ERROR(hr); |
221 | 252 | //buffer->Release(); |
253 | + | |
222 | 254 | } // buffer.Release() |
223 | 255 | |
224 | 256 | d3d_device_->OMSetRenderTargets( 1, &(render_target_view_.GetInterfacePtr()), NULL ); |
225 | 257 | |
258 | + | |
259 | + | |
226 | 260 | // Setup the viewport |
227 | 261 | D3D10_VIEWPORT vp; |
228 | 262 | vp.Width = width; |
@@ -235,12 +269,12 @@ | ||
235 | 269 | |
236 | 270 | // Create the effect |
237 | 271 | DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; |
238 | - #if defined( DEBUG ) || defined( _DEBUG ) | |
239 | - // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders. | |
240 | - // Setting this flag improves the shader debugging experience, but still allows | |
241 | - // the shaders to be optimized and to run exactly the way they will run in | |
242 | - // the release configuration of this program. | |
243 | - dwShaderFlags |= D3D10_SHADER_DEBUG; | |
272 | + #if defined( DEBUG ) || defined( _DEBUG ) | |
273 | + // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders. | |
274 | + // Setting this flag improves the shader debugging experience, but still allows | |
275 | + // the shaders to be optimized and to run exactly the way they will run in | |
276 | + // the release configuration of this program. | |
277 | + dwShaderFlags |= D3D10_SHADER_DEBUG; | |
244 | 278 | #endif |
245 | 279 | hr = D3DX10CreateEffectFromFile( L"Tutorial07.fx", NULL, NULL, "fx_4_0", dwShaderFlags, 0, |
246 | 280 | d3d_device_, NULL, NULL, &effect_, NULL, NULL ); |
@@ -509,24 +543,7 @@ | ||
509 | 543 | |
510 | 544 | paint_struct begin_paint(hwnd); |
511 | 545 | |
512 | - //if (!(render_target_->CheckWindowState() & D2D1_WINDOW_STATE_OCCLUDED)) | |
513 | - //{ | |
514 | - // // Retrieve the size of the render target. | |
515 | - // D2D1_SIZE_F renderTargetSize = render_target_->GetSize(); | |
516 | - // try { | |
517 | - // //render_target_->BeginDraw(); | |
518 | - // base_->on_render(); | |
519 | - // //EXCEPTION_ON_ERROR(render_target_->EndDraw()); | |
520 | - // } catch (sf::win32_error_exception& e ) | |
521 | - // { | |
522 | - // if(e.hresult() == D2DERR_RECREATE_TARGET) | |
523 | - // { | |
524 | - // discard_device(); | |
525 | - // } else { | |
526 | - // throw; | |
527 | - // } | |
528 | - // } | |
529 | - //} | |
546 | + | |
530 | 547 | return FALSE; |
531 | 548 | } |
532 | 549 | case WM_DISPLAYCHANGE: |
@@ -574,6 +591,7 @@ | ||
574 | 591 | { |
575 | 592 | |
576 | 593 | static float t = 0.0f; |
594 | + | |
577 | 595 | if(d3d_device_){ |
578 | 596 | // Update our time |
579 | 597 | if( driver_type_ == D3D10_DRIVER_TYPE_REFERENCE ) |
@@ -600,7 +618,7 @@ | ||
600 | 618 | // |
601 | 619 | // Clear the back buffer |
602 | 620 | // |
603 | - float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; // red, green, blue, alpha | |
621 | + float ClearColor[4] = { 0.3f, 0.8f, 0.3f, 1.0f }; // red, green, blue, alpha | |
604 | 622 | d3d_device_->ClearRenderTargetView( render_target_view_, ClearColor ); |
605 | 623 | |
606 | 624 | // |
@@ -623,34 +641,54 @@ | ||
623 | 641 | // |
624 | 642 | // Present our back buffer to our front buffer |
625 | 643 | // |
626 | - swap_chain_->Present( 0, 0 ); | |
644 | + //swap_chain_->Present( 0, 0 ); | |
627 | 645 | } |
646 | + // Swap chain will tell us how big the back buffer is | |
647 | + DXGI_SWAP_CHAIN_DESC swapDesc; | |
648 | + HRESULT hr = swap_chain_->GetDesc(&swapDesc); | |
649 | + if (render_target_ && hr == S_OK) | |
650 | + { | |
651 | + // Retrieve the size of the render target. | |
652 | + D2D1_SIZE_F renderTargetSize = render_target_->GetSize(); | |
653 | + try { | |
654 | + render_target_->BeginDraw(); | |
655 | + render_target_->SetTransform(D2D1::Matrix3x2F::Identity()); | |
656 | + //render_target_->Clear(D2D1::ColorF(D2D1::ColorF::White)); | |
657 | + ID2D1SolidColorBrushPtr brush; | |
658 | + render_target_->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &brush); | |
659 | + D2D1_RECT_F layoutRect = D2D1::RectF(50.f, 50.f, 500.f, 200.f); | |
660 | + IDWriteTextFormatPtr write_text_format; | |
661 | + // Text Formatの作成 | |
662 | + EXCEPTION_ON_ERROR(write_factory_->CreateTextFormat( | |
663 | + L"メイリオ", // Font family name. | |
664 | + NULL, // Font collection (NULL sets it to use the system font collection). | |
665 | + DWRITE_FONT_WEIGHT_REGULAR, | |
666 | + DWRITE_FONT_STYLE_NORMAL, | |
667 | + DWRITE_FONT_STRETCH_NORMAL, | |
668 | + 72.0f, | |
669 | + L"ja-jp", | |
670 | + &write_text_format | |
671 | + )); | |
672 | + // Actually draw the text at the origin. | |
673 | + render_target_->DrawTextW( | |
674 | + L"こんにちは、世界!\nBy S.F.", | |
675 | + wcslen(L"こんにちは、世界!\nBy S.F."), | |
676 | + write_text_format, | |
677 | + layoutRect, | |
678 | + brush); | |
679 | + EXCEPTION_ON_ERROR(render_target_->EndDraw()); | |
628 | 680 | |
629 | - //::ID2D1HwndRenderTargetPtr target(render_target()); | |
630 | - //target->SetTransform(D2D1::Matrix3x2F::Identity()); | |
631 | - //target->Clear(D2D1::ColorF(D2D1::ColorF::White)); | |
632 | - //ID2D1SolidColorBrushPtr brush; | |
633 | - //target->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &brush); | |
634 | - //D2D1_RECT_F layoutRect = D2D1::RectF(50.f, 50.f, 500.f, 200.f); | |
635 | - //IDWriteTextFormatPtr write_text_format; | |
636 | - //// Text Formatの作成 | |
637 | - //EXCEPTION_ON_ERROR(write_factory()->CreateTextFormat( | |
638 | - // L"メイリオ", // Font family name. | |
639 | - // NULL, // Font collection (NULL sets it to use the system font collection). | |
640 | - // DWRITE_FONT_WEIGHT_REGULAR, | |
641 | - // DWRITE_FONT_STYLE_NORMAL, | |
642 | - // DWRITE_FONT_STRETCH_NORMAL, | |
643 | - // 72.0f, | |
644 | - // L"ja-jp", | |
645 | - // &write_text_format | |
646 | - //)); | |
647 | - //// Actually draw the text at the origin. | |
648 | - //target->DrawTextW( | |
649 | - // L"こんにちは、世界!\nBy S.F.", | |
650 | - // wcslen(L"こんにちは、世界!\nBy S.F."), | |
651 | - // write_text_format, | |
652 | - // layoutRect, | |
653 | - // brush); | |
681 | + } catch (sf::win32_error_exception& e ) | |
682 | + { | |
683 | + if(e.hresult() == D2DERR_RECREATE_TARGET) | |
684 | + { | |
685 | + discard_device(); | |
686 | + } else { | |
687 | + throw; | |
688 | + } | |
689 | + } | |
690 | + } | |
691 | + swap_chain_->Present( 0, 0 ); | |
654 | 692 | }; |
655 | 693 | |
656 | 694 | } |
@@ -5,7 +5,7 @@ | ||
5 | 5 | This file is part of the Shooting3 |
6 | 6 | Copyright 2005-7 by Satoshi Fujiwara. |
7 | 7 | |
8 | - S.F.Tracker can be redistributed and/or modified under the terms of the | |
8 | + Shooting3 can be redistributed and/or modified under the terms of the | |
9 | 9 | GNU General Public License, as published by the Free Software Foundation; |
10 | 10 | either version 2 of the License, or (at your option) any later version. |
11 | 11 |
@@ -21,27 +21,24 @@ | ||
21 | 21 | |
22 | 22 | ============================================================================== |
23 | 23 | */ |
24 | -//#include <d2d1.h> | |
25 | -//#include <d2d1helper.h> | |
26 | -//#include <dwrite.h> | |
27 | 24 | // Windows Header Files: |
28 | - | |
29 | 25 | #include "exception.h" |
30 | 26 | #include "xbyak.h" |
31 | 27 | #include "input.h" |
32 | 28 | |
33 | -//_COM_SMARTPTR_TYPEDEF(ID2D1Factory,__uuidof(ID2D1Factory)); | |
34 | -//_COM_SMARTPTR_TYPEDEF(IWICImagingFactory, __uuidof(IWICImagingFactory)); | |
35 | -//_COM_SMARTPTR_TYPEDEF(IDWriteFactory , __uuidof(IDWriteFactory)); | |
36 | -//_COM_SMARTPTR_TYPEDEF(ID2D1HwndRenderTarget , __uuidof(ID2D1HwndRenderTarget)); | |
37 | -//_COM_SMARTPTR_TYPEDEF(IDWriteTextFormat, __uuidof(IDWriteTextFormat)); | |
38 | -//_COM_SMARTPTR_TYPEDEF(ID2D1PathGeometry , __uuidof(ID2D1PathGeometry)); | |
39 | -//_COM_SMARTPTR_TYPEDEF(ID2D1LinearGradientBrush , __uuidof(ID2D1LinearGradientBrush)); | |
40 | -//_COM_SMARTPTR_TYPEDEF(ID2D1SolidColorBrush , __uuidof(ID2D1SolidColorBrush)); | |
41 | -//_COM_SMARTPTR_TYPEDEF(ID2D1BitmapBrush , __uuidof(ID2D1BitmapBrush)); | |
42 | -//_COM_SMARTPTR_TYPEDEF(ID2D1Bitmap , __uuidof(ID2D1Bitmap)); | |
29 | +_COM_SMARTPTR_TYPEDEF(ID2D1Factory,__uuidof(ID2D1Factory)); | |
30 | +_COM_SMARTPTR_TYPEDEF(IWICImagingFactory, __uuidof(IWICImagingFactory)); | |
31 | +_COM_SMARTPTR_TYPEDEF(IDWriteFactory , __uuidof(IDWriteFactory)); | |
32 | +_COM_SMARTPTR_TYPEDEF(ID2D1HwndRenderTarget , __uuidof(ID2D1HwndRenderTarget)); | |
33 | +_COM_SMARTPTR_TYPEDEF(ID2D1RenderTarget , __uuidof(ID2D1HwndRenderTarget)); | |
34 | +_COM_SMARTPTR_TYPEDEF(IDWriteTextFormat, __uuidof(IDWriteTextFormat)); | |
35 | +_COM_SMARTPTR_TYPEDEF(ID2D1PathGeometry , __uuidof(ID2D1PathGeometry)); | |
36 | +_COM_SMARTPTR_TYPEDEF(ID2D1LinearGradientBrush , __uuidof(ID2D1LinearGradientBrush)); | |
37 | +_COM_SMARTPTR_TYPEDEF(ID2D1SolidColorBrush , __uuidof(ID2D1SolidColorBrush)); | |
38 | +_COM_SMARTPTR_TYPEDEF(ID2D1BitmapBrush , __uuidof(ID2D1BitmapBrush)); | |
39 | +_COM_SMARTPTR_TYPEDEF(ID2D1Bitmap , __uuidof(ID2D1Bitmap)); | |
43 | 40 | |
44 | -_COM_SMARTPTR_TYPEDEF(ID3D10Device,__uuidof(ID3D10Device)); | |
41 | +_COM_SMARTPTR_TYPEDEF(ID3D10Device1,__uuidof(ID3D10Device1)); | |
45 | 42 | _COM_SMARTPTR_TYPEDEF(IDXGISwapChain,__uuidof(IDXGISwapChain)); |
46 | 43 | _COM_SMARTPTR_TYPEDEF(ID3D10RenderTargetView,__uuidof(ID3D10RenderTargetView)); |
47 | 44 | _COM_SMARTPTR_TYPEDEF(ID3D10Effect,IID_ID3D10Effect); |
@@ -251,8 +248,8 @@ | ||
251 | 248 | } |
252 | 249 | }; |
253 | 250 | |
251 | + ID3D10Device1Ptr d3d_device_; | |
254 | 252 | D3D10_DRIVER_TYPE driver_type_; |
255 | - ID3D10DevicePtr d3d_device_; | |
256 | 253 | IDXGISwapChainPtr swap_chain_; |
257 | 254 | ID3D10RenderTargetViewPtr render_target_view_; |
258 | 255 | ID3D10EffectPtr effect_; |
@@ -273,9 +270,9 @@ | ||
273 | 270 | ID3DX10SpritePtr sprite_; |
274 | 271 | |
275 | 272 | HWND hwnd_; |
276 | - //ID2D1FactoryPtr factory_; | |
277 | - // ID2D1HwndRenderTargetPtr render_target_; | |
278 | - //IDWriteFactoryPtr write_factory_; | |
273 | + ID2D1FactoryPtr factory_; | |
274 | + ID2D1RenderTargetPtr render_target_; | |
275 | + IDWriteFactoryPtr write_factory_; | |
279 | 276 | //IWICImagingFactoryPtr wic_imaging_factory_; |
280 | 277 | hwnd_this_thunk thunk_; |
281 | 278 | std::wstring menu_name_; |