• R/O
  • SSH
  • HTTPS

shooting3: Commit


Commit MetaInfo

Revision3 (tree)
Time2009-12-07 19:44:39
Authorsfpg

Log Message

まだまだ完成に程遠いです。

Change Summary

Incremental Difference

--- shooting3/Input.cpp (revision 2)
+++ shooting3/Input.cpp (revision 3)
@@ -39,8 +39,6 @@
3939 input::~input()
4040 {
4141 release();
42- if(lpDI)
43- lpDI->Release();
4442 }
4543
4644 //////////////////////////////////////////////////////////////////////////////////
@@ -137,15 +135,15 @@
137135 {
138136 if(lpDIDMouse){
139137 lpDIDMouse->Unacquire();
140- lpDIDMouse->Release();
138+ lpDIDMouse.Release();
141139 }
142140 if(lpDIDKeyboard){
143141 lpDIDKeyboard->Unacquire();
144- lpDIDKeyboard->Release();
142+ lpDIDKeyboard.Release();
145143 }
146144 if(bJoystick){
147145 lpDIDJoystick->Unacquire();
148- lpDIDJoystick->Release();
146+ lpDIDJoystick.Release();
149147 }
150148 }
151149
--- shooting3/includes.h (revision 2)
+++ shooting3/includes.h (revision 3)
@@ -83,4 +83,9 @@
8383 #include <comdef.h>
8484 #include "avrt.h"
8585 #include "mmsystem.h"
86+#include <d2d1.h>
87+#include <d2d1helper.h>
88+#include <dwrite.h>
89+#include <wincodec.h>
90+#include <wincodecsdk.h>
8691
--- shooting3/sf_windows.cpp (revision 2)
+++ shooting3/sf_windows.cpp (revision 3)
@@ -50,7 +50,7 @@
5050 // // Note: This method can fail, but it's okay to ignore the
5151 // // error here -- it will be repeated on the next call to
5252 // // EndDraw.
53- // render_target_->Resize(size);
53+ // //render_target_->Resize(size);
5454 //}
5555 }
5656 case WM_PAINT:
@@ -101,13 +101,6 @@
101101
102102 void base_window::create_device_independent_resources()
103103 {
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- //));
111104
112105 //wic_imaging_factory_.CreateInstance(CLSID_WICImagingFactory);
113106
@@ -161,6 +154,7 @@
161154
162155 void base_window::create_device()
163156 {
157+
164158 input_.reset(new input(HINST_THISCOMPONENT,hwnd_));
165159 HRESULT hr = S_OK;
166160
@@ -170,7 +164,7 @@
170164 UINT width = rc.right - rc.left;
171165 UINT height = rc.bottom - rc.top;
172166
173- UINT createDeviceFlags = 0;
167+ UINT createDeviceFlags = D3D10_CREATE_DEVICE_BGRA_SUPPORT;
174168
175169 #ifdef _DEBUG
176170 createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
@@ -184,6 +178,15 @@
184178
185179 UINT numDriverTypes = sizeof( driverTypes ) / sizeof( driverTypes[0] );
186180
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+
187190 // D3Dデバイスとスワップチェーンの作成
188191 DXGI_SWAP_CHAIN_DESC sd;
189192 ZeroMemory( &sd, sizeof( sd ) );
@@ -190,7 +193,7 @@
190193 sd.BufferCount = 1;
191194 sd.BufferDesc.Width = width;
192195 sd.BufferDesc.Height = height;
193- sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
196+ sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM ;
194197 sd.BufferDesc.RefreshRate.Numerator = 60;
195198 sd.BufferDesc.RefreshRate.Denominator = 1;
196199 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
@@ -202,8 +205,8 @@
202205 for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
203206 {
204207 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_ );
207210 if( SUCCEEDED( hr ) )
208211 break;
209212 }
@@ -210,6 +213,34 @@
210213
211214 EXCEPTION_ON_ERROR(hr);
212215
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+
213244 // Create a render target view
214245 {
215246 ID3D10Texture2DPtr buffer;
@@ -219,10 +250,13 @@
219250 hr = d3d_device_->CreateRenderTargetView( buffer, NULL, &(render_target_view_.GetInterfacePtr()));
220251 EXCEPTION_ON_ERROR(hr);
221252 //buffer->Release();
253+
222254 } // buffer.Release()
223255
224256 d3d_device_->OMSetRenderTargets( 1, &(render_target_view_.GetInterfacePtr()), NULL );
225257
258+
259+
226260 // Setup the viewport
227261 D3D10_VIEWPORT vp;
228262 vp.Width = width;
@@ -235,12 +269,12 @@
235269
236270 // Create the effect
237271 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;
244278 #endif
245279 hr = D3DX10CreateEffectFromFile( L"Tutorial07.fx", NULL, NULL, "fx_4_0", dwShaderFlags, 0,
246280 d3d_device_, NULL, NULL, &effect_, NULL, NULL );
@@ -509,24 +543,7 @@
509543
510544 paint_struct begin_paint(hwnd);
511545
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+
530547 return FALSE;
531548 }
532549 case WM_DISPLAYCHANGE:
@@ -574,6 +591,7 @@
574591 {
575592
576593 static float t = 0.0f;
594+
577595 if(d3d_device_){
578596 // Update our time
579597 if( driver_type_ == D3D10_DRIVER_TYPE_REFERENCE )
@@ -600,7 +618,7 @@
600618 //
601619 // Clear the back buffer
602620 //
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
604622 d3d_device_->ClearRenderTargetView( render_target_view_, ClearColor );
605623
606624 //
@@ -623,34 +641,54 @@
623641 //
624642 // Present our back buffer to our front buffer
625643 //
626- swap_chain_->Present( 0, 0 );
644+ //swap_chain_->Present( 0, 0 );
627645 }
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());
628680
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 );
654692 };
655693
656694 }
--- shooting3/sf_windows.h (revision 2)
+++ shooting3/sf_windows.h (revision 3)
@@ -5,7 +5,7 @@
55 This file is part of the Shooting3
66 Copyright 2005-7 by Satoshi Fujiwara.
77
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
99 GNU General Public License, as published by the Free Software Foundation;
1010 either version 2 of the License, or (at your option) any later version.
1111
@@ -21,27 +21,24 @@
2121
2222 ==============================================================================
2323 */
24-//#include <d2d1.h>
25-//#include <d2d1helper.h>
26-//#include <dwrite.h>
2724 // Windows Header Files:
28-
2925 #include "exception.h"
3026 #include "xbyak.h"
3127 #include "input.h"
3228
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));
4340
44-_COM_SMARTPTR_TYPEDEF(ID3D10Device,__uuidof(ID3D10Device));
41+_COM_SMARTPTR_TYPEDEF(ID3D10Device1,__uuidof(ID3D10Device1));
4542 _COM_SMARTPTR_TYPEDEF(IDXGISwapChain,__uuidof(IDXGISwapChain));
4643 _COM_SMARTPTR_TYPEDEF(ID3D10RenderTargetView,__uuidof(ID3D10RenderTargetView));
4744 _COM_SMARTPTR_TYPEDEF(ID3D10Effect,IID_ID3D10Effect);
@@ -251,8 +248,8 @@
251248 }
252249 };
253250
251+ ID3D10Device1Ptr d3d_device_;
254252 D3D10_DRIVER_TYPE driver_type_;
255- ID3D10DevicePtr d3d_device_;
256253 IDXGISwapChainPtr swap_chain_;
257254 ID3D10RenderTargetViewPtr render_target_view_;
258255 ID3D10EffectPtr effect_;
@@ -273,9 +270,9 @@
273270 ID3DX10SpritePtr sprite_;
274271
275272 HWND hwnd_;
276- //ID2D1FactoryPtr factory_;
277- // ID2D1HwndRenderTargetPtr render_target_;
278- //IDWriteFactoryPtr write_factory_;
273+ ID2D1FactoryPtr factory_;
274+ ID2D1RenderTargetPtr render_target_;
275+ IDWriteFactoryPtr write_factory_;
279276 //IWICImagingFactoryPtr wic_imaging_factory_;
280277 hwnd_this_thunk thunk_;
281278 std::wstring menu_name_;
Show on old repository browser