1 #include "mof/private/PixelMapTextureBuilder.hpp"
2 #include "mof/private/GraphicsDeviceImpl.hpp"
5 #include "mof/ConsoleIO.hpp"
6 #include "mof/Font.hpp"
9 mof::PixelMapTextureBuilder::PixelMapTextureBuilder( const std::shared_ptr<mof::PixelMap>& pixelMap)
10 : m_pPixelMap(pixelMap)
14 mof::PixelMapTextureBuilder::~PixelMapTextureBuilder(void)
20 LPDIRECT3DTEXTURE9 mof::PixelMapTextureBuilder::create(){
22 LPDIRECT3DDEVICE9 pDevice = mof::GraphicsDevice::getRawDevice();
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;
30 //
\83e
\83N
\83X
\83`
\83\83\8dì
\90¬
31 LPDIRECT3DTEXTURE9 texture;
36 hr = D3DXCreateTexture
38 pDevice , tWidth , tHeight ,
39 1 , D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8,
40 D3DPOOL_DEFAULT, &texture
45 throw std::runtime_error("Failed --- D3DXCreateTexture");
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");
56 //
\83t
\83H
\83\93\83g
\8fî
\95ñ
\82Ì
\8f\91\82«
\8d\9e\82Ý
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));
66 texture->UnlockRect(0);