DavidNorgren

Untitled

Jul 10th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <d3dx9.h>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. // include the Direct3D Library files
  9. #pragma comment (lib, "d3d9.lib")
  10. #pragma comment (lib, "d3dx9.lib")
  11.  
  12. #define GMEXPORT extern "C" __declspec (dllexport)
  13.  
  14. LPDIRECT3D9 d3d;
  15. LPDIRECT3DDEVICE9 d3ddev;
  16. LPDIRECT3DTEXTURE9 textures[1024];
  17. int textureCount = 0;
  18.  
  19. wstring towstr(const string str) {
  20.     wstring buffer;
  21.     buffer.resize(MultiByteToWideChar(CP_UTF8, 0, &str[0], -1, 0, 0));
  22.     MultiByteToWideChar(CP_UTF8, 0, &str[0], -1, &buffer[0], buffer.size());
  23.     return &buffer[0];
  24. }
  25.  
  26. BOOL WINAPI DllMain( HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved) {
  27.     return TRUE;
  28. }
  29.  
  30. GMEXPORT double init( long POINTER ){
  31.     d3ddev = (LPDIRECT3DDEVICE9)POINTER;
  32.     return 0.0;
  33. }
  34.  
  35. GMEXPORT double GenerateMipMaps( long POINTER ) {
  36.  
  37.     // Fetch D3D device
  38.     d3ddev = (LPDIRECT3DDEVICE9)POINTER;
  39.  
  40.     // Get active texture
  41.     LPDIRECT3DBASETEXTURE9 texture;
  42.     d3ddev->GetTexture( 0, &texture );
  43.  
  44.     std::cout << "D3DTF: Generating Mip maps for texture: " << texture << std::endl;
  45.     std::cout << "  Level count (Before): " << texture->GetLevelCount() << std::endl;
  46.  
  47.     // Generate mip levels:
  48.     texture->SetAutoGenFilterType( D3DTEXF_ANISOTROPIC );
  49.     texture->GenerateMipSubLevels();
  50.  
  51.     std::cout << "  Level count (After): " << texture->GetLevelCount() << std::endl;
  52.  
  53.     return 0.0;
  54. }
  55.  
  56. GMEXPORT double texture_create(char *filename) {
  57.     wstring wpath = towstr(filename);
  58.  
  59.     //// ITS TWO LINES MIKE DAILLY.. TWO LINES //////////////////////////
  60.     LPDIRECT3DTEXTURE9 texture;
  61.     D3DXCreateTextureFromFileW( d3ddev, &wpath[0], &texture );
  62.     ////////////////////////////////////////////////////////////////////
  63.  
  64.     // store in internal array
  65.     textureCount ++;
  66.     textures[textureCount] = texture;
  67.  
  68.     return textureCount;
  69. }
  70.  
  71. GMEXPORT double texture_free(double textureIndex) {
  72.     textures[(int)textureIndex]->Release();
  73.     return 0.0;
  74. }
  75.  
  76. GMEXPORT double texture_set_stage_ext( double textureIndex, double stage ) {
  77.     if( stage >= 0 && textureIndex > 0 )
  78.         d3ddev->SetTexture( (int)stage, textures[(int)textureIndex] );
  79.     return 0.0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment