Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 73.52 KB | None | 0 0
  1. // Neuz.cpp : Defines the entry point for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "2DRender.h"
  5. #include "targa.h"
  6. #include "..\_UnhandledException\ExceptionHandler.h"
  7.  
  8.  
  9. /////////////////////////////////////////////////////////////////////////////
  10. // Class Name : CLipRect : public CRect
  11. // Remarks    :
  12. //   Ŭ¸³Çο¡ °ü·ÃµÈ ±â´ÉÀ» Á¦°øÇÑ´Ù. »ç°¢Çü ³¢¸®ÀÇ °ãħ äũ, Ŭ¸³ÇΠäŷ
  13. // µûÀ§¸¦ ÇÑ´Ù.
  14. //
  15.  
  16. ////////////////////////////////////////////////////////////////////////////
  17. // Func. Name : Clipping
  18. // Parameters :
  19. // Return     :
  20. // Remarks    :
  21. //
  22. BOOL CRectClip::Clipping(CRect& rect) const
  23. {
  24.     if(rect.right  <= left) return FALSE;
  25.     if(rect.bottom <= top ) return FALSE;
  26.     if(rect.left >= right ) return FALSE;
  27.     if(rect.top  >= bottom) return FALSE;
  28.     if(rect.left < left) rect.left = left;
  29.     if(rect.top  < top ) rect.top  = top ;
  30.     if(rect.right  > right ) rect.right  = right ;
  31.     if(rect.bottom > bottom) rect.bottom = bottom;
  32.     return TRUE;
  33. }
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Func. Name : RectLapRect
  36. // Parameters :
  37. //  rect : Á¶»çÇÒ CRect
  38. // Return     :
  39. //  TRUEÀÌ¸é °ãÃÆÀ½. FALSEÀÌ¸é °ãÄ¡Áö ¾ÊÀ½.
  40. // Remarks    :
  41. //   Rect¿Í Rect°¡ °ãĨ(Lap)´ÂÁö Á¶»çÇÑ´Ù.
  42. //
  43. BOOL CRectClip::RectLapRect(CRect rect) const
  44. {
  45.     if(rect.right  <= left) return FALSE;
  46.     if(rect.bottom <= top ) return FALSE;
  47.     if(rect.left >= right ) return FALSE;
  48.     if(rect.top  >= bottom) return FALSE;
  49.     return TRUE;
  50. }
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53. // Func. Name : RectInRect
  54. // Parameters :
  55. //  rect : Á¶»çÇÒ CRect
  56. // Return     :
  57. //  TRUEÀÌ¸é °ãÃÆÀ½. FALSEÀÌ¸é °ãÄ¡Áö ¾ÊÀ½.
  58. // Remarks    :
  59. //   Rect¿Í Rect°¡ °ãĨ(Lap)´ÂÁö Á¶»çÇÑ´Ù.
  60. //
  61. BOOL CRectClip::RectInRect(CRect rect) const
  62. {
  63.     if(rect.left < left) return FALSE;
  64.     if(rect.top  < top ) return FALSE;
  65.     if(rect.right  > right ) return FALSE;
  66.     if(rect.bottom > bottom) return FALSE;
  67.     return TRUE;
  68. }
  69. /////////////////////////////////////////////////////////////////////////////
  70. // Class Name : C2DRender
  71. // Remarks    :
  72. //   2D Æò¸é¿¡ ±×¸²À» ±×¸®°Å³ª ÅؽºÃç Ãâ·Â
  73. //
  74.  
  75.  
  76. /*
  77. struct TextureSprite
  78. {
  79.     LPDIRECT3DVERTEXBUFFER9 pVertexBuffer;
  80.     LPDIRECT3DTEXTURE9      pTexture[8];
  81. }
  82. */
  83. #define MAX_NUM_VERTICES 50*6
  84.  
  85. struct FONT2DVERTEX { D3DXVECTOR4 p;   DWORD color;     FLOAT tu, tv; };
  86. struct FONT3DVERTEX { D3DXVECTOR3 p;   D3DXVECTOR3 n;   FLOAT tu, tv; };
  87.  
  88. #define D3DFVF_FONT2DVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
  89. #define D3DFVF_FONT3DVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
  90.  
  91. inline DRAWVERTEX Init2DVertex( int x,int y, D3DCOLOR color )
  92. {
  93.     DRAWVERTEX v;  
  94.     v.vec.x = (FLOAT)x;
  95.     v.vec.y = (FLOAT)y;
  96.     v.vec.z = 0;
  97.     v.rhw = 1.0f;
  98.     v.color = color;  
  99.     return v;
  100. }
  101. /*
  102. inline FONT2DVERTEX Init2DVertex( const D3DXVECTOR4& p, D3DCOLOR color,
  103.                                      FLOAT tu, FLOAT tv )
  104. {
  105.    FONT2DVERTEX v;   v.p = p;   v.color = color;   v.tu = tu;   v.tv = tv;
  106.    return v;
  107. }
  108. */
  109. C2DRender::C2DRender()
  110. {
  111.     m_pd3dDevice = NULL;
  112.     m_pVBFillTriangle = NULL;
  113.     m_pVBTriangle = NULL;
  114.     m_pVBFillRect = NULL;
  115.     m_pVBRect = NULL;
  116.     m_pVBRoundRect = NULL;
  117.     m_pVBLine = NULL;
  118.     m_pVBPixel = NULL;
  119.     //m_pVBTexture = NULL;
  120.     m_pFont = NULL;
  121.     m_ptOrigin = 0;
  122.     m_clipRect.SetRect(0,0,800,600);
  123.     m_dwTextColor = D3DCOLOR_RGBA(255,255,255,255);
  124. }
  125. C2DRender::~C2DRender()
  126. {
  127.     DeleteDeviceObjects();
  128. }
  129. HRESULT C2DRender::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice )
  130. {
  131.     HRESULT hr = S_OK;
  132.     m_pd3dDevice = pd3dDevice;
  133.     return hr;
  134. }
  135. HRESULT C2DRender::RestoreDeviceObjects( D3DSURFACE_DESC*  pd3dsdBackBuffer )
  136. {
  137.     if( m_pd3dDevice == NULL ) return S_OK;
  138.     m_clipRect.SetRect( 0, 0, pd3dsdBackBuffer->Width, pd3dsdBackBuffer->Height );
  139.     HRESULT hr = S_OK;
  140.     /*
  141.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*4, D3DUSAGE_WRITEONLY| D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_SYSTEMMEM, &m_pVBFillRect     , NULL);
  142.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*5, D3DUSAGE_WRITEONLY| D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_SYSTEMMEM, &m_pVBRect         , NULL);
  143.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*8, D3DUSAGE_WRITEONLY| D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_SYSTEMMEM, &m_pVBRoundRect    , NULL);
  144.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*2, D3DUSAGE_WRITEONLY| D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_SYSTEMMEM, &m_pVBLine         , NULL);
  145.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*2, D3DUSAGE_WRITEONLY| D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_SYSTEMMEM, &m_pVBPixel        , NULL);
  146.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*3, D3DUSAGE_WRITEONLY| D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_SYSTEMMEM, &m_pVBFillTriangle , NULL);
  147.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*4, D3DUSAGE_WRITEONLY| D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_SYSTEMMEM, &m_pVBTriangle     , NULL);
  148.     m_pd3dDevice->CreateVertexBuffer( sizeof(TEXTUREVERTEX)*4, D3DUSAGE_WRITEONLY| D3DUSAGE_DYNAMIC, D3DFVF_TEXTUREVERTEX, D3DPOOL_SYSTEMMEM, &m_pVBTexture      , NULL);
  149. */
  150.    
  151.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*4, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_DEFAULT, &m_pVBFillRect, NULL );
  152.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*5, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_DEFAULT, &m_pVBRect, NULL );
  153.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*8, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_DEFAULT, &m_pVBRoundRect, NULL );
  154.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*2, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_DEFAULT, &m_pVBLine, NULL );
  155.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*2, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_DEFAULT, &m_pVBPixel, NULL );
  156.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*3, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_DEFAULT, &m_pVBFillTriangle, NULL );
  157.     m_pd3dDevice->CreateVertexBuffer( sizeof(DRAWVERTEX   )*4, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_DRAWVERTEX   , D3DPOOL_DEFAULT, &m_pVBTriangle, NULL );
  158.     //m_pd3dDevice->CreateVertexBuffer( sizeof(TEXTUREVERTEX)*4, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_TEXTUREVERTEX, D3DPOOL_DEFAULT, &m_pVBTexture, NULL );
  159.  
  160.  
  161. //D3DPOOL_SYSTEMMEM
  162. //r( MAX_NUM_VERTICES*sizeof(FONT2DVERTEX),
  163.  //                                                     D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0,
  164.    //                                                   D3DPOOL_DEFAULT, &m_pVB ) ) )
  165.    //{
  166.     return hr;
  167. }
  168. HRESULT C2DRender::InvalidateDeviceObjects()
  169. {
  170.     return DeleteDeviceObjects();
  171. }
  172. HRESULT C2DRender::DeleteDeviceObjects()
  173. {
  174.     HRESULT hr = S_OK;
  175.     SAFE_RELEASE(m_pVBFillRect );
  176.     SAFE_RELEASE(m_pVBRect     );
  177.     SAFE_RELEASE(m_pVBRoundRect);
  178.     SAFE_RELEASE(m_pVBLine     );
  179.     SAFE_RELEASE(m_pVBPixel    );
  180.     //SAFE_RELEASE(m_pVBTexture  );
  181.     SAFE_RELEASE(m_pVBFillTriangle);
  182.     SAFE_RELEASE(m_pVBTriangle );
  183.     return hr;
  184. }
  185.  
  186. void C2DRender::SetViewport(CRect rect)
  187. {
  188.     D3DVIEWPORT9 viewport;
  189.     viewport.X      = rect.left;
  190.     viewport.Y      = rect.top;
  191.     viewport.Width  = rect.Width();
  192.     viewport.Height = rect.Height();
  193.     viewport.MinZ   = 0.0f;
  194.     viewport.MaxZ   = 1.0f;
  195.     m_pd3dDevice->SetViewport(&viewport);
  196.     m_clipRect = rect;
  197.     //SetViewportOrg(rect.left,rect.top);
  198. }
  199. void C2DRender::SetViewport(int nLeft,int nTop,int nRight,int nBottom)
  200. {
  201.     m_clipRect = CRect(nLeft,nTop,nRight,nBottom);
  202.     D3DVIEWPORT9 viewport;
  203.     viewport.X      = m_clipRect.left;
  204.     viewport.Y      = m_clipRect.top;
  205.     viewport.Width  = m_clipRect.Width();
  206.     viewport.Height = m_clipRect.Height();
  207.     viewport.MinZ   = 0.0f;
  208.     viewport.MaxZ   = 1.0f;
  209.     m_pd3dDevice->SetViewport(&viewport);
  210.     //SetViewportOrg(nLeft,nTop);
  211. }
  212. BOOL C2DRender::ResizeFillRectVB( CRect* pRect, DWORD dwColorLT, DWORD dwColorRT, DWORD dwColorLB, DWORD dwColorRB, LPDIRECT3DVERTEXBUFFER9 pVB, LPDIRECT3DTEXTURE9 m_pTexture )
  213. {
  214.     DRAWVERTEX* pDrawVertices;
  215.     HRESULT hr = pVB->Lock( 0,sizeof(DRAWVERTEX)*4,(void**)&pDrawVertices, D3DLOCK_DISCARD );
  216.     if(hr != D3D_OK) return FALSE;
  217. //  dwColor |=  0xff000000;
  218.     pDrawVertices->vec.x     = (FLOAT)pRect->left;
  219.     pDrawVertices->vec.y     = (FLOAT)pRect->top;
  220.     pDrawVertices->vec.z     = 0.0f;
  221.     pDrawVertices->rhw   = 1.0f;
  222.     pDrawVertices->color = dwColorLT;
  223.     pDrawVertices++;
  224.     pDrawVertices->vec.x     = (FLOAT)pRect->right;
  225.     pDrawVertices->vec.y     = (FLOAT)pRect->top;
  226.     pDrawVertices->vec.z     = 0.0f;
  227.     pDrawVertices->rhw   = 1.0f;
  228.     pDrawVertices->color = dwColorRT;
  229.     pDrawVertices++;
  230.     pDrawVertices->vec.x     = (FLOAT)pRect->left;
  231.     pDrawVertices->vec.y     = (FLOAT)pRect->bottom;
  232.     pDrawVertices->vec.z     = 0.0f;
  233.     pDrawVertices->rhw   = 1.0f;
  234.     pDrawVertices->color = dwColorLB;
  235.     pDrawVertices++;
  236.     pDrawVertices->vec.x     = (FLOAT)pRect->right;
  237.     pDrawVertices->vec.y     = (FLOAT)pRect->bottom;
  238.     pDrawVertices->vec.z     = 0.0f;
  239.     pDrawVertices->rhw   = 1.0f;
  240.     pDrawVertices->color = dwColorRB;
  241.     pDrawVertices++;
  242.  
  243.     pVB->Unlock();
  244.     return TRUE;
  245. }
  246. BOOL C2DRender::RenderFillRect( CRect rect, DWORD dwColorLT, DWORD dwColorRT, DWORD dwColorLB, DWORD dwColorRB, LPDIRECT3DTEXTURE9 m_pTexture )
  247. {
  248.     if( m_pd3dDevice == NULL )
  249.         return FALSE;
  250.    
  251.     if( rect.left == 0 && rect.right == 0 && rect.top == 0 && rect.bottom == 0 )
  252.         return FALSE;
  253.  
  254.     rect += m_ptOrigin; //rect.right; rect.bottom;
  255.     ResizeFillRectVB( &rect, dwColorLT, dwColorRT, dwColorLB, dwColorRB, m_pVBFillRect,m_pTexture );
  256.         // ¾ËÆÄ°ªÀÌ Çϳª¶óµµ 0xff°¡ ¾Æ´Ñ°Ô ÀÖ´Ù¸é ¹ÝÅõ¸í ó¸®.
  257.        if( ( dwColorLT & 0xff000000 ) != 0xff000000 || ( dwColorRT & 0xff000000 ) != 0xff000000 || ( dwColorLB & 0xff000000 ) != 0xff000000 || ( dwColorRB & 0xff000000 ) != 0xff000000 ) ////bSupportsAlphaBlend )
  258.        {
  259.             m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
  260.            //m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND,   D3DBLEND_SRCALPHA );
  261.            //m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND,  D3DBLEND_INVSRCALPHA );
  262.        }
  263.        else
  264.        {
  265.            m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
  266.        }
  267.        //m_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,  TRUE );
  268.        //m_pd3dDevice->SetRenderState( D3DRS_ALPHAREF,         0x08 );
  269.        //m_pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC,  D3DCMP_GREATEREQUAL );
  270.        //m_pd3dDevice->SetRenderState( D3DRS_FILLMODE,   D3DFILL_SOLID );
  271.        //m_pd3dDevice->SetRenderState( D3DRS_CULLMODE,   D3DCULL_CCW );
  272.        //m_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE,    FALSE );
  273.        //m_pd3dDevice->SetRenderState( D3DRS_CLIPPING,         TRUE );
  274.        //m_pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE,  FALSE );
  275.        //m_pd3dDevice->SetRenderState( D3DRS_VERTEXBLEND,      D3DVBF_DISABLE );
  276.        //m_pd3dDevice->SetRenderState( D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE );
  277.        //m_pd3dDevice->SetRenderState( D3DRS_FOGENABLE,        FALSE );
  278.        //m_pd3dDevice->SetRenderState( D3DRS_COLORWRITEENABLE,
  279.          //  D3DCOLORWRITEENABLE_RED  | D3DCOLORWRITEENABLE_GREEN |
  280.            //D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA );
  281.  
  282.        //m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
  283.        //m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  284.        //m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
  285.        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  286.        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  287.        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
  288.        //m_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
  289.        //m_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
  290.        //m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
  291.        //m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
  292.        //m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
  293.        //m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
  294.        //m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE );
  295.  
  296.     m_pd3dDevice->SetTexture( 0, m_pTexture );
  297.     m_pd3dDevice->SetFVF( D3DFVF_DRAWVERTEX );
  298.     m_pd3dDevice->SetStreamSource( 0, m_pVBFillRect, 0,sizeof( DRAWVERTEX ) );
  299.     m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2);
  300.     return TRUE;
  301. }
  302. BOOL C2DRender::RenderResizeRect( CRect rect, int nThick )
  303. {
  304.     CRect rectT( rect.left, rect.top - nThick, rect.right, rect.top );
  305.     CRect rectB( rect.left, rect.bottom, rect.right, rect.bottom + nThick );
  306.     CRect rectL( rect.left - nThick, rect.top, rect.left, rect.bottom );
  307.     CRect rectR( rect.right, rect.top, rect.right + nThick, rect.bottom );
  308.     CRect rectLT( rect.left  - nThick, rect.top - nThick, rect.left, rect.top );
  309.     CRect rectRT( rect.right, rect.top - nThick, rect.right + nThick, rect.top );
  310.     CRect rectLB( rect.left - nThick, rect.bottom, rect.left, rect.bottom + nThick );
  311.     CRect rectRB( rect.right, rect.bottom, rect.right + nThick, rect.bottom + nThick );
  312.  
  313.     RenderFillRect( rectT, 0xafff8080 );
  314.     RenderFillRect( rectB, 0xafff8080 );
  315.     RenderFillRect( rectL, 0xafff8080 );
  316.     RenderFillRect( rectR, 0xafff8080 );
  317.     RenderFillRect( rectLT, 0xff8080ff );
  318.     RenderFillRect( rectRT, 0xff8080ff );
  319.     RenderFillRect( rectLB, 0xff8080ff );
  320.     RenderFillRect( rectRB, 0xff8080ff );
  321.  
  322.     return TRUE;
  323. }
  324. /*
  325.         CRect rect = m_pWndFocusChild->GetWindowRect( TRUE );
  326.         rect.InflateRect( 1, 1 );
  327.         p2DRender->RenderRect( rect, 0x80808080 );
  328.         rect.InflateRect( 1, 1 );
  329.         p2DRender->RenderRect( rect, 0xaf808080 );
  330.         rect.InflateRect( 1, 1 );
  331.         p2DRender->RenderRect( rect, 0x80808080 );
  332.         rect.InflateRect( 1, 1 );
  333.         p2DRender->RenderRect( rect, 0xaf808080 );
  334. */     
  335.        
  336. ///////////////////////////////////////////////////////////////////////////////////////////
  337.  
  338. BOOL C2DRender::ResizeRectVB( CRect* pRect, DWORD dwColorLT, DWORD dwColorRT, DWORD dwColorLB, DWORD dwColorRB, LPDIRECT3DVERTEXBUFFER9 pVB)
  339. {
  340.     DRAWVERTEX* pDrawVertices;
  341.     HRESULT hr = pVB->Lock( 0,sizeof(DRAWVERTEX)*5,(void**)&pDrawVertices, D3DLOCK_DISCARD );
  342.     if(hr != D3D_OK) return FALSE;
  343.     //dwColor |=  0xff000000;
  344.     pDrawVertices->vec.x     = (FLOAT)pRect->left;
  345.     pDrawVertices->vec.y     = (FLOAT)pRect->top;
  346.     pDrawVertices->vec.z     = 0.0f;
  347.     pDrawVertices->rhw   = 1.0f;
  348.     pDrawVertices->color = dwColorLT;
  349.     pDrawVertices++;
  350.     pDrawVertices->vec.x     = (FLOAT)pRect->right;
  351.     pDrawVertices->vec.y     = (FLOAT)pRect->top;
  352.     pDrawVertices->vec.z     = 0.0f;
  353.     pDrawVertices->rhw   = 1.0f;
  354.     pDrawVertices->color = dwColorRT;
  355.     pDrawVertices++;
  356.     pDrawVertices->vec.x     = (FLOAT)pRect->right;
  357.     pDrawVertices->vec.y     = (FLOAT)pRect->bottom;
  358.     pDrawVertices->vec.z     = 0.0f;
  359.     pDrawVertices->rhw   = 1.0f;
  360.     pDrawVertices->color = dwColorRB;
  361.     pDrawVertices++;
  362.     pDrawVertices->vec.x     = (FLOAT)pRect->left;
  363.     pDrawVertices->vec.y     = (FLOAT)pRect->bottom;
  364.     pDrawVertices->vec.z     = 0.0f;
  365.     pDrawVertices->rhw   = 1.0f;
  366.     pDrawVertices->color = dwColorLB;
  367.     pDrawVertices++;
  368.     pDrawVertices->vec.x     = (FLOAT)pRect->left;
  369.     pDrawVertices->vec.y     = (FLOAT)pRect->top;
  370.     pDrawVertices->vec.z     = 0.0f;
  371.     pDrawVertices->rhw   = 1.0f;
  372.     pDrawVertices->color = dwColorLT;
  373.  
  374.     pVB->Unlock();
  375.     return TRUE;
  376. }
  377. BOOL C2DRender::RenderRect( CRect rect, DWORD dwColorLT, DWORD dwColorRT, DWORD dwColorLB, DWORD dwColorRB )
  378. {
  379.     rect += m_ptOrigin; rect.right--; rect.bottom--;
  380.     ResizeRectVB( &rect, dwColorLT, dwColorRT, dwColorLB, dwColorRB, m_pVBRect);
  381.     m_pd3dDevice->SetTexture( 0, NULL );
  382.     m_pd3dDevice->SetFVF( D3DFVF_DRAWVERTEX );
  383.     m_pd3dDevice->SetStreamSource( 0, m_pVBRect, 0,sizeof( DRAWVERTEX ) );
  384.     m_pd3dDevice->DrawPrimitive( D3DPT_LINESTRIP, 0, 4);
  385.     return TRUE;
  386. }
  387. ///////////////////////////////////////////////////////////////////////////////////////////
  388.  
  389. BOOL C2DRender::ResizeRoundRectVB( CRect* pRect, DWORD dwColorLT, DWORD dwColorRT, DWORD dwColorLB, DWORD dwColorRB, LPDIRECT3DVERTEXBUFFER9 pVB, LPDIRECT3DTEXTURE9 m_pTexture)
  390. {
  391.     DRAWVERTEX* pDrawVertices;
  392.     HRESULT hr = pVB->Lock( 0,sizeof(DRAWVERTEX)*8,(void**)&pDrawVertices, D3DLOCK_DISCARD );
  393.     if(hr != D3D_OK) return FALSE;
  394. //  dwColor |=  0xff000000;
  395.     //////////////////////////////////////
  396.     pDrawVertices->vec.x     = (FLOAT)pRect->left + 1;
  397.     pDrawVertices->vec.y     = (FLOAT)pRect->top;
  398.     pDrawVertices->vec.z     = 0.0f;
  399.     pDrawVertices->rhw   = 1.0f;
  400.     pDrawVertices->color = dwColorLT;
  401.     pDrawVertices++;
  402.     pDrawVertices->vec.x     = (FLOAT)pRect->right;// - 1;
  403.     pDrawVertices->vec.y     = (FLOAT)pRect->top;
  404.     pDrawVertices->vec.z     = 0.0f;
  405.     pDrawVertices->rhw   = 1.0f;
  406.     pDrawVertices->color = dwColorRT;
  407.     pDrawVertices++;
  408.     //////////////////////////////////////
  409.     pDrawVertices->vec.x     = (FLOAT)pRect->right;
  410.     pDrawVertices->vec.y     = (FLOAT)pRect->top + 1;
  411.     pDrawVertices->vec.z     = 0.0f;
  412.     pDrawVertices->rhw   = 1.0f;
  413.     pDrawVertices->color = dwColorRT;
  414.     pDrawVertices++;
  415.     pDrawVertices->vec.x     = (FLOAT)pRect->right;
  416.     pDrawVertices->vec.y     = (FLOAT)pRect->bottom;// - 1;
  417.     pDrawVertices->vec.z     = 0.0f;
  418.     pDrawVertices->rhw   = 1.0f;
  419.     pDrawVertices->color = dwColorRB;
  420.     pDrawVertices++;
  421.     //////////////////////////////////////
  422.     pDrawVertices->vec.x     = (FLOAT)pRect->left + 1;
  423.     pDrawVertices->vec.y     = (FLOAT)pRect->bottom;
  424.     pDrawVertices->vec.z     = 0.0f;
  425.     pDrawVertices->rhw   = 1.0f;
  426.     pDrawVertices->color = dwColorLB;
  427.     pDrawVertices++;
  428.     pDrawVertices->vec.x     = (FLOAT)pRect->right;// - 1;
  429.     pDrawVertices->vec.y     = (FLOAT)pRect->bottom;
  430.     pDrawVertices->vec.z     = 0.0f;
  431.     pDrawVertices->rhw   = 1.0f;
  432.     pDrawVertices->color = dwColorRB;
  433.     pDrawVertices++;
  434.     //////////////////////////////////////
  435.     pDrawVertices->vec.x     = (FLOAT)pRect->left;
  436.     pDrawVertices->vec.y     = (FLOAT)pRect->top + 1;
  437.     pDrawVertices->vec.z     = 0.0f;
  438.     pDrawVertices->rhw   = 1.0f;
  439.     pDrawVertices->color = dwColorLT;
  440.     pDrawVertices++;
  441.     pDrawVertices->vec.x     = (FLOAT)pRect->left;
  442.     pDrawVertices->vec.y     = (FLOAT)pRect->bottom;// - 1;
  443.     pDrawVertices->vec.z     = 0.0f;
  444.     pDrawVertices->rhw   = 1.0f;
  445.     pDrawVertices->color = dwColorRB;
  446.     pDrawVertices++;
  447.     //////////////////////////////////////
  448.     pVB->Unlock();
  449.     return TRUE;
  450. }
  451. BOOL C2DRender::RenderRoundRect( CRect rect, DWORD dwColorLT, DWORD dwColorRT, DWORD dwColorLB, DWORD dwColorRB, LPDIRECT3DTEXTURE9 m_pTexture)
  452. {
  453.     rect += m_ptOrigin; rect.right--; rect.bottom--;
  454.     ResizeRoundRectVB( &rect, dwColorLT, dwColorRT, dwColorLB, dwColorRB, m_pVBRoundRect );
  455.     m_pd3dDevice->SetTexture( 0, m_pTexture );
  456.     m_pd3dDevice->SetFVF( D3DFVF_DRAWVERTEX );
  457.     m_pd3dDevice->SetStreamSource( 0, m_pVBRoundRect, 0,sizeof( DRAWVERTEX ) );
  458.     m_pd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, 4);
  459.     return TRUE;
  460. }
  461.  
  462. BOOL C2DRender::RenderLine( CPoint pt1, CPoint pt2, DWORD dwColor1, DWORD dwColor2 )
  463. {
  464.     pt1 += m_ptOrigin;
  465.     pt2 += m_ptOrigin;
  466.  
  467.     DRAWVERTEX* pDrawVertices;
  468.     HRESULT hr = m_pVBLine->Lock( 0,sizeof(DRAWVERTEX)*2,(void**)&pDrawVertices, D3DLOCK_DISCARD );
  469.     if(hr != D3D_OK) return FALSE;
  470.     pDrawVertices->vec.x     = (FLOAT)pt1.x;
  471.     pDrawVertices->vec.y     = (FLOAT)pt1.y;
  472.     pDrawVertices->vec.z     = -0.0f;
  473.     pDrawVertices->rhw   = 1.0f;
  474.     pDrawVertices->color = dwColor1;
  475.     pDrawVertices++;
  476.     pDrawVertices->vec.x     = (FLOAT)pt2.x;
  477.     pDrawVertices->vec.y     = (FLOAT)pt2.y;
  478.     pDrawVertices->vec.z     = -0.0f;
  479.     pDrawVertices->rhw   = 1.0f;
  480.     pDrawVertices->color = dwColor2;
  481.     pDrawVertices++;
  482.     m_pVBLine->Unlock();
  483.  
  484.     m_pd3dDevice->SetTexture( 0, NULL );
  485.     m_pd3dDevice->SetFVF( D3DFVF_DRAWVERTEX );
  486.     m_pd3dDevice->SetStreamSource( 0, m_pVBLine, 0,sizeof( DRAWVERTEX ) );
  487.     m_pd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, 1);
  488.     return TRUE;
  489. }
  490.  
  491. void C2DRender::TextOut_EditString( int x,int y, CEditString& strEditString, int nPos, int nLines, int nLineSpace )
  492. {
  493.     SIZE size = m_pFont->GetTextExtent( strEditString );
  494.     size.cy = m_pFont->GetMaxHeight() * strEditString.GetLineCount();
  495.     CRect rect( x + m_ptOrigin.x, y + m_ptOrigin.y, x + m_ptOrigin.x + size.cx, y + m_ptOrigin.y + size.cy );
  496.     if( m_clipRect.RectLapRect( rect ) )
  497.     {
  498.         TCHAR strHan[3];
  499.         int nLength  = strEditString.GetLength();
  500.         DWORD dwCurOffset;
  501.         x += m_ptOrigin.x;
  502.         y += m_ptOrigin.y;
  503.         int nBegin = x;
  504.         m_pFont->DrawText( (FLOAT)( x ), (FLOAT)( y ), 0, strEditString, nPos, nLines, nLineSpace );
  505.         if( nLines == 0 )
  506.             nLines = strEditString.GetLineCount();
  507.         int nMax = nPos + nLines;
  508.         if( nMax > (int)( strEditString.GetLineCount() ) )
  509.             nMax = strEditString.GetLineCount();
  510.  
  511.             //nLines = nLength;
  512.         //for( int i = nPos; i < nPos + nLength; i++ )
  513.         for( int i = nPos; i < nMax; i++ )
  514.         {
  515.             CString string = strEditString.GetLine( i );
  516.             DWORD dwOffset = strEditString.GetLineOffset( i );
  517.             strHan[0] = 0;
  518.             dwCurOffset = 0;
  519.             const char* begin = string;
  520.             const char* end = begin + string.GetLength();
  521.             const char* iter = begin;
  522.  
  523.             while(*iter && iter < end)
  524.             {
  525.                 DWORD dwColor = strEditString.m_adwColor[ dwOffset + iter-begin ];
  526.                 DWORD dwStyle = strEditString.m_abyStyle[ dwOffset + iter-begin ];
  527.                 WORD wCodePage = strEditString.m_awCodePage[ dwOffset + iter-begin ];
  528.  
  529.                 const char* next = CharNextEx(iter, wCodePage );
  530.                
  531.                 char temp[16];
  532.                 memcpy(temp, iter, next-iter);
  533.                 temp[next-iter] = 0;
  534.  
  535.                 SIZE size;
  536.                 m_pFont->GetTextExtent( temp, &size, wCodePage );
  537.  
  538.                 iter = next;
  539.  
  540.                 if( *temp == 10 )       //gmpbigsun(100414) : pass a character 'ENTER'
  541.                     continue;
  542.  
  543.                 // ºí·° ÀâÀº ½ºÆ®¸µ. ¹ÝÀü Ãâ·Â
  544.                 if( dwStyle & ESSTY_BLOCK )
  545.                 {
  546.                     DWORD dwBkgr = dwColor;
  547.                     dwColor = ~dwColor | 0xff000000;
  548.                     RenderFillRect( CRect( x - m_ptOrigin.x, y - m_ptOrigin.y, x + size.cx - m_ptOrigin.x, y + size.cy - m_ptOrigin.y ), 0xff000000 );
  549.                     m_pFont->DrawText( (FLOAT)( x ), (FLOAT)( y ), dwColor, temp, 0, wCodePage );
  550.                 }
  551.                 if( dwStyle & ESSTY_SHADOW )
  552.                 {
  553.                     m_pFont->DrawText( (FLOAT)( x+2 ), (FLOAT)( y+1 ), 0xffcfcfcf, temp, 0, wCodePage );
  554.                     m_pFont->DrawText( (FLOAT)( x+1 ), (FLOAT)( y ), dwColor, temp, 0, wCodePage );
  555.                 }
  556.  
  557.                 if( dwStyle & ESSTY_BOLD )
  558.                 {
  559.                     if( ::GetLanguage() == LANG_THA )
  560.                         m_pFont->DrawText( (FLOAT)( x ), (FLOAT)( y ), 0xff1010ff, temp, 0, wCodePage );
  561.                     else
  562.                         m_pFont->DrawText( (FLOAT)( x+1 ), (FLOAT)( y ), dwColor, temp, 0, wCodePage );
  563.                 }
  564.  
  565.                 if( dwStyle & ESSTY_UNDERLINE )
  566.                     RenderLine( CPoint( x - m_ptOrigin.x, y + size.cy - m_ptOrigin.y - 2 ), CPoint( x + size.cx - m_ptOrigin.x, y + size.cy - m_ptOrigin.y - 2 ), dwColor );
  567.                 if( dwStyle & ESSTY_STRIKETHROUGH )
  568.                     RenderLine( CPoint( x - m_ptOrigin.x, y + ( size.cy / 2 ) - m_ptOrigin.y ), CPoint( x + size.cx - m_ptOrigin.x, y + ( size.cy / 2 ) - m_ptOrigin.y ), dwColor );
  569.  
  570.                 x += size.cx;
  571.             }
  572.  
  573.             x = nBegin;
  574.             y += m_pFont->GetMaxHeight() + nLineSpace;
  575.         }
  576.     }
  577. }
  578.  
  579. void C2DRender::TextOut( int x,int y, LPCTSTR pszString, DWORD dwColor, DWORD dwShadowColor )
  580. {
  581.     if( m_pFont )
  582.     {
  583.         SIZE size = m_pFont->GetTextExtent( pszString );
  584.         //size.cx = 8;
  585.         CRect rect( x + m_ptOrigin.x, y + m_ptOrigin.y, x + m_ptOrigin.x + size.cx, y + m_ptOrigin.y + size.cy );
  586.         if( m_clipRect.RectLapRect( rect ) )
  587.         {
  588.             if( dwShadowColor & 0xff000000 )
  589.                 m_pFont->DrawText( (FLOAT)( x + m_ptOrigin.x + 1 ), (FLOAT)( y + m_ptOrigin.y + 1 ), dwShadowColor, (TCHAR*)pszString);
  590.             m_pFont->DrawText( (FLOAT)( x + m_ptOrigin.x ), (FLOAT)( y + m_ptOrigin.y ), dwColor, (TCHAR*)pszString);
  591.         }
  592.     }
  593. }
  594. void C2DRender::TextOut( int x,int y, FLOAT fXScale, FLOAT fYScale, LPCTSTR pszString, DWORD dwColor, DWORD dwShadowColor )
  595. {
  596.     if( m_pFont )
  597.     {
  598.         SIZE size = m_pFont->GetTextExtent( pszString );
  599.         CRect rect( x + m_ptOrigin.x, y + m_ptOrigin.y, x + m_ptOrigin.x + size.cx, y + m_ptOrigin.y + size.cy );
  600.         if( m_clipRect.RectLapRect( rect ) )
  601.         {
  602.             if( dwShadowColor & 0xff000000 )
  603.                 m_pFont->DrawText( (FLOAT)( x + m_ptOrigin.x + 1 ), (FLOAT)( y + m_ptOrigin.y + 1 ), dwShadowColor, (TCHAR*)pszString);
  604.             m_pFont->DrawText( (FLOAT)( x + m_ptOrigin.x ), (FLOAT)( y + m_ptOrigin.y ), fXScale, fYScale, dwColor, (TCHAR*)pszString);
  605.         }
  606.     }
  607. }
  608. void C2DRender::TextOut( int x,int y, int nValue, DWORD dwColor, DWORD dwShadowColor )
  609. {
  610.     if( m_pFont )
  611.     {
  612.         TCHAR szString[ 32 ];
  613.         _itot( nValue, szString, 10 );
  614.         SIZE size = m_pFont->GetTextExtent( szString );
  615.         CRect rect( x + m_ptOrigin.x, y + m_ptOrigin.y, x + m_ptOrigin.x + size.cx, y + m_ptOrigin.y + size.cy );
  616.         if( m_clipRect.RectLapRect( rect ) )
  617.         {
  618.             if( dwShadowColor & 0xff000000 )
  619.                 m_pFont->DrawText( (FLOAT)( x + m_ptOrigin.x + 1 ), (FLOAT)( y + m_ptOrigin.y + 1 ), dwShadowColor, (TCHAR*)szString);
  620.             m_pFont->DrawText( (FLOAT)( x + m_ptOrigin.x ), (FLOAT)( y + m_ptOrigin.y ), dwColor, (TCHAR*)szString);
  621.         }
  622.     }
  623. }
  624.  
  625. BOOL C2DRender::RenderTexture2( CPoint pt, CTexture* pTexture, FLOAT fScaleX , FLOAT fScaleY, D3DCOLOR color )
  626. {
  627.     pt += m_ptOrigin;
  628.     CPoint ptCenter = pTexture->m_ptCenter;
  629.     ptCenter.x  = (LONG)( ptCenter.x * fScaleX );
  630.     ptCenter.y  = (LONG)( ptCenter.y * fScaleY );
  631.     pt -= ptCenter;
  632.    
  633.     FLOAT left   = (FLOAT)( pt.x );
  634.     FLOAT top    = (FLOAT)( pt.y );
  635.     FLOAT right  = pt.x + ( fScaleX * pTexture->m_size.cx );
  636.     FLOAT bottom = pt.y + ( fScaleY * pTexture->m_size.cy );
  637.  
  638.     TEXTUREVERTEX2 vertex[ 4 ];
  639.     TEXTUREVERTEX2* pVertices = vertex;
  640.    
  641.     SetTextureVertex2( pVertices, left, top, pTexture->m_fuLT, pTexture->m_fvLT, color );
  642.     pVertices++;
  643.     SetTextureVertex2( pVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT, color );
  644.     pVertices++;
  645.     SetTextureVertex2( pVertices, left, bottom, pTexture->m_fuLB, pTexture->m_fvLB, color );
  646.     pVertices++;
  647.     SetTextureVertex2( pVertices, right, bottom, pTexture->m_fuRB, pTexture->m_fvRB, color );
  648.     pVertices++;
  649.    
  650.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
  651.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
  652.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );     
  653.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );     
  654.    
  655.     m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );  
  656.     m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
  657.  
  658.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
  659.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  660.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
  661.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  662.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  663.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
  664.  
  665.    m_pd3dDevice->SetVertexShader( NULL );
  666.     m_pd3dDevice->SetTexture( 0, pTexture->m_pTexture );
  667.     m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX2 );
  668.     m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( TEXTUREVERTEX2 ) );
  669.     m_pd3dDevice->SetTexture( 0, NULL );
  670.     return TRUE;
  671. };
  672.  
  673. BOOL C2DRender::RenderTextureColor( CPoint pt, CTexture* pTexture, FLOAT fScaleX , FLOAT fScaleY, D3DCOLOR color )
  674. {
  675.     pt += m_ptOrigin;
  676.     CPoint ptCenter = pTexture->m_ptCenter;
  677.     ptCenter.x  = (LONG)( ptCenter.x * fScaleX );
  678.     ptCenter.y  = (LONG)( ptCenter.y * fScaleY );
  679.     pt -= ptCenter;
  680.    
  681.     FLOAT left   = (FLOAT)( pt.x );
  682.     FLOAT top    = (FLOAT)( pt.y );
  683.     FLOAT right  = pt.x + ( fScaleX * pTexture->m_size.cx );
  684.     FLOAT bottom = pt.y + ( fScaleY * pTexture->m_size.cy );
  685.    
  686.     TEXTUREVERTEX2 vertex[ 4 ];
  687.     TEXTUREVERTEX2* pVertices = vertex;
  688.    
  689.     SetTextureVertex2( pVertices, left, top, pTexture->m_fuLT, pTexture->m_fvLT, color );
  690.     pVertices++;
  691.     SetTextureVertex2( pVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT, color );
  692.     pVertices++;
  693.     SetTextureVertex2( pVertices, left, bottom, pTexture->m_fuLB, pTexture->m_fvLB, color );
  694.     pVertices++;
  695.     SetTextureVertex2( pVertices, right, bottom, pTexture->m_fuRB, pTexture->m_fvRB, color );
  696.     pVertices++;
  697.    
  698.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
  699.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
  700.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );     
  701.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );     
  702.    
  703.     m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );  
  704.     m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
  705.    
  706.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
  707.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  708.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
  709.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  710.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  711.    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
  712.    
  713.    m_pd3dDevice->SetVertexShader( NULL );
  714.     m_pd3dDevice->SetTexture( 0, NULL );
  715.     m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX2 );
  716.     m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( TEXTUREVERTEX2 ) );
  717.     m_pd3dDevice->SetTexture( 0, NULL );
  718.     return TRUE;
  719. };
  720.  
  721. BOOL C2DRender::RenderTextureEx( CPoint pt, CPoint pt2, CTexture* pTexture, DWORD dwBlendFactorAlhpa, FLOAT fScaleX , FLOAT fScaleY, BOOL bAnti )
  722. {
  723.     pt += m_ptOrigin;
  724.     if(!pTexture) return FALSE;
  725.     CPoint ptCenter = pTexture->m_ptCenter;
  726.     ptCenter.x  = (LONG)( ptCenter.x * fScaleX );
  727.     ptCenter.y  = (LONG)( ptCenter.y * fScaleY );
  728.     pt -= ptCenter;
  729.    
  730.     FLOAT left   = (FLOAT)( pt.x );
  731.     FLOAT top    = (FLOAT)( pt.y );
  732.     FLOAT right  = pt.x + ( fScaleX * pt2.x );
  733.     FLOAT bottom = pt.y + ( fScaleY * pt2.y );
  734.    
  735.     TEXTUREVERTEX vertex[ 4 ];
  736.     TEXTUREVERTEX* pVertices = vertex;
  737.    
  738.     SetTextureVertex( pVertices, left, top, pTexture->m_fuLT, pTexture->m_fvLT );
  739.     pVertices++;
  740.     SetTextureVertex( pVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT);
  741.     pVertices++;
  742.     SetTextureVertex( pVertices, left, bottom, pTexture->m_fuLB, pTexture->m_fvLB);
  743.     pVertices++;
  744.     SetTextureVertex( pVertices, right, bottom, pTexture->m_fuRB, pTexture->m_fvRB);
  745.     pVertices++;
  746.    
  747.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
  748.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
  749.  
  750.     if( bAnti )
  751.     {
  752.         m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );     
  753.         m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );     
  754.     }
  755.     else
  756.     {
  757.         m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );     
  758.         m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );     
  759.     }
  760.    
  761.     m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );  
  762.     m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
  763.    
  764.     m_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( dwBlendFactorAlhpa, 0, 0, 0 ) );
  765.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
  766.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  767.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  768.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  769.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR  );
  770.    
  771.    m_pd3dDevice->SetVertexShader( NULL );
  772.     m_pd3dDevice->SetTexture( 0, pTexture->m_pTexture );
  773.     m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
  774.     m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( TEXTUREVERTEX ) );
  775.     m_pd3dDevice->SetTexture( 0, NULL );
  776.     return TRUE;
  777. };
  778.  
  779. BOOL C2DRender::RenderTextureEx2( CPoint pt, CPoint pt2, CTexture* pTexture, DWORD dwBlendFactorAlhpa, FLOAT fScaleX , FLOAT fScaleY, D3DCOLOR color )
  780. {
  781.     pt += m_ptOrigin;
  782.     CPoint ptCenter = pTexture->m_ptCenter;
  783.     ptCenter.x  = (LONG)( ptCenter.x * fScaleX );
  784.     ptCenter.y  = (LONG)( ptCenter.y * fScaleY );
  785.     pt -= ptCenter;
  786.    
  787.     FLOAT left   = (FLOAT)( pt.x );
  788.     FLOAT top    = (FLOAT)( pt.y );
  789.     FLOAT right  = pt.x + ( fScaleX * pt2.x );
  790.     FLOAT bottom = pt.y + ( fScaleY * pt2.y );
  791.    
  792.     TEXTUREVERTEX2 vertex[ 4 ];
  793.     TEXTUREVERTEX2* pVertices = vertex;
  794.    
  795.     SetTextureVertex2( pVertices, left, top, pTexture->m_fuLT, pTexture->m_fvLT, color );
  796.     pVertices++;
  797.     SetTextureVertex2( pVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT, color);
  798.     pVertices++;
  799.     SetTextureVertex2( pVertices, left, bottom, pTexture->m_fuLB, pTexture->m_fvLB, color);
  800.     pVertices++;
  801.     SetTextureVertex2( pVertices, right, bottom, pTexture->m_fuRB, pTexture->m_fvRB, color);
  802.     pVertices++;
  803.    
  804.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
  805.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
  806.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );     
  807.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );     
  808.    
  809.     m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );  
  810.     m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
  811.    
  812.     m_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( dwBlendFactorAlhpa, 0, 0, 0 ) );
  813.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
  814.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  815.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  816.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  817.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR  );
  818.    
  819.    m_pd3dDevice->SetVertexShader( NULL );
  820.     m_pd3dDevice->SetTexture( 0, NULL /*pTexture->m_pTexture*/ );
  821.     m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX2 );
  822.     m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( TEXTUREVERTEX2 ) );
  823.     m_pd3dDevice->SetTexture( 0, NULL );
  824.     return TRUE;
  825. };
  826.  
  827.  
  828. BOOL C2DRender::RenderTexture( CPoint pt, CTexture* pTexture, DWORD dwBlendFactorAlhpa, FLOAT fScaleX , FLOAT fScaleY )
  829. {
  830.     if( !pTexture )         //gmpbigsun
  831.         return FALSE;
  832.  
  833.     pt += m_ptOrigin;
  834.     CPoint ptCenter = pTexture->m_ptCenter;
  835.     ptCenter.x  = (LONG)( ptCenter.x * fScaleX );
  836.     ptCenter.y  = (LONG)( ptCenter.y * fScaleY );
  837.     pt -= ptCenter;
  838.  
  839.     FLOAT left   = (FLOAT)( pt.x );
  840.     FLOAT top    = (FLOAT)( pt.y );
  841.     FLOAT right  = pt.x + ( fScaleX * pTexture->m_size.cx );
  842.     FLOAT bottom = pt.y + ( fScaleY * pTexture->m_size.cy );
  843.    
  844.     TEXTUREVERTEX vertex[ 4 ];
  845.     TEXTUREVERTEX* pVertices = vertex;
  846.    
  847.     SetTextureVertex( pVertices, left, top, pTexture->m_fuLT, pTexture->m_fvLT );
  848.     pVertices++;
  849.     SetTextureVertex( pVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT);
  850.     pVertices++;
  851.     SetTextureVertex( pVertices, left, bottom, pTexture->m_fuLB, pTexture->m_fvLB);
  852.     pVertices++;
  853.     SetTextureVertex( pVertices, right, bottom, pTexture->m_fuRB, pTexture->m_fvRB);
  854.     pVertices++;
  855.  
  856.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
  857.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
  858.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );     
  859.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );     
  860.  
  861.     m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );  
  862.     m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
  863.  
  864.     m_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( dwBlendFactorAlhpa, 0, 0, 0 ) );
  865.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
  866.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  867.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  868.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  869.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR  );
  870.  
  871.    m_pd3dDevice->SetVertexShader( NULL );
  872.     m_pd3dDevice->SetTexture( 0, pTexture->m_pTexture );
  873.     m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
  874.     m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( TEXTUREVERTEX ) );
  875.     m_pd3dDevice->SetTexture( 0, NULL );
  876.     return TRUE;
  877. };
  878.  
  879. // ÅؽºÃÄ È¸ÀüÇؼ­ Âï±â.
  880. BOOL C2DRender::RenderTextureRotate( CPoint pt, CTexture* pTexture, DWORD dwBlendFactorAlhpa, FLOAT fScaleX , FLOAT fScaleY, FLOAT fRadian )
  881. {
  882.     pt += m_ptOrigin;
  883.     CPoint ptCenter = pTexture->m_ptCenter;
  884.     ptCenter.x  = (LONG)( ptCenter.x * fScaleX );
  885.     ptCenter.y  = (LONG)( ptCenter.y * fScaleY );
  886.     pt -= ptCenter;
  887.  
  888.     FLOAT _left   = (FLOAT)( pt.x );
  889.     FLOAT _top    = (FLOAT)( pt.y );
  890.     FLOAT _right  = pt.x + ( fScaleX * pTexture->m_size.cx );
  891.     FLOAT _bottom = pt.y + ( fScaleY * pTexture->m_size.cy );
  892.    
  893. //  FLOAT cx = _left + ((_right - _left) / 2);      // Áß½ÉÁ¡(Àý´ëÁÂÇ¥)
  894. //  FLOAT cy = _top  + ((_bottom - _top) / 2);
  895.     FLOAT cx = _left + ptCenter.x;      // Áß½ÉÁ¡(Àý´ëÁÂÇ¥)
  896.     FLOAT cy = _top  + ptCenter.y;
  897.    
  898.     _left -= cx;        // ·ÎÄñâÁØÀ¸·Î º¯È¯.
  899.     _right -= cx;
  900.     _top -= cy;
  901.     _bottom -= cy;
  902.    
  903.     D3DXVECTOR2 v1, v2, v3, v4;
  904.     D3DXMATRIX  mRot;
  905.  
  906.     v1.x = _left;   v1.y = _top;    // Á»ó
  907.     v2.x = _right;  v2.y = _top;    // ¿ì»ó
  908.     v3.x = _left;   v3.y = _bottom; // ÁÂÇÏ
  909.     v4.x = _right;  v4.y = _bottom; // ¿ìÇÏ
  910.  
  911.     D3DXMatrixRotationZ( &mRot, fRadian );
  912.     D3DXVec2TransformCoord( &v1, &v1, &mRot );      // 2DÁÂÇ¥ ȸÀü.
  913.     D3DXVec2TransformCoord( &v2, &v2, &mRot );      // 2DÁÂÇ¥ ȸÀü.
  914.     D3DXVec2TransformCoord( &v3, &v3, &mRot );      // 2DÁÂÇ¥ ȸÀü.
  915.     D3DXVec2TransformCoord( &v4, &v4, &mRot );      // 2DÁÂÇ¥ ȸÀü.
  916.    
  917.    
  918.     TEXTUREVERTEX vertex[ 4 ];
  919.     TEXTUREVERTEX* pVertices = vertex;
  920.    
  921.     SetTextureVertex( pVertices, cx + v1.x, cy + v1.y, pTexture->m_fuLT, pTexture->m_fvLT );
  922.     pVertices++;
  923.     SetTextureVertex( pVertices, cx + v2.x, cy + v2.y, pTexture->m_fuRT, pTexture->m_fvRT);
  924.     pVertices++;
  925.     SetTextureVertex( pVertices, cx + v3.x, cy + v3.y, pTexture->m_fuLB, pTexture->m_fvLB);
  926.     pVertices++;
  927.     SetTextureVertex( pVertices, cx + v4.x, cy + v4.y, pTexture->m_fuRB, pTexture->m_fvRB);
  928.     pVertices++;
  929.    
  930.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
  931.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
  932.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );     
  933.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );     
  934.    
  935.     m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );  
  936.     m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
  937.    
  938.     m_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( dwBlendFactorAlhpa, 0, 0, 0 ) );
  939.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
  940.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  941.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  942.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  943.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR  );
  944.    
  945.    m_pd3dDevice->SetVertexShader( NULL );
  946.     m_pd3dDevice->SetTexture( 0, pTexture->m_pTexture );
  947.     m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
  948.     m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( TEXTUREVERTEX ) );
  949.     m_pd3dDevice->SetTexture( 0, NULL );
  950.     return TRUE;
  951. }
  952.  
  953. BOOL C2DRender::RenderTextureRotate( CPoint pt, CTexture* pTexture, DWORD dwBlendFactorAlhpa, FLOAT fRadian, BOOL bCenter, FLOAT fScaleX, FLOAT fScaleY )
  954. {
  955.     // gmpbigsun( 09_12_2# ) : ÅؽºÃç ȸÀüÃà º¯°æ
  956.     // if bCenter is TRUE, Axis is texture center
  957.     // else Axis is left-top
  958.  
  959.     pt += m_ptOrigin;
  960.     CPoint ptCenter = pTexture->m_ptCenter;
  961.     ptCenter.x  = (LONG)( ptCenter.x * fScaleX );
  962.     ptCenter.y  = (LONG)( ptCenter.y * fScaleY );
  963.     pt -= ptCenter;
  964.  
  965.     FLOAT _left   = (FLOAT)( pt.x );
  966.     FLOAT _top    = (FLOAT)( pt.y );
  967.     FLOAT _right  = pt.x + ( fScaleX * pTexture->m_size.cx );
  968.     FLOAT _bottom = pt.y + ( fScaleY * pTexture->m_size.cy );
  969.    
  970.     FLOAT cx = 0.0f;
  971.     FLOAT cy = 0.0f;
  972.     if( bCenter )
  973.     {
  974.         cx = _left + ((_right - _left) / 2);        // Áß½ÉÁ¡(Àý´ëÁÂÇ¥)
  975.         cy = _top  + ((_bottom - _top) / 2);
  976.     }
  977.     else
  978.     {
  979.         cx = _left + ptCenter.x;        // Áß½ÉÁ¡(Àý´ëÁÂÇ¥)
  980.         cy = _top  + ptCenter.y;
  981.     }
  982.    
  983.     _left -= cx;        // ·ÎÄñâÁØÀ¸·Î º¯È¯.
  984.     _right -= cx;
  985.     _top -= cy;
  986.     _bottom -= cy;
  987.    
  988.     D3DXVECTOR2 v1, v2, v3, v4;
  989.     D3DXMATRIX  mRot;
  990.  
  991.     v1.x = _left;   v1.y = _top;    // Á»ó
  992.     v2.x = _right;  v2.y = _top;    // ¿ì»ó
  993.     v3.x = _left;   v3.y = _bottom; // ÁÂÇÏ
  994.     v4.x = _right;  v4.y = _bottom; // ¿ìÇÏ
  995.  
  996.     D3DXMatrixRotationZ( &mRot, fRadian );
  997.     D3DXVec2TransformCoord( &v1, &v1, &mRot );      // 2DÁÂÇ¥ ȸÀü.
  998.     D3DXVec2TransformCoord( &v2, &v2, &mRot );      // 2DÁÂÇ¥ ȸÀü.
  999.     D3DXVec2TransformCoord( &v3, &v3, &mRot );      // 2DÁÂÇ¥ ȸÀü.
  1000.     D3DXVec2TransformCoord( &v4, &v4, &mRot );      // 2DÁÂÇ¥ ȸÀü.
  1001.    
  1002.    
  1003.     TEXTUREVERTEX vertex[ 4 ];
  1004.     TEXTUREVERTEX* pVertices = vertex;
  1005.    
  1006.     SetTextureVertex( pVertices, cx + v1.x, cy + v1.y, pTexture->m_fuLT, pTexture->m_fvLT );
  1007.     pVertices++;
  1008.     SetTextureVertex( pVertices, cx + v2.x, cy + v2.y, pTexture->m_fuRT, pTexture->m_fvRT);
  1009.     pVertices++;
  1010.     SetTextureVertex( pVertices, cx + v3.x, cy + v3.y, pTexture->m_fuLB, pTexture->m_fvLB);
  1011.     pVertices++;
  1012.     SetTextureVertex( pVertices, cx + v4.x, cy + v4.y, pTexture->m_fuRB, pTexture->m_fvRB);
  1013.     pVertices++;
  1014.    
  1015.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
  1016.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
  1017.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );     
  1018.     m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );     
  1019.    
  1020.     m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );  
  1021.     m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
  1022.    
  1023.     m_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( dwBlendFactorAlhpa, 0, 0, 0 ) );
  1024.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
  1025.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  1026.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  1027.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  1028.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR  );
  1029.    
  1030.    m_pd3dDevice->SetVertexShader( NULL );
  1031.     m_pd3dDevice->SetTexture( 0, pTexture->m_pTexture );
  1032.     m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
  1033.     m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( TEXTUREVERTEX ) );
  1034.     m_pd3dDevice->SetTexture( 0, NULL );
  1035.     return TRUE;
  1036. }
  1037.  
  1038. BOOL C2DRender::RenderFillTriangle( CPoint pt1, CPoint pt2, CPoint pt3, DWORD dwColor1, DWORD dwColor2, DWORD dwColor3 )
  1039. {
  1040.     pt1 += m_ptOrigin;
  1041.     pt2 += m_ptOrigin;
  1042.     pt3 += m_ptOrigin;
  1043.  
  1044.     DRAWVERTEX* pDrawVertices;
  1045.     HRESULT hr = m_pVBFillTriangle->Lock( 0, sizeof(DRAWVERTEX) * 3 , (void**)&pDrawVertices, D3DLOCK_DISCARD );
  1046.     pDrawVertices->vec.x     = (FLOAT)pt1.x;
  1047.     pDrawVertices->vec.y     = (FLOAT)pt1.y;
  1048.     pDrawVertices->vec.z     = 0.0f;
  1049.     pDrawVertices->rhw   = 1.0f;
  1050.     pDrawVertices->color = dwColor1;
  1051.     pDrawVertices++;
  1052.     pDrawVertices->vec.x     = (FLOAT)pt2.x;
  1053.     pDrawVertices->vec.y     = (FLOAT)pt2.y;
  1054.     pDrawVertices->vec.z     = 0.0f;
  1055.     pDrawVertices->rhw   = 1.0f;
  1056.     pDrawVertices->color = dwColor2;
  1057.     pDrawVertices++;
  1058.     pDrawVertices->vec.x     = (FLOAT)pt3.x;
  1059.     pDrawVertices->vec.y     = (FLOAT)pt3.y;
  1060.     pDrawVertices->vec.z     = 0.0f;
  1061.     pDrawVertices->rhw   = 1.0f;
  1062.     pDrawVertices->color = dwColor3;
  1063.     pDrawVertices++;
  1064.     m_pVBFillTriangle->Unlock();
  1065.  
  1066.     m_pd3dDevice->SetTexture( 0, NULL );
  1067.     m_pd3dDevice->SetFVF( D3DFVF_DRAWVERTEX );
  1068.     m_pd3dDevice->SetStreamSource( 0, m_pVBFillTriangle, 0,sizeof( DRAWVERTEX ) );
  1069.     m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1);
  1070.     return TRUE;
  1071. }
  1072. ///////////////////////////////////////////////////////////////////////////////////////////
  1073.  
  1074. BOOL C2DRender::RenderTriangle( CPoint pt1, CPoint pt2, CPoint pt3, DWORD dwColor1, DWORD dwColor2, DWORD dwColor3 )
  1075. {
  1076.     pt1 += m_ptOrigin;
  1077.     pt2 += m_ptOrigin;
  1078.     pt3 += m_ptOrigin;
  1079.  
  1080.     DRAWVERTEX* pDrawVertices;
  1081.     HRESULT hr = m_pVBTriangle->Lock( 0, sizeof(DRAWVERTEX) * 4, (void**)&pDrawVertices, D3DLOCK_DISCARD );
  1082.     pDrawVertices->vec.x     = (FLOAT)pt1.x;
  1083.     pDrawVertices->vec.y     = (FLOAT)pt1.y;
  1084.     pDrawVertices->vec.z     = 0.0f;
  1085.     pDrawVertices->rhw   = 1.0f;
  1086.     pDrawVertices->color = dwColor1;
  1087.     pDrawVertices++;
  1088.     pDrawVertices->vec.x     = (FLOAT)pt2.x;
  1089.     pDrawVertices->vec.y     = (FLOAT)pt2.y;
  1090.     pDrawVertices->vec.z     = 0.0f;
  1091.     pDrawVertices->rhw   = 1.0f;
  1092.     pDrawVertices->color = dwColor2;
  1093.     pDrawVertices++;
  1094.     pDrawVertices->vec.x     = (FLOAT)pt3.x;
  1095.     pDrawVertices->vec.y     = (FLOAT)pt3.y;
  1096.     pDrawVertices->vec.z     = 0.0f;
  1097.     pDrawVertices->rhw   = 1.0f;
  1098.     pDrawVertices->color = dwColor3;
  1099.     pDrawVertices++;
  1100.     pDrawVertices->vec.x     = (FLOAT)pt1.x;
  1101.     pDrawVertices->vec.y     = (FLOAT)pt1.y;
  1102.     pDrawVertices->vec.z     = 0.0f;
  1103.     pDrawVertices->rhw   = 1.0f;
  1104.     pDrawVertices->color = dwColor1;
  1105.     m_pVBTriangle->Unlock();
  1106.  
  1107.     m_pd3dDevice->SetTexture( 0, NULL );
  1108.     m_pd3dDevice->SetFVF( D3DFVF_DRAWVERTEX );
  1109.     m_pd3dDevice->SetStreamSource( 0, m_pVBTriangle, 0,sizeof( DRAWVERTEX ) );
  1110.     m_pd3dDevice->DrawPrimitive( D3DPT_LINESTRIP, 0, 3);
  1111.     return TRUE;
  1112. }
  1113. //////////////////////////////////////////////////////////////////////////////////
  1114. CTexture::CTexture()
  1115. {
  1116.     m_pTexture = NULL;
  1117.     m_bAutoFree = FALSE;
  1118.     m_ptCenter = CPoint( 0, 0 );
  1119.  
  1120. #ifdef __YDEBUG
  1121.     m_Pool = D3DPOOL_MANAGED;
  1122. #endif //__YDEBUG
  1123.    
  1124.    
  1125.  
  1126. }
  1127. CTexture::~CTexture()
  1128. {
  1129.     if( m_bAutoFree )
  1130.         DeleteDeviceObjects();
  1131. }
  1132.  
  1133. BOOL CTexture::DeleteDeviceObjects()
  1134. {
  1135.     SAFE_RELEASE( m_pTexture );
  1136.     return TRUE;
  1137. }
  1138. BOOL CTexture::CreateTexture( LPDIRECT3DDEVICE9 pd3dDevice,
  1139.      int nWidth, int nHeight, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool )
  1140. {
  1141.     if( Pool != 0 && Pool != 1 )
  1142.     {
  1143.         int a = 0;
  1144.     }
  1145.  
  1146.     HRESULT hr = pd3dDevice->CreateTexture( nWidth, nHeight, 1, Usage, Format, Pool, &m_pTexture, NULL );
  1147.    
  1148.     if( hr != D3D_OK ) 
  1149.     {
  1150.         CString string;
  1151.         string.Format( "ÅؽºÃç »ý¼º ¸øÇÔ. Error = %d, cx = %d, cy = %d", hr, nWidth, nHeight );
  1152. #ifdef __CLIENT
  1153. //      if( hr == D3DERR_INVALIDDEVICE )
  1154. //      {
  1155. //          MessageBox( g_Neuz.GetSafeHwnd(), "Á˼ÛÇÕ´Ï´Ù. Áö¿øÇÏÁö ¾Ê´Â ±×·¡ÇÈÄ«µåÀÔ´Ï´Ù.\r\nSorry. Not support graphic hardware", "Error", MB_OK );
  1156. //          exit(1);
  1157. //      }
  1158. #endif
  1159.         ADDERRORMSG( string );
  1160.         ASSERT( 0 );
  1161.         return FALSE;
  1162.     }
  1163.     m_size = CSize(nWidth, nHeight);
  1164.     m_fuLT = 0.0f;
  1165.     m_fvLT = 0.0f;
  1166.     m_fuRT = 1.0f;
  1167.     m_fvRT = 0.0f;
  1168.     m_fuLB = 0.0f;
  1169.     m_fvLB = 1.0f;
  1170.     m_fuRB = 1.0f,
  1171.     m_fvRB = 1.0f;
  1172.     m_ptCenter = CPoint(0,0);
  1173.     m_bAutoFree = TRUE;
  1174. //#endif
  1175.  
  1176. #ifdef __YDEBUG
  1177.     m_nLevels = Levels;
  1178.     m_dwUsage = Usage;
  1179.     m_Pool    = Pool;
  1180.     m_Format  = Format;
  1181. #endif //__YDEBUG
  1182.     return TRUE;
  1183. }
  1184.  
  1185. BOOL CTexture::LoadTexture( LPDIRECT3DDEVICE9 pd3dDevice, LPCTSTR pFileName, D3DCOLOR d3dKeyColor, BOOL bMyLoader )
  1186. {
  1187. #ifndef __WORLDSERVER
  1188.     // ¿©±â¼­ ÅؽºÃç »ý¼º
  1189.  
  1190. #ifdef _DEBUG
  1191.     m_strFileName = pFileName;
  1192. #endif
  1193.     SIZE size;
  1194.     TCHAR szFileName[ MAX_PATH ];
  1195.     DWORD dwOffsetDest = 0;
  1196.     DWORD dwOffsetSrc = 0;
  1197.     _tcscpy( szFileName, pFileName );
  1198.     _tcslwr( szFileName );
  1199.  
  1200. #ifdef __YDEBUG
  1201.     m_strTexFileName = pFileName;
  1202.     m_d3dKeyColor    = d3dKeyColor;
  1203.     m_bMyLoader      = bMyLoader;
  1204. #endif //__YDEBUG
  1205.  
  1206.     if( bMyLoader == FALSE ) // dds only
  1207.     {
  1208.         // item, icon, A1R5G5B5
  1209.         //dKeyColor = 0;
  1210.         D3DXIMAGE_INFO imageInfo;
  1211.           // Create the texture using D3DX
  1212.         HRESULT hr = ::LoadTextureFromRes( pd3dDevice, pFileName,
  1213.             D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A1R5G5B5,//D3DFMT_UNKNOWN,//D3DFMT_A1R5G5B5,
  1214.             D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR,
  1215.             D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR, d3dKeyColor, &imageInfo, NULL, &m_pTexture );
  1216.         if( hr != S_OK )
  1217.         {
  1218.             LPCTSTR szErr = Error( "CTexture::LoadTexture : %s read error", pFileName );
  1219.             ADDERRORMSG( szErr );
  1220.             return FALSE;      
  1221.         }
  1222.         size.cx = imageInfo.Width;
  1223.         size.cy = imageInfo.Height;
  1224.         m_size = size;
  1225.     }
  1226.     else // bmp or tga
  1227.     if( strstr( szFileName, ".bmp" ) )
  1228.     {
  1229.         IMAGE image;
  1230.         LPBYTE lpData = NULL;
  1231.         if( LoadBMP( pFileName, &image ) == TRUE )
  1232.         {
  1233.             lpData = image.lpData;
  1234.             m_size = image.size;
  1235.             size = m_size;
  1236.             AdjustSize( &m_size );
  1237.             int nDestLine = m_size.cx - size.cx;
  1238.  
  1239.         //#define BMP32BIT
  1240.         #ifdef BMP32BIT
  1241.             CreateTexture( pd3dDevice, m_size.cx, m_size.cy, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED );
  1242.         #else
  1243.             CreateTexture( pd3dDevice, m_size.cx, m_size.cy, D3DX_DEFAULT, 0, D3DFMT_A1R5G5B5, D3DPOOL_MANAGED );
  1244.         #endif
  1245.             HRESULT hr;
  1246.             D3DLOCKED_RECT lockedRect;
  1247.             if( ( hr = m_pTexture->LockRect( 0, &lockedRect, 0, 0 ) ) == D3D_OK )// Lock
  1248.             {
  1249.             #ifdef BMP32BIT
  1250.                 LPDWORD pDest = (LPDWORD)lockedRect.pBits;
  1251.                 LPDWORD pSrc = (LPDWORD)lpData;
  1252.             #else
  1253.                 LPWORD pDest = (LPWORD)lockedRect.pBits;
  1254.             #endif
  1255.                 for(int y = 0; y < size.cy; y++, dwOffsetDest += nDestLine )
  1256.                 {
  1257.                     for(int x = 0; x < size.cx; x++, dwOffsetSrc += 3, dwOffsetDest++ )
  1258.                     {                  
  1259.                         BYTE byData1 = lpData[ dwOffsetSrc + 0 ];
  1260.                         BYTE byData2 = lpData[ dwOffsetSrc + 1 ];
  1261.                         BYTE byData3 = lpData[ dwOffsetSrc + 2 ];
  1262.                     #ifdef BMP32BIT
  1263.                         if( byData1 == 255 && byData2 == 0 && byData3 == 255 )
  1264.                             pDest[ dwOffsetDest ] = 0;
  1265.                         else
  1266.                             pDest[ dwOffsetDest ] = 0xff000000 | ( byData3 << 16 ) | ( byData2 << 8 ) | byData1;
  1267.                     #else
  1268.                         if( byData1 == 255 && byData2 == 0 && byData3 == 255 )
  1269.                             pDest[ dwOffsetDest] = 0x0000;
  1270.                         else
  1271.                             pDest[ dwOffsetDest] = 0x8000 | ( ( byData3 >> 3 ) << 10 ) | ( ( byData2 >> 3 ) << 5 ) | ( byData1 >> 3 );
  1272.                     #endif
  1273.                     }
  1274.                 }
  1275.                 m_pTexture->UnlockRect( 0);
  1276.             }
  1277.             else
  1278.             {
  1279.             #ifndef _DEBUG
  1280.                 CString string;
  1281.                 string.Format( "Lock ½ÇÆÐ : Error = %d", hr );
  1282.                 ADDERRORMSG( string );
  1283.                 ASSERT( 0 );
  1284.             #endif
  1285.             }
  1286.         }
  1287.         else
  1288.             Error( "CTexture::LoadTexture : %s read error", pFileName );
  1289.     }
  1290.     else // bmp or tga
  1291.     if( strstr( szFileName, ".tga" ) )
  1292.     {
  1293.         LPBYTE lpData = NULL;
  1294.         CTarga targa;
  1295.         if( targa.Load( pFileName, &lpData, &m_size ) == TRUE )
  1296.         {
  1297.             size = m_size;
  1298.             AdjustSize( &m_size );
  1299.             int nDestLine = m_size.cx - size.cx;
  1300.         #define BMP32BIT
  1301.         #ifdef BMP32BIT
  1302.             CreateTexture( pd3dDevice, m_size.cx, m_size.cy, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED );// == FALSE )
  1303.         #else
  1304.             CreateTexture( pd3dDevice, m_size.cx, m_size.cy, D3DX_DEFAULT, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED );
  1305.         #endif
  1306.             HRESULT hr;
  1307.             D3DLOCKED_RECT lockedRect;
  1308.             if( ( hr = m_pTexture->LockRect( 0, &lockedRect, 0, 0 ) ) == D3D_OK )// Lock
  1309.             {
  1310.             #ifdef BMP32BIT
  1311.                 LPDWORD pDest = (LPDWORD)lockedRect.pBits;
  1312.                 LPDWORD pSrc = (LPDWORD)lpData;
  1313.             #else
  1314.                 LPWORD pDest = (LPWORD)lockedRect.pBits;
  1315.             #endif
  1316.                 for(int y = 0; y < size.cy; y++, dwOffsetDest += nDestLine )
  1317.                 {
  1318.                     for(int x = 0; x < size.cx; x++, dwOffsetSrc++, dwOffsetDest++ )
  1319.                     {                  
  1320.                 #ifdef BMP32BIT
  1321.                         pDest[ dwOffsetDest ] = pSrc[ dwOffsetSrc ];
  1322.                 #else
  1323.                         BYTE byData1 = lpData[ dwOffsetSrc + 0 ] >> 4;
  1324.                         BYTE byData2 = lpData[ dwOffsetSrc + 1 ] >> 4;
  1325.                         BYTE byData3 = lpData[ dwOffsetSrc + 2 ] >> 4;
  1326.                         BYTE byData4 = lpData[ dwOffsetSrc + 3 ] >> 4;
  1327.  
  1328.                         if( byData1 == 0xf && byData2 == 0 && byData3 == 0xf )
  1329.                             pDest[ dwOffsetDest] = 0x0000;
  1330.                         else
  1331.                             pDest[ dwOffsetDest] = ( byData4 << 12 ) | ( byData3 << 8 ) | ( byData2 << 4 ) | byData1;
  1332.                 #endif
  1333.                     }
  1334.                 }
  1335.                 m_pTexture->UnlockRect( 0);
  1336.             }
  1337.             else
  1338.             {
  1339.             #ifndef _DEBUG
  1340.                 CString string;
  1341.                 string.Format( "Lock ½ÇÆÐ : Error = %d", hr );
  1342.                 ADDERRORMSG( string );
  1343.                 ASSERT( 0 );
  1344.             #endif
  1345.             }
  1346.         }
  1347.         else
  1348.             Error( "CTexture::LoadTexture : %s read error", pFileName );
  1349.  
  1350.         SAFE_DELETE( lpData );
  1351.     }
  1352.     if(m_pTexture == NULL )
  1353.         return FALSE;
  1354. #undef BMP32BIT
  1355.     //D3DUtil_SetColorKey( m_pTexture, d3dKeyColor );
  1356.     //D3DSURFACE_DESC surfaceDesc;
  1357.     //m_pTexture->GetLevelDesc( 0,&surfaceDesc );
  1358.  
  1359.     m_fuLT = 0.0f;
  1360.     m_fvLT = 0.0f;
  1361.  
  1362.     m_fuRT = (FLOAT) size.cx / m_size.cx;
  1363.     m_fvRT = 0.0f;
  1364.  
  1365.     m_fuLB = 0.0f;
  1366.     m_fvLB = (FLOAT) size.cy / m_size.cy;
  1367.  
  1368.     m_fuRB = (FLOAT) size.cx / m_size.cx;
  1369.     m_fvRB = (FLOAT) size.cy / m_size.cy;
  1370.  
  1371.     m_ptCenter.x = 0;
  1372.     m_ptCenter.y = 0;
  1373.  
  1374.     m_sizePitch = m_size;
  1375.     m_size = size;
  1376.  
  1377.     m_bAutoFree = TRUE;
  1378. #endif  // __WORLDSERVER
  1379.     return 1;
  1380. }
  1381.  
  1382. void CTexture::Invalidate()
  1383. {
  1384. #ifdef __YDEBUG
  1385.     if( m_Pool != D3DPOOL_DEFAULT )
  1386.         return;
  1387.        
  1388.     SAFE_RELEASE(m_pTexture);
  1389. #endif //__YDEBUG
  1390. }
  1391.  
  1392. BOOL CTexture::SetInvalidate(LPDIRECT3DDEVICE9 pd3dDevice)
  1393. {
  1394. #ifdef __YDEBUG
  1395.     if( m_Pool != D3DPOOL_DEFAULT )
  1396.         return TRUE;
  1397.  
  1398.     if( m_pTexture == NULL )
  1399.         return LoadTexture( pd3dDevice, m_strTexFileName, m_d3dKeyColor, m_bMyLoader );
  1400.     else
  1401.         return TRUE;
  1402. #endif //__YDEBUG
  1403.  
  1404.     return TRUE;
  1405. }
  1406.  
  1407.  
  1408.  
  1409. CTexturePack::CTexturePack()
  1410. {
  1411.     m_dwNumber = 0;
  1412.     m_pTexture = NULL;
  1413.     m_ap2DTexture = NULL;
  1414. }
  1415. CTexturePack::~CTexturePack()
  1416. {
  1417.     DeleteDeviceObjects();
  1418. }
  1419. BOOL CTexturePack::DeleteDeviceObjects()
  1420. {
  1421.     SAFE_RELEASE( m_pTexture );
  1422.     SAFE_DELETE_ARRAY( m_ap2DTexture );
  1423.     return TRUE;
  1424. }
  1425. HRESULT CTexturePack::RestoreDeviceObjects(LPDIRECT3DDEVICE9 pd3dDevice)
  1426. {
  1427.     for( int i=0; i<(int)( m_dwNumber ); i++ )
  1428.         m_ap2DTexture[i].SetInvalidate( pd3dDevice );  
  1429.    
  1430.     return S_OK;
  1431. }
  1432. HRESULT CTexturePack::InvalidateDeviceObjects()
  1433. {
  1434.     for( int i=0; i<(int)( m_dwNumber ); i++ )
  1435.         m_ap2DTexture[i].Invalidate();
  1436.  
  1437.     return S_OK;
  1438. }
  1439.  
  1440. void CTexturePack::MakeVertex( C2DRender* p2DRender, CPoint point, int nIndex, TEXTUREVERTEX** ppVertices )
  1441. {
  1442.     CTexture* pTexture = GetAt( nIndex );
  1443.    
  1444.     point += p2DRender->m_ptOrigin;
  1445.     CPoint ptCenter = pTexture->m_ptCenter;
  1446.     //ptCenter.x *= fScaleX;
  1447.     //ptCenter.y *= fScaleY;
  1448.     point -= ptCenter;
  1449.    
  1450.     FLOAT left   = (FLOAT)( point.x );
  1451.     FLOAT top    = (FLOAT)( point.y );
  1452.     FLOAT right  = (FLOAT)( point.x + ( /*fScaleX **/ pTexture->m_size.cx ) );
  1453.     FLOAT bottom = (FLOAT)( point.y + ( /*fScaleY **/ pTexture->m_size.cy ) );
  1454.    
  1455.     SetTextureVertex( *ppVertices, left, top, pTexture->m_fuLT, pTexture->m_fvLT );
  1456.     (*ppVertices)++;
  1457.     SetTextureVertex( *ppVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT);
  1458.     (*ppVertices)++;
  1459.     SetTextureVertex( *ppVertices, (FLOAT)( point.x ), bottom, pTexture->m_fuLB, pTexture->m_fvLB);
  1460.     (*ppVertices)++;
  1461.    
  1462.     SetTextureVertex( *ppVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT);
  1463.     (*ppVertices)++;
  1464.     SetTextureVertex( *ppVertices, (FLOAT)( point.x ), bottom, pTexture->m_fuLB, pTexture->m_fvLB);
  1465.     (*ppVertices)++;
  1466.     SetTextureVertex( *ppVertices, right, bottom, pTexture->m_fuRB, pTexture->m_fvRB);
  1467.     (*ppVertices)++;
  1468. }
  1469. void CTexturePack::MakeVertex( C2DRender* p2DRender, CPoint point, int nIndex, TEXTUREVERTEX2** ppVertices, DWORD dwColor )
  1470. {
  1471.     CTexture* pTexture = GetAt( nIndex );
  1472.    
  1473.     point += p2DRender->m_ptOrigin;
  1474.     CPoint ptCenter = pTexture->m_ptCenter;
  1475.     //ptCenter.x *= fScaleX;
  1476.     //ptCenter.y *= fScaleY;
  1477.     point -= ptCenter;
  1478.    
  1479.     FLOAT left   = (FLOAT)( point.x );
  1480.     FLOAT top    = (FLOAT)( point.y );
  1481.     FLOAT right  = (FLOAT)( point.x + ( /*fScaleX **/ pTexture->m_size.cx ) );
  1482.     FLOAT bottom = (FLOAT)( point.y + ( /*fScaleY **/ pTexture->m_size.cy ) );
  1483.    
  1484.     SetTextureVertex2( *ppVertices, left, top, pTexture->m_fuLT, pTexture->m_fvLT, dwColor );
  1485.     (*ppVertices)++;
  1486.     SetTextureVertex2( *ppVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT, dwColor);
  1487.     (*ppVertices)++;
  1488.     SetTextureVertex2( *ppVertices, (FLOAT)( point.x ), bottom, pTexture->m_fuLB, pTexture->m_fvLB, dwColor );
  1489.     (*ppVertices)++;
  1490.    
  1491.     SetTextureVertex2( *ppVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT, dwColor );
  1492.     (*ppVertices)++;
  1493.     SetTextureVertex2( *ppVertices, (FLOAT)( point.x ), bottom, pTexture->m_fuLB, pTexture->m_fvLB, dwColor );
  1494.     (*ppVertices)++;
  1495.     SetTextureVertex2( *ppVertices, right, bottom, pTexture->m_fuRB, pTexture->m_fvRB, dwColor );
  1496.     (*ppVertices)++;
  1497. }
  1498. void CTexturePack::Render( LPDIRECT3DDEVICE9 pd3dDevice, TEXTUREVERTEX* pVertices, int nVertexNum )
  1499. {
  1500.     if( nVertexNum == 0 )
  1501.         return;
  1502.     pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
  1503.     pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
  1504.     pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );    
  1505.     pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );    
  1506.    
  1507.     pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
  1508.     pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
  1509.    
  1510.     pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
  1511.     pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  1512.     //pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE);
  1513.  
  1514.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  1515.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  1516.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR  );
  1517.  
  1518.     pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( 255, 0, 0, 0 ) );
  1519.    
  1520.     pd3dDevice->SetVertexShader( NULL );
  1521.     pd3dDevice->SetTexture( 0, m_pTexture );
  1522.     pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
  1523.     pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST, nVertexNum / 3, pVertices, sizeof( TEXTUREVERTEX ) );
  1524. }
  1525. void CTexturePack::Render( LPDIRECT3DDEVICE9 pd3dDevice, TEXTUREVERTEX2* pVertices, int nVertexNum )
  1526. {
  1527.     if( nVertexNum == 0 )
  1528.         return;
  1529.     pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
  1530.     pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
  1531.     pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );    
  1532.     pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );    
  1533.    
  1534.     pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
  1535.     pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
  1536.  
  1537.     pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
  1538.     pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  1539.     pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
  1540.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  1541.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  1542.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
  1543. /* 
  1544.     pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
  1545.     pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  1546.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE);
  1547.    
  1548.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
  1549.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  1550.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR  );
  1551.    
  1552.     pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( 255, 0, 0, 0 ) );
  1553. */ 
  1554.     pd3dDevice->SetVertexShader( NULL );
  1555.     pd3dDevice->SetTexture( 0, m_pTexture );
  1556.     pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX2 );
  1557.     pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST, nVertexNum / 3, pVertices, sizeof( TEXTUREVERTEX2 ) );
  1558. }
  1559. BOOL CTexturePack::LoadScript( LPDIRECT3DDEVICE9 pd3dDevice, LPCTSTR pszFileName )
  1560. {
  1561.     CScanner scanner;
  1562.     if( scanner.Load( pszFileName ) == FALSE )
  1563.     {
  1564.         Error( "%s not found", pszFileName );
  1565.         return FALSE;
  1566.     }
  1567.  
  1568.     DWORD dwCount = 0;
  1569.     CTexture* pTexture;
  1570.     BOOL bMultiLang = FALSE;
  1571.  
  1572.     do {
  1573.         scanner.GetToken();
  1574.         if(scanner.Token == "number")
  1575.         {  
  1576.             m_dwNumber = scanner.GetNumber();
  1577.             m_ap2DTexture = new CTexture[ m_dwNumber ];
  1578.         }
  1579.         else
  1580.         if( scanner.Token == "MULTI_LANGUAGE" )
  1581.         {
  1582.             bMultiLang = TRUE;
  1583.         }
  1584.         else
  1585.         if(scanner.Token == "texture")
  1586.         {  
  1587.             scanner.GetToken();
  1588.  
  1589.             TCHAR strFileName[MAX_PATH];
  1590.             strcpy(strFileName,scanner.token); 
  1591.             D3DCOLOR d3dKeyColor = scanner.GetHex();
  1592.             // ¿©±â¼­ ÅؽºÃç »ý¼º (Create the texture using D3DX)
  1593.             D3DXIMAGE_INFO imageInfo;
  1594.  
  1595.             if( bMultiLang )
  1596.             {
  1597.                 LoadTextureFromRes( pd3dDevice, MakePath( "Theme\\", ::GetLanguage(), strFileName ),
  1598.                                         D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, //D3DFMT_A4R4G4B4,
  1599.                                         D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR,
  1600.                                         D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR, d3dKeyColor, &imageInfo, NULL, &m_pTexture );
  1601.             }
  1602.             else
  1603.             {
  1604.                 LoadTextureFromRes( pd3dDevice, strFileName,
  1605.                     D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, //D3DFMT_A4R4G4B4,
  1606.                     D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR,
  1607.                     D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR, d3dKeyColor, &imageInfo, NULL, &m_pTexture );
  1608.             }
  1609.  
  1610.             m_size.cx = imageInfo.Width;
  1611.             m_size.cy = imageInfo.Height;
  1612.         }
  1613.         else
  1614.         if(scanner.Token == "data") // ÁÂÇ¥¿Í »çÀÌÁî
  1615.         {  
  1616.             if( dwCount >= m_dwNumber )
  1617.             {
  1618.             }
  1619.             pTexture = &m_ap2DTexture[ dwCount++ ];
  1620.             pTexture->m_size.cx = scanner.GetNumber(); 
  1621.             pTexture->m_size.cy = scanner.GetNumber(); 
  1622.             pTexture->m_fuLT = (FLOAT)scanner.GetNumber() / m_size.cx;
  1623.             pTexture->m_fvLT = (FLOAT)scanner.GetNumber() / m_size.cy;
  1624.             pTexture->m_fuRT = (FLOAT)scanner.GetNumber() / m_size.cx;
  1625.             pTexture->m_fvRT = (FLOAT)scanner.GetNumber() / m_size.cy;
  1626.             pTexture->m_fuLB = (FLOAT)scanner.GetNumber() / m_size.cx;
  1627.             pTexture->m_fvLB = (FLOAT)scanner.GetNumber() / m_size.cy;
  1628.             pTexture->m_fuRB = (FLOAT)scanner.GetNumber() / m_size.cx;
  1629.             pTexture->m_fvRB = (FLOAT)scanner.GetNumber() / m_size.cy;
  1630.             pTexture->m_pTexture = m_pTexture;
  1631.         }
  1632.         else
  1633.         if( scanner.Token == "pos" ) // ÁÂÇ¥
  1634.         {  
  1635.             if( dwCount >= m_dwNumber )
  1636.             {
  1637.             }
  1638.             pTexture = &m_ap2DTexture[ dwCount++ ];
  1639.             pTexture->m_size.cx = scanner.GetNumber(); 
  1640.             pTexture->m_size.cy = scanner.GetNumber(); 
  1641.             int x = scanner.GetNumber();
  1642.             int y = scanner.GetNumber();
  1643.             scanner.GetToken();
  1644.             if( scanner.Token == "h" )
  1645.             {
  1646.                 pTexture->m_fuRT = (FLOAT) x / m_size.cx;
  1647.                 pTexture->m_fvRT = (FLOAT) y / m_size.cy;
  1648.                 pTexture->m_fuLT = (FLOAT) ( (FLOAT)x + pTexture->m_size.cx - 0 ) / (FLOAT)m_size.cx;
  1649.                 pTexture->m_fvLT = (FLOAT) y / m_size.cy;
  1650.                 pTexture->m_fuRB = (FLOAT) x / m_size.cx;
  1651.                 pTexture->m_fvRB = (FLOAT) ( (FLOAT)y + pTexture->m_size.cy - 0 ) / (FLOAT)m_size.cy;
  1652.                 pTexture->m_fuLB = (FLOAT) ( (FLOAT)x + pTexture->m_size.cx - 0 ) / (FLOAT)m_size.cx;
  1653.                 pTexture->m_fvLB = (FLOAT) ( (FLOAT)y + pTexture->m_size.cy - 0 ) / (FLOAT)m_size.cy;
  1654.             }
  1655.             else
  1656.             if( scanner.Token == "v" )
  1657.             {
  1658.                 pTexture->m_fuLB = (FLOAT) x / m_size.cx;
  1659.                 pTexture->m_fvLB = (FLOAT) y / m_size.cy;
  1660.                 pTexture->m_fuRB = (FLOAT) ( (FLOAT)x + pTexture->m_size.cx - 0 ) / (FLOAT)m_size.cx;
  1661.                 pTexture->m_fvRB = (FLOAT) y / m_size.cy;
  1662.                 pTexture->m_fuLT = (FLOAT) x / m_size.cx;
  1663.                 pTexture->m_fvLT = (FLOAT) ( (FLOAT)y + pTexture->m_size.cy - 0 ) / (FLOAT)m_size.cy;
  1664.                 pTexture->m_fuRT = (FLOAT) ( (FLOAT)x + pTexture->m_size.cx - 0 ) / (FLOAT)m_size.cx;
  1665.                 pTexture->m_fvRT = (FLOAT) ( (FLOAT)y + pTexture->m_size.cy - 0 ) / (FLOAT)m_size.cy;
  1666.             }
  1667.             else
  1668.             if( scanner.Token == "hv" )
  1669.             {
  1670.                 pTexture->m_fuRB = (FLOAT) x / m_size.cx;
  1671.                 pTexture->m_fvRB = (FLOAT) y / m_size.cy;
  1672.                 pTexture->m_fuLB = (FLOAT) ( (FLOAT)x + pTexture->m_size.cx - 0 ) / (FLOAT)m_size.cx;
  1673.                 pTexture->m_fvLB = (FLOAT) y / m_size.cy;
  1674.                 pTexture->m_fuRT = (FLOAT) x / m_size.cx;
  1675.                 pTexture->m_fvRT = (FLOAT) ( (FLOAT)y + pTexture->m_size.cy - 0 ) / (FLOAT)m_size.cy;
  1676.                 pTexture->m_fuLT = (FLOAT) ( (FLOAT)x + pTexture->m_size.cx - 0 ) / (FLOAT)m_size.cx;
  1677.                 pTexture->m_fvLT = (FLOAT) ( (FLOAT)y + pTexture->m_size.cy - 0 ) / (FLOAT)m_size.cy;
  1678.             }
  1679.             else
  1680.             {
  1681.                 pTexture->m_fuLT = (FLOAT) x / m_size.cx;
  1682.                 pTexture->m_fvLT = (FLOAT) y / m_size.cy;
  1683.                 pTexture->m_fuRT = (FLOAT) ( (FLOAT)x + pTexture->m_size.cx - 0 ) / (FLOAT)m_size.cx;
  1684.                 pTexture->m_fvRT = (FLOAT) y / m_size.cy;
  1685.                 pTexture->m_fuLB = (FLOAT) x / m_size.cx;
  1686.                 pTexture->m_fvLB = (FLOAT) ( (FLOAT)y + pTexture->m_size.cy - 0 ) / (FLOAT)m_size.cy;
  1687.                 pTexture->m_fuRB = (FLOAT) ( (FLOAT)x + pTexture->m_size.cx - 0 ) / (FLOAT)m_size.cx;
  1688.                 pTexture->m_fvRB = (FLOAT) ( (FLOAT)y + pTexture->m_size.cy - 0 ) / (FLOAT)m_size.cy;
  1689.             }
  1690.             pTexture->m_pTexture = m_pTexture;
  1691.         }
  1692.         else
  1693.         if(scanner.Token == "datauv") // uv »óÅ·ΠÀÔ·Â
  1694.         {  
  1695.             if( dwCount >= m_dwNumber )
  1696.             {  
  1697.             }
  1698.             pTexture = &m_ap2DTexture[ dwCount++ ];
  1699.             pTexture->m_size.cx = scanner.GetNumber(); 
  1700.             pTexture->m_size.cy = scanner.GetNumber(); 
  1701.             pTexture->m_fuLT = scanner.GetFloat();
  1702.             pTexture->m_fvLT = scanner.GetFloat();
  1703.             pTexture->m_fuRT = scanner.GetFloat();
  1704.             pTexture->m_fvRT = scanner.GetFloat();
  1705.             pTexture->m_fuLB = scanner.GetFloat();
  1706.             pTexture->m_fvLB = scanner.GetFloat();
  1707.             pTexture->m_fuRB = scanner.GetFloat();
  1708.             pTexture->m_fvRB = scanner.GetFloat();
  1709.             pTexture->m_pTexture = m_pTexture;
  1710.         }
  1711.         else
  1712.         if(scanner.Token == "serialize")
  1713.         {  
  1714.             if( dwCount >= m_dwNumber )
  1715.             {
  1716.                 Error( "%s ¿¡·¯, ÇÒ´ç :%d, ½ÇÁ¦°¹¼ö : %d", pszFileName, m_dwNumber, dwCount );
  1717.                 return FALSE;
  1718.             }
  1719.             int nCnt = 0;
  1720.             int nFrame = scanner.GetNumber();  
  1721.             SIZE size;
  1722.             size.cx = scanner.GetNumber(); 
  1723.             size.cy = scanner.GetNumber(); 
  1724.             POINT start;
  1725.             start.x = scanner.GetNumber(); 
  1726.             start.y = scanner.GetNumber(); 
  1727.             POINT center;
  1728.             center.x = scanner.GetNumber();
  1729.             center.y = scanner.GetNumber();
  1730.            
  1731.             for( int i = start.y; i < m_size.cy; i += size.cy )
  1732.             {
  1733.                 for( int j = start.x; j < m_size.cx; j += size.cx, nCnt++ )
  1734.                 {
  1735.                     if( nCnt < nFrame )
  1736.                     {
  1737.                        
  1738.                         if( dwCount >= m_dwNumber )
  1739.                         {
  1740.                             Error( "%s ¿¡·¯, ÇÒ´ç :%d, ½ÇÁ¦°¹¼ö : %d", pszFileName, m_dwNumber, dwCount );
  1741.                             return FALSE;
  1742.                         }
  1743.                        
  1744.                         pTexture = &m_ap2DTexture[ dwCount ];
  1745.                         dwCount++;
  1746.  
  1747.                         pTexture->m_size = size;   
  1748.                         pTexture->m_ptCenter = center;
  1749.                         int x = j;
  1750.                         int y = i;
  1751.                         pTexture->m_fuLT = (FLOAT) x / m_size.cx;
  1752.                         pTexture->m_fvLT = (FLOAT) y / m_size.cy;
  1753.                         pTexture->m_fuRT = (FLOAT) ( (FLOAT)x + pTexture->m_size.cx - 0 ) / (FLOAT)m_size.cx;
  1754.                         pTexture->m_fvRT = (FLOAT) y / m_size.cy;
  1755.                         pTexture->m_fuLB = (FLOAT) x / m_size.cx;
  1756.                         pTexture->m_fvLB = (FLOAT) ( (FLOAT)y + pTexture->m_size.cy - 0 ) / (FLOAT)m_size.cy;
  1757.                         pTexture->m_fuRB = (FLOAT) ( (FLOAT)x + pTexture->m_size.cx - 0 ) / (FLOAT)m_size.cx;
  1758.                         pTexture->m_fvRB = (FLOAT) ( (FLOAT)y + pTexture->m_size.cy - 0 ) / (FLOAT)m_size.cy;
  1759.                         pTexture->m_pTexture = m_pTexture;
  1760.                     }
  1761.                 }
  1762.             }
  1763.         }
  1764.     } while(scanner.tok!=FINISHED);
  1765.     return TRUE;
  1766. }
  1767.  
  1768. CTextureMng::CTextureMng()
  1769. {
  1770. }
  1771. CTextureMng::~CTextureMng()
  1772. {
  1773.     DeleteDeviceObjects();
  1774. }
  1775.  
  1776.  
  1777.  
  1778. BOOL CTextureMng::SetInvalidate(LPDIRECT3DDEVICE9 pd3dDevice)
  1779. {
  1780.     for( MapTexItor i = m_mapTexture.begin(); i != m_mapTexture.end(); ++i )
  1781.         ((*i).second)->SetInvalidate(pd3dDevice);
  1782.  
  1783.     return TRUE;
  1784. }
  1785.  
  1786.  
  1787. void CTextureMng::Invalidate()
  1788. {
  1789.     for( MapTexItor i = m_mapTexture.begin(); i != m_mapTexture.end(); ++i )
  1790.         ((*i).second)->Invalidate();
  1791. }
  1792.  
  1793. BOOL CTextureMng::DeleteDeviceObjects()
  1794. {
  1795.  
  1796. #ifdef __VS2003
  1797.     if(m_mapTexture.size() <= 0) return TRUE;
  1798. #endif
  1799.  
  1800.     for( MapTexItor i = m_mapTexture.begin(); i != m_mapTexture.end(); ++i )
  1801.         SAFE_DELETE( (*i).second );
  1802.     m_mapTexture.clear();
  1803.     return TRUE;
  1804. }
  1805. BOOL CTextureMng::RemoveTexture( LPCTSTR pKey )
  1806. {
  1807.     MapTexItor mapTexItor = m_mapTexture.find( pKey );
  1808.     if( mapTexItor != m_mapTexture.end() )
  1809.     {
  1810.         SAFE_DELETE( (*mapTexItor).second );
  1811.         m_mapTexture.erase( pKey );
  1812.     }
  1813.     return TRUE;
  1814. }
  1815. CTexture* CTextureMng::AddTexture( LPDIRECT3DDEVICE9 pd3dDevice, LPCTSTR pFileName, D3DCOLOR d3dKeyColor, BOOL bMyLoader )
  1816. {
  1817.     CTexture* pTexture = NULL;
  1818.     MapTexItor mapTexItor;
  1819.  
  1820.      mapTexItor = m_mapTexture.find( pFileName );
  1821.      if( mapTexItor != m_mapTexture.end() )
  1822.         return (*mapTexItor).second;
  1823.     pTexture = new CTexture;
  1824.     if( pTexture->LoadTexture( pd3dDevice, pFileName, d3dKeyColor, bMyLoader ) )
  1825.     {
  1826.         m_mapTexture.insert( MapTexType( pFileName, pTexture ) );
  1827.         return pTexture;
  1828.     }
  1829.     safe_delete( pTexture );
  1830.     return NULL;
  1831. }
  1832. CTexture* CTextureMng::AddTexture( LPDIRECT3DDEVICE9 pd3dDevice, LPCTSTR pKey, CTexture* pTexture )
  1833. {
  1834.     MapTexItor mapTexItor;
  1835.     mapTexItor = m_mapTexture.find( pKey );
  1836.     if( mapTexItor != m_mapTexture.end() )
  1837.         return (*mapTexItor).second;
  1838.     m_mapTexture.insert( MapTexType( pKey, pTexture ) );
  1839.     return pTexture;
  1840. }
  1841. CTexture* CTextureMng::GetAt( LPCTSTR pFileName )
  1842. {
  1843.     MapTexItor mapTexItor = m_mapTexture.find( pFileName );
  1844.     if( mapTexItor != m_mapTexture.end() )
  1845.         return (CTexture*)(*mapTexItor).second;
  1846.     return NULL;
  1847. }
  1848.  
  1849.  
  1850. #ifdef __CLIENT
  1851. #ifndef __VM_0820
  1852. MemPooler<CDamageNum>*  CDamageNum::m_pPool = new MemPooler<CDamageNum>( 32 );
  1853. #endif  // __VM_0820
  1854.  
  1855. void CDamageNum::Process()
  1856. {
  1857.     switch( m_nState )
  1858.     {
  1859.     case 0: // init
  1860.         {
  1861.         D3DXVECTOR3 vTemp;
  1862.         g_DamageNumMng.m_viewport.X = 0;
  1863.         g_DamageNumMng.m_viewport.Y = 0;
  1864.         D3DXVec3Project( &vTemp, &(m_vPos + D3DXVECTOR3(0, 1.0f, 0)), &g_DamageNumMng.m_viewport, &g_DamageNumMng.m_matProj, &g_DamageNumMng.m_matView, &g_DamageNumMng.m_matWorld );
  1865.         m_fY = vTemp.y;
  1866.         m_fDy = 10.0f;
  1867.         m_nState ++;
  1868.         }
  1869.         break;
  1870.     case 1: // ¿Ã¶ó°¡´ÂÁß.
  1871. //      m_fDy -= 2.0f;
  1872.         if( m_nCnt >= 8 )
  1873.         {
  1874.             m_nState ++;
  1875.             m_nCnt = 0;
  1876.             m_fDy = 0;
  1877.         }
  1878.         break;
  1879.     case 2: // Áøµ¿
  1880.         if( g_nRenderCnt & 1 )
  1881.             m_fDy = -3.0f;
  1882.         else
  1883.             m_fDy = 3.0f;
  1884.  
  1885.         if( m_nCnt >= 10 )
  1886.         {
  1887.             m_nState ++;
  1888.             m_fDy = 0;
  1889.             m_nCnt = 0;
  1890.         }
  1891.         break;
  1892.     case 3: // ´ë±â
  1893.         if( m_nCnt >= 15 )
  1894.         {
  1895.             m_nCnt = 0;
  1896.             m_fDy = 2.0f;
  1897.             m_nState ++;
  1898.         }
  1899.         break;
  1900.     case 4: // »ç¶óÁö±â
  1901.         break;
  1902.  
  1903.        
  1904.     }
  1905.  
  1906.     m_fY -= m_fDy;
  1907.     m_nCnt ++;
  1908.    
  1909.     m_nFrame ++;
  1910. }
  1911.  
  1912. //static float s_fY[35] = { 30, 25, 20, 15, 10,  20, 20, 20, 20, 20,  20, 20, 20, 20, 20,  20, 20, 20, 20, 20,  
  1913. //                       -20, 20, -8, 8, -6,  6, -4, 4, -2, 2,  0, 0, 0, 0, 0 };
  1914.  
  1915. void CDamageNum::Render(CTexturePack *textPackNum)
  1916. {
  1917.    
  1918.     FLOAT fX,fY;
  1919.     D3DXVECTOR3 vTemp;
  1920.     // 3d ÁÂÇ¥¸¦ È­¸é»óÀÇ ÁÂÇ¥·Î º¯È¯ÇÑ´Ù
  1921.     D3DXVec3TransformCoord( &vTemp, &m_vPos, &g_DamageNumMng.m_matView );
  1922.     if( vTemp.z < 0 )   return;
  1923.     g_DamageNumMng.m_viewport.X = 0;
  1924.     g_DamageNumMng.m_viewport.Y = 0;
  1925.     D3DXVec3Project( &vTemp, &(m_vPos + D3DXVECTOR3(0, 1.0f, 0)), &g_DamageNumMng.m_viewport, &g_DamageNumMng.m_matProj, &g_DamageNumMng.m_matView, &g_DamageNumMng.m_matWorld );
  1926.     // ÇöÀç ¾Ö´Ï¸ÞÀÌ¼Ç ÁøÇà »óȲ¿¡ ¸ÂÃß¾î À§Ä¡, Å©±â, opacity µîÀ» ¼³Á¤ÇÑ´Ù.
  1927.     fX = vTemp.x;
  1928. //  if( m_nFrame == 1 )
  1929. //      m_fY = vTemp.y;
  1930. //  fY = vTemp.y - m_nFrame * 3;`
  1931. //  if( m_nFrame < 35 )
  1932. //      m_fY -= s_fY[ m_nFrame ];
  1933.  
  1934.     fY = m_fY;
  1935. //  FLOAT fScaleX = ( m_nFrame < 4 ) ? 30.5f - ( 29.0f / 10.0f ) * m_nFrame : 1.5f + ( 1.0f / 100.0f ) * ( m_nFrame - 10 );
  1936. //  FLOAT fScaleY = ( m_nFrame < 4 ) ? 0.1f + ( 0.3f / 10.0f ) * m_nFrame : 1.5f + ( 1.0f / 100.0f ) * ( m_nFrame - 10 );
  1937.     FLOAT fScaleX = 2.0f;
  1938.     FLOAT fScaleY = 2.0f;
  1939.     int nAlpha = 255;
  1940.     if( m_nState == 4 )
  1941.     {
  1942.         fScaleX = fScaleY = 3.0f + (m_nCnt * 0.05f);
  1943.         nAlpha = 75 - (m_nCnt * 2);
  1944.         if( nAlpha < 0 )    nAlpha = 0;
  1945.     }
  1946. //  if( m_nFrame < 40 )     nAlpha = 255;
  1947. //  else nAlpha = 255 - ( 255.0f / 80 ) * ( m_nFrame - 40 );
  1948.    
  1949.     fScaleX /= 4;
  1950.     fScaleY /= 4;
  1951.  
  1952.     // ¼Ó¼º°ª¿¡ µû¶ó Ãâ·ÂÇÏ´Â ³»¿ëÀ» ¹Ù²Û´Ù.
  1953.     if( m_nAttribute < 4 ) { // ¼ýÀÚÀÎ °æ¿ì
  1954.         // ÇÑÀÚ¸®¾¿ Â÷·Ê´ë·Î Ãâ·ÂÇÑ´Ù
  1955.         char strTemp[64];
  1956.         sprintf( strTemp, "%d", m_nNumber );
  1957.         int nLength = strlen(strTemp);
  1958.         fX -= fScaleX * textPackNum->m_ap2DTexture[0].m_size.cx * (1.0f+0.5f*(nLength-1)) / 2.0f;
  1959.         for( int i = 0; i < nLength; i++ )
  1960.         {
  1961.             DWORD nIndex = strTemp[i] - '0' + m_nAttribute * 14;
  1962.             if( (int)nIndex >= 0 )  // ¿¡·¯¹æÁö.
  1963.             {
  1964.                 textPackNum->Render( &g_Neuz.m_2DRender, CPoint( (int)( fX ), (int)( fY ) ), nIndex ,(DWORD)nAlpha,fScaleX,fScaleY);
  1965.             }
  1966.             else
  1967.             {
  1968.                 LPCTSTR szErr = Error( "DamageNum::Render : %s %d", strTemp, m_nAttribute );
  1969.                 ADDERRORMSG( szErr );
  1970.             }
  1971.            
  1972.             fX  = (FLOAT)( fX + (textPackNum->m_ap2DTexture[nIndex].m_size.cx*0.5*fScaleX) );
  1973.         }
  1974.     }
  1975.     else
  1976.     if( m_nAttribute == 4 ) // missÀÎ °æ¿ì
  1977.     {
  1978.         fX  = (FLOAT)( fX - (textPackNum->m_ap2DTexture[10].m_size.cx*0.5/2*fScaleX) );
  1979.         textPackNum->Render( &g_Neuz.m_2DRender, CPoint( (int)( fX ), (int)( fY ) ), 10 ,nAlpha,fScaleX,fScaleY);
  1980.     }
  1981.     else
  1982.     if( m_nAttribute == 5 ) // goodÀÎ °æ¿ì
  1983.     {
  1984.         fX  = (FLOAT)( fX - (textPackNum->m_ap2DTexture[11].m_size.cx*0.5/2*fScaleX) );
  1985.         textPackNum->Render( &g_Neuz.m_2DRender, CPoint( (int)( fX ), (int)( fY ) ), 11 ,nAlpha,fScaleX,fScaleY);
  1986.     }
  1987.     else
  1988.     if( m_nAttribute == 6 ) // niceÀÎ °æ¿ì
  1989.     {
  1990.         fX  = (FLOAT)( fX - (textPackNum->m_ap2DTexture[12].m_size.cx*0.5/2*fScaleX) );
  1991.         textPackNum->Render( &g_Neuz.m_2DRender, CPoint( (int)( fX ), (int)( fY ) ), 12 ,nAlpha,fScaleX,fScaleY);
  1992.     }
  1993.     else
  1994.     if( m_nAttribute == 7 ) // yeah~ÀÎ °æ¿ì
  1995.     {
  1996.         fX  = (FLOAT)( fX - (textPackNum->m_ap2DTexture[13].m_size.cx*0.5/2*fScaleX) );
  1997.         textPackNum->Render( &g_Neuz.m_2DRender, CPoint( (int)( fX ), (int)( fY ) ), 13 ,nAlpha,fScaleX,fScaleY);
  1998.     }
  1999.  
  2000.     m_nFrame++;
  2001.    
  2002. }
  2003.  
  2004. void CDamageNumMng::LoadTexture(LPDIRECT3DDEVICE9 pd3dDevice)
  2005. {
  2006.     m_textPackNum.LoadScript( pd3dDevice, MakePath( DIR_SFX, _T( "DmgEffect.inc" ) ) );
  2007. }
  2008.  
  2009. CDamageNumMng::~CDamageNumMng()
  2010. {
  2011.     DeleteDeviceObjects();
  2012. }
  2013. BOOL CDamageNumMng::DeleteDeviceObjects()
  2014. {
  2015.     CDamageNum* pDamagenum;
  2016.     for(int i=0;i<m_Array.GetSize();i++)
  2017.     {
  2018.         pDamagenum=(CDamageNum*)m_Array.GetAt(i);
  2019.         safe_delete( pDamagenum );
  2020.     }
  2021.     m_Array.RemoveAll();
  2022.     m_textPackNum.DeleteDeviceObjects();
  2023.     return TRUE;
  2024. }
  2025. void CDamageNumMng::AddNumber(D3DXVECTOR3 vPos,DWORD nNumber,DWORD nAttribute)
  2026. {
  2027.     CDamageNum* pDamagenum=new CDamageNum(vPos,nNumber,nAttribute);
  2028.     m_Array.Add(pDamagenum);
  2029. }
  2030.  
  2031. HRESULT CDamageNumMng::RestoreDeviceObjects()
  2032. {
  2033.     m_textPackNum.RestoreDeviceObjects(g_Neuz.m_pd3dDevice);
  2034.     return S_OK;
  2035. }
  2036. HRESULT CDamageNumMng::InvalidateDeviceObjects()
  2037. {
  2038.     m_textPackNum.InvalidateDeviceObjects();
  2039.     return S_OK;
  2040. }
  2041.  
  2042. void CDamageNumMng::Process()
  2043. {
  2044.     CDamageNum* pDamagenum;
  2045.  
  2046.     for(int i=0;i<m_Array.GetSize();i++)
  2047.     {
  2048.         pDamagenum=(CDamageNum*)m_Array.GetAt(i);
  2049.         if(pDamagenum->m_nFrame>=100)
  2050.         {
  2051.             safe_delete( pDamagenum );
  2052.             m_Array.RemoveAt(i);
  2053.             i--;
  2054.         }
  2055.         else
  2056.         {
  2057.             pDamagenum->Process();
  2058.         }
  2059.     }
  2060. }
  2061. void CDamageNumMng::Render()
  2062. {
  2063.     CDamageNum* pDamagenum;
  2064.  
  2065.     for(int i=0;i<m_Array.GetSize();i++)
  2066.     {
  2067.         pDamagenum=(CDamageNum*)m_Array.GetAt(i);
  2068.         pDamagenum->Render(&m_textPackNum);
  2069.     }
  2070. }
  2071. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement