Advertisement
Guest User

QTS no. 14 - Create texture from resource

a guest
Aug 17th, 2010
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. /*
  2. -----------------------------------------
  3. * Game hacking QTS ( Quickie Tip Series )
  4. * no. 14 - Create texture from resource
  5. -----------------------------------------
  6. * Author: SEGnosis  - GHAnon.net
  7. * Thanks to:
  8. * bitterbanana      - No known site
  9. * Drunken Cheetah   - No known site
  10. * fatboy88      - No known site
  11. * Geek4Ever         - No known site
  12. * learn_more        - www.uc-forum.com
  13. * Novocaine         - http://ilsken.net/blog/?page_id=64
  14. * Philly0494        - No known site
  15. * Roverturbo        - www.uc-forum.com
  16. * SilentKarma       - www.halocoders.com - offline
  17. * Strife        - www.uc-forum.com
  18. * Wieter20      - No known site
  19. */
  20.  
  21. //----------------------------------//
  22. // resource.h
  23. #ifndef IDC_STATIC
  24. #define IDC_STATIC (-1)
  25. #endif
  26.  
  27. #define ID_PNG_BASE                             107 // ID for png custom resource
  28.  
  29.  
  30.  
  31. // Res.rc
  32. #include <windows.h>
  33. #include <commctrl.h>
  34. #include <richedit.h>
  35. #include "resource.h"
  36.  
  37. ID_PNG_BASE        ID_PNG         ".\\MyTexture.png" // reletive
  38.  
  39.  
  40.  
  41. // dll main
  42. HMODULE g_hModule;
  43.  
  44. BOOL WINAPI DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpvReserved )
  45. {
  46.     switch( dwReason )
  47.     {
  48.         case DLL_THREAD_ATTACH:
  49.             break;
  50.  
  51.         case DLL_PROCESS_ATTACH:
  52.                 g_hModule = hModule;
  53.             break;
  54.            
  55.         case DLL_THREAD_DETACH:
  56.             break;
  57.  
  58.         case DLL_PROCESS_DETACH:
  59.             break;
  60.     }
  61.    
  62.     return TRUE;
  63. }
  64.  
  65.  
  66.  
  67. // function
  68. void LoadCustomTextureFromResource( LPDIRECT3DTEXTURE9& m_Texture, char* szType, LPSTR szResource )
  69. {
  70.     HRSRC   hRes        = FindResource( g_hModule, szResource, szType );
  71.     HGLOBAL hResource   = LoadResource( g_hModule, hRes );
  72.     DWORD   iResSize        = SizeofResource( g_hModule, hRes );
  73.    
  74.     BYTE* pData = ( BYTE* )LockResource( hResource );
  75.     D3DXCreateTextureFromFileInMemory( m_pDevice, pData,  iResSize,  &m_Texture );
  76.        
  77.     FreeResource( hResource );
  78. }
  79.  
  80.  
  81.  
  82. // How to use
  83. LPDIRECT3DTEXTURE9  g_TexBackground;
  84.  
  85. LoadCustomTextureFromResource( g_TexBackground, "ID_PNG", MAKEINTRESOURCE( ID_PNG_BASE ) );
  86. //----------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement