Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <d3dx9.h>
- #include <string>
- using namespace std;
- // include the Direct3D Library files
- #pragma comment (lib, "d3d9.lib")
- #pragma comment (lib, "d3dx9.lib")
- #define GMEXPORT extern "C" __declspec (dllexport)
- LPDIRECT3D9 d3d;
- LPDIRECT3DDEVICE9 d3ddev;
- LPDIRECT3DTEXTURE9 textures[1024];
- int textureCount = 0;
- wstring towstr(const string str) {
- wstring buffer;
- buffer.resize(MultiByteToWideChar(CP_UTF8, 0, &str[0], -1, 0, 0));
- MultiByteToWideChar(CP_UTF8, 0, &str[0], -1, &buffer[0], buffer.size());
- return &buffer[0];
- }
- BOOL WINAPI DllMain( HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved) {
- return TRUE;
- }
- GMEXPORT double init( long POINTER ){
- d3ddev = (LPDIRECT3DDEVICE9)POINTER;
- return 0.0;
- }
- GMEXPORT double GenerateMipMaps( long POINTER ) {
- // Fetch D3D device
- d3ddev = (LPDIRECT3DDEVICE9)POINTER;
- // Get active texture
- LPDIRECT3DBASETEXTURE9 texture;
- d3ddev->GetTexture( 0, &texture );
- std::cout << "D3DTF: Generating Mip maps for texture: " << texture << std::endl;
- std::cout << " Level count (Before): " << texture->GetLevelCount() << std::endl;
- // Generate mip levels:
- texture->SetAutoGenFilterType( D3DTEXF_ANISOTROPIC );
- texture->GenerateMipSubLevels();
- std::cout << " Level count (After): " << texture->GetLevelCount() << std::endl;
- return 0.0;
- }
- GMEXPORT double texture_create(char *filename) {
- wstring wpath = towstr(filename);
- //// ITS TWO LINES MIKE DAILLY.. TWO LINES //////////////////////////
- LPDIRECT3DTEXTURE9 texture;
- D3DXCreateTextureFromFileW( d3ddev, &wpath[0], &texture );
- ////////////////////////////////////////////////////////////////////
- // store in internal array
- textureCount ++;
- textures[textureCount] = texture;
- return textureCount;
- }
- GMEXPORT double texture_free(double textureIndex) {
- textures[(int)textureIndex]->Release();
- return 0.0;
- }
- GMEXPORT double texture_set_stage_ext( double textureIndex, double stage ) {
- if( stage >= 0 && textureIndex > 0 )
- d3ddev->SetTexture( (int)stage, textures[(int)textureIndex] );
- return 0.0;
- }
Advertisement
Add Comment
Please, Sign In to add comment