OSDN Git Service

fix build system ofmoflib1 and saisei1
[moflib/moflib.git] / moflib-1.0 / src / mof / PixelMapTextureBuilder.cpp
1 #include "mof/private/PixelMapTextureBuilder.hpp"
2 #include "mof/private/GraphicsDeviceImpl.hpp"
3 #include <list>
4 #include <memory>
5 #include "mof/ConsoleIO.hpp"
6 #include "mof/Font.hpp"
7
8
9 mof::PixelMapTextureBuilder::PixelMapTextureBuilder( const std::shared_ptr<mof::PixelMap>& pixelMap)
10 : m_pPixelMap(pixelMap)
11 {
12 }
13
14 mof::PixelMapTextureBuilder::~PixelMapTextureBuilder(void)
15 {
16         
17 }
18
19
20 LPDIRECT3DTEXTURE9 mof::PixelMapTextureBuilder::create(){
21         HRESULT hr;
22         LPDIRECT3DDEVICE9 pDevice = mof::GraphicsDevice::getRawDevice();
23
24         unsigned int tWidth = 2;
25         while(tWidth < m_pPixelMap->shape()[0])tWidth *= 2;
26         unsigned int tHeight = 2;
27         while(tHeight < m_pPixelMap->shape()[1])tHeight *= 2;
28         
29   
30         // \83e\83N\83X\83`\83\83\8dì\90¬
31         LPDIRECT3DTEXTURE9 texture;
32         if
33     (
34         FAILED
35         (
36             hr = D3DXCreateTexture
37                 (
38                     pDevice , tWidth , tHeight ,
39                     1 , D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, 
40                     D3DPOOL_DEFAULT, &texture
41                 )
42         )
43     )
44     {
45                 throw std::runtime_error("Failed --- D3DXCreateTexture");
46         }
47
48    
49
50         // \83e\83N\83X\83`\83\83\82É\83t\83H\83\93\83g\83r\83b\83g\83}\83b\83v\8f\91\82«\8d\9e\82Ý
51         D3DLOCKED_RECT LockedRect;
52         if(FAILED(hr = texture->LockRect(0, &LockedRect, NULL, D3DLOCK_DISCARD))){
53                 throw std::runtime_error("Failed --- LockRect");
54         }
55
56         // \83t\83H\83\93\83g\8fî\95ñ\82Ì\8f\91\82«\8d\9e\82Ý
57         
58         FillMemory(LockedRect.pBits , LockedRect.Pitch * tHeight , 0);
59         for(unsigned int y = 0 ; y < m_pPixelMap->shape()[1] ; y++){
60                 for(unsigned int x = 0 ; x < m_pPixelMap->shape()[0] ; x++){
61                         memcpy((BYTE*)LockedRect.pBits + LockedRect.Pitch * y + 4 * x , &((*m_pPixelMap)[x][y]) , sizeof(DWORD));
62                 }
63         }
64
65         
66         texture->UnlockRect(0);
67         return texture;
68
69
70 }
71