Beispiel #1
0
bool Texture::LoadFromFile(const string & file) {
	D3DXIMAGE_INFO imgInfo;

	int slashPos = file.find_last_of('/');
	int dotPos = file.find_last_of('.');
	string ext = file.substr(dotPos + 1, file.size() - dotPos);
	string name = file.substr(slashPos + 1, dotPos - slashPos - 1);

	// cache lookup
	string cacheFileName = "./cache/" + name + ".dds";
	FILE * pFile = fopen(cacheFileName.c_str(), "r");
	bool genericTex = file.find("textures/generic") != string::npos;
	if(pFile && genericTex) {
		fclose(pFile);
		if(FAILED(D3DXCreateTextureFromFileExA(pD3D, cacheFileName.c_str(), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_FROM_FILE, 0, D3DFMT_FROM_FILE, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, &imgInfo, NULL, &mTexture))) {
			Log::Write(StringBuilder("WARNING: Unable to load ") << file << " texture!");
			return false;
		} else {
			Log::Write(StringBuilder("Texture successfully loaded from DDS cache: ") << cacheFileName);
		}
	} else {
		if(FAILED(D3DXCreateTextureFromFileExA(pD3D, file.c_str(), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, &imgInfo, 0, &mTexture))) {
			Log::Write(StringBuilder("WARNING: Unable to load ") << file << " texture!");
			return false;
		} else {
			Log::Write(StringBuilder("Texture successfully loaded: ") << file);
		}
	}
	mWidth = imgInfo.Width;
	mHeight = imgInfo.Height;
	mColorDepth = 32;
	return true;
}
Beispiel #2
0
bool RenderChain::add_lut(const std::string &id,
      const std::string &path,
      bool smooth)
{
   LPDIRECT3DTEXTURE lut;

   RARCH_LOG("[D3D]: Loading LUT texture: %s.\n", path.c_str());

   if (FAILED(D3DXCreateTextureFromFileExA(
               dev,
               path.c_str(),
               D3DX_DEFAULT_NONPOW2,
               D3DX_DEFAULT_NONPOW2,
               0,
               0,
               D3DFMT_FROM_FILE,
               D3DPOOL_MANAGED,
               smooth ? D3DX_FILTER_LINEAR : D3DX_FILTER_POINT,
               0,
               0,
               NULL,
               NULL,
               &lut)))
      return false;

   dev->SetTexture(0, lut);
   dev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
   dev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
   dev->SetTexture(0, NULL);

   lut_info info = { lut, id, smooth };
   luts.push_back(info);
   return true;
}
Beispiel #3
0
	void SPTexture::Load( 
		LPDIRECT3DDEVICE9 pDevice,
		LPCSTR		pSrcFile,
		UINT		setWidth,
		UINT		setHeight,
		UINT		MipLevels,
		DWORD		Usage,
		D3DFORMAT	Format,
		D3DPOOL		Pool, 
		DWORD		Filter,
		DWORD		MipFilter,
		D3DCOLOR	ColorKey )
	{
		SPGameManager::GetSingleton()->GetGame()->LockDrawing();

		D3DXIMAGE_INFO i;
		D3DXCreateTextureFromFileExA(pDevice, pSrcFile, setWidth, setHeight,
			MipLevels, Usage,	Format, Pool, Filter, MipFilter, ColorKey,
			&i, NULL, &texture); 

		height = i.Height;
		width = i.Width;
		format = Format;

		SPGameManager::GetSingleton()->GetGame()->UnlockDrawing();
	}
Beispiel #4
0
LPDIRECT3DTEXTURE d3d_texture_new(LPDIRECT3DDEVICE dev,
      const char *path, unsigned width, unsigned height,
      unsigned miplevels, unsigned usage, D3DFORMAT format,
      D3DPOOL pool, unsigned filter, unsigned mipfilter,
      D3DCOLOR color_key, void *src_info_data, 
      PALETTEENTRY *palette)
{
   HRESULT hr;
   LPDIRECT3DTEXTURE buf;
   D3DXIMAGE_INFO *src_info = (D3DXIMAGE_INFO*)src_info_data;

   if (path)
      hr = D3DXCreateTextureFromFileExA(dev,
            path, width, height, miplevels, usage, format,
            pool, filter, mipfilter, color_key, src_info,
            palette, &buf);
   else
   {
      hr = dev->CreateTexture(width, height, miplevels, usage,
            format, pool, &buf
#ifndef _XBOX1
            , NULL
#endif
            );
   }

   if (FAILED(hr))
	   return NULL;

   return buf;
}
Beispiel #5
0
// 
// BitmapSprite::VOnRestore - Chapter 10, page 322
//
HRESULT BitmapSprite::VOnRestore()
{
	if (FAILED (Sprite::VOnRestore() ) )
	{
		return E_FAIL;
	}

	SAFE_RELEASE(m_pTexture);

    D3DXIMAGE_INFO imageInfo;
	ZeroMemory(&imageInfo, sizeof(D3DXIMAGE_INFO));

	if (m_bInCache)
	{
		Resource resource(m_fileName.c_str());
		shared_ptr<ResHandle> texture = g_pApp->m_ResCache->GetHandle(&resource);
		if ( FAILED ( D3DXCreateTextureFromFileInMemoryEx( 
			DXUTGetD3D9Device(), // device
			texture->Buffer(),		// source data
			texture->Size(),	// source data size
			D3DX_DEFAULT,		// width - get it from the file
			D3DX_DEFAULT,		// height - get it from the file
			D3DX_DEFAULT,		// miplevels - get it from the file
			0,					// useage - default (not a render target or dynamic)
			D3DFMT_UNKNOWN,		// format - get it from the file
			D3DPOOL_DEFAULT,	// pool - use default
			D3DX_FILTER_NONE,	// filter - don't use any filter
			D3DX_DEFAULT,		// mip filter - use default
			g_Transparent,		// color key - use our transparent color
			&imageInfo,			// grab the source info
			NULL,				// palleteindex - we don't need it
			&m_pTexture ) ) )	// the texture pointer
			return false;
	}
	else
	{
		if ( FAILED ( D3DXCreateTextureFromFileExA ( 
			DXUTGetD3D9Device(), 
			m_fileName.c_str(),	// source file name
			D3DX_DEFAULT,		// width - get it from the file
			D3DX_DEFAULT,		// height - get it from the file
			D3DX_DEFAULT,		// miplevels - get it from the file
			0,					// useage - default (not a render target or dynamic)
			D3DFMT_UNKNOWN,		// format - get it from the file
			D3DPOOL_DEFAULT,	// pool - use default
			D3DX_FILTER_NONE,	// filter - don't use any filter
			D3DX_DEFAULT,		// mip filter - use default
			g_Transparent,		// color key - use our transparent color
			&imageInfo,			// grab the source info
			NULL,				// palleteindex - we don't need it
			&m_pTexture ) ) )	// the texture pointer
			return false;
	}

	m_TextureWidth = m_Width = imageInfo.Width;
	m_TextureHeight = m_Height = imageInfo.Height / m_NumFrames;
	GCC_ASSERT(m_Height * m_NumFrames == imageInfo.Height && _T("Sprite height error"));

	return true;
}
LPDIRECT3DTEXTURE9 TextureManager::GetInstanceTexture(const char* path, const char* fileName)
{
	if ( textureDataMap.find(fileName) == textureDataMap.end() )
	{
		char fullPath[512];
		strcpy_s(fullPath, path);
		strcat_s(fullPath, fileName);

		D3DXCreateTextureFromFileExA(
			GameManager::GetDevice(),
			fullPath,
			D3DX_DEFAULT_NONPOW2,
			D3DX_DEFAULT_NONPOW2,
			D3DX_DEFAULT,
			0,
			D3DFMT_UNKNOWN,
			D3DPOOL_MANAGED,
			D3DX_FILTER_NONE,
			D3DX_DEFAULT,
			0,
			&textureDataMap[fileName].second,
			nullptr,
			&textureDataMap[fileName].first);
	}
	return textureDataMap[fileName].first;
}
bool CGraphics::LoadFonts()
{
	// Create the font and sprite objects
	static const sFontInfo fontInfos[] =
	{
		{ "default",		15,		FW_NORMAL },
		{ "default-bold",	15,		FW_BOLD },
		{ "tahoma",			15,		FW_NORMAL },
		{ "tahoma-bold",	15,		FW_BOLD },
		{ "verdana",		15,		FW_NORMAL },
		{ "arial",			15,		FW_NORMAL }
	};

	bool bSuccess = true;
	for(int i = 0; bSuccess && i < NUM_FONTS; i++)
	{	
		bSuccess &= SUCCEEDED(D3DXCreateFont(m_pDevice, fontInfos[i].uiHeight, 0, fontInfos[i].uiWeight, 1, FALSE,
						DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, fontInfos[i].szFontName,
                        &m_pFonts[i]));
	}

	// Load texture for radar
	D3DXCreateTextureFromFileExA(m_pDevice, SharedUtility::GetAbsolutePath("multiplayer\\datafiles\\hud.png").Get(), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 
		D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,D3DX_DEFAULT, 0, 
		NULL, NULL, &m_pRadarOverlayTexture);

	return bSuccess && SUCCEEDED(D3DXCreateSprite(m_pDevice, &m_pSprite));
}
Beispiel #8
0
GImage::GImage(GRenderer * renderer, const char * filename)
{
	//USES_CONVERSION;

	D3DXIMAGE_INFO info;
	D3DXGetImageInfoFromFileA(filename, &info);	//이미지 정보를 저장
	D3DXCreateTextureFromFileExA(renderer->getDevice(), filename, info.Width, info.Height, 1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, -1, -1, 0xffff00ff, &info, NULL, &texture);
	width = info.Width;
	height = info.Height;
}
Beispiel #9
0
int Model::load(const std::string& xfile)
{
	LPD3DXBUFFER pD3DXMtrlBuff;

	if ( FAILED( D3DXLoadMeshFromX( xfile.c_str(), D3DXMESH_SYSTEMMEM,
		Graphics::inst()->Device(), NULL,
		&pD3DXMtrlBuff, NULL, &m_numMaterials,
		&m_pD3DMesh ) ) )
	{
		return -1;
	}

	D3DXMATERIAL* pD3DXMats = ( D3DXMATERIAL* ) pD3DXMtrlBuff->GetBufferPointer();
	m_pD3DMaterials = new D3DMATERIAL9[m_numMaterials];
	if ( m_pD3DMaterials == 0 )
		return -1;

	m_pD3DTexture = new LPDIRECT3DTEXTURE9[m_numMaterials];
	if ( m_pD3DTexture == 0 )
		return -1;

	for ( DWORD i = 0; i < m_numMaterials; i++ )
	{
		m_pD3DMaterials[i] = pD3DXMats[i].MatD3D;

		m_pD3DMaterials[i].Ambient = m_pD3DMaterials[i].Diffuse;

		m_pD3DTexture[i] = 0;
		if ( pD3DXMats[i].pTextureFilename != 0 
			&& lstrlenA( pD3DXMats[i].pTextureFilename ) > 0 )
		{
			D3DXCreateTextureFromFileExA(
				Graphics::inst()->Device(),
				pD3DXMats[i].pTextureFilename,
				0, 0, 0, 0,
				D3DFMT_A8R8G8B8,
				D3DPOOL_MANAGED,
				D3DX_FILTER_LINEAR,
				D3DX_FILTER_LINEAR,
				D3DCOLOR_XRGB(0, 0, 0),
				0, 0, &m_pD3DTexture[i]);
//			if ( FAILED( D3DXCreateTextureFromFileA( Graphics::inst()->Device(),
//				pD3DXMats[i].pTextureFilename,
//				&m_pD3DTexture[i] ) ) )
//			{
//				return -1;
//			}
		}
	}

	pD3DXMtrlBuff->Release();

	return S_OK;
}
Beispiel #10
0
    // texture
    TextureHandle Gfx_Texture_Load(RenderDevice* dev, const char* filename, TextureType::type type)
    { 
        D3DXIMAGE_INFO info = {0};

        uint32 mip_levels_flags = D3DX_FROM_FILE;
        D3DFORMAT texture_format_flags = D3DFMT_FROM_FILE;

        TextureDescr tex;
        IDirect3DTexture9* native2D = NULL;
        IDirect3DVolumeTexture9* native3D = NULL;
        IDirect3DCubeTexture9* nativeCUBE = NULL;

        if( type == TextureType::Tex2D )
        {
            HRESULT hr = D3DXCreateTextureFromFileExA(
                dev->d3d9device, filename, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, mip_levels_flags,
                0, texture_format_flags , D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, &info, NULL, &native2D);
            validate_d3d_result(hr);
            tex = TextureDescr::create_2D(info.Width, info.Height, pixel_format_from_dx9(info.Format));
        }
        else if( type == TextureType::Tex3D )
        {
            HRESULT hr = D3DXCreateVolumeTextureFromFileExA(
                dev->d3d9device, filename, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, mip_levels_flags,
                0, texture_format_flags , D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, &info, NULL, &native3D);
            validate_d3d_result(hr);
            tex = TextureDescr::create_3D(info.Width, info.Height, info.Depth, pixel_format_from_dx9(info.Format));
        }
        else if( type == TextureType::TexCUBE )
        {
            HRESULT hr = D3DXCreateCubeTextureFromFileExA(
                dev->d3d9device, filename, D3DX_DEFAULT_NONPOW2, mip_levels_flags,
                0, texture_format_flags , D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, &info, NULL, &nativeCUBE);
            validate_d3d_result(hr);
            tex = TextureDescr::create_CUBE(info.Width, pixel_format_from_dx9(info.Format));
        }

        if( tex.format == PixelFormat::Unknown )
        {
            Log::warning("Could not load texture '%s'. Perhaps it doesn't exist or uses unsupported format.", filename);
            return InvalidResourceHandle();
        }
        else
        {
            TextureDX9 res;
            res.desc        = tex;
            res.native2D    = native2D;
            res.native3D    = native3D;
            res.nativeCUBE  = nativeCUBE;
            res.surface     = NULL;
            return dev->resources->textures.push(res);
        }
    }
Beispiel #11
0
bool Mario::LoadTexture()
{
	if( FAILED( D3DXCreateTextureFromFileExA( pDevice, 
		"textures\\Mario_right.bmp",
		128,
		128,
		D3DX_DEFAULT,NULL,
		D3DFMT_UNKNOWN,   
               D3DPOOL_MANAGED,   //memory class
                             D3DX_DEFAULT,      //filter
                             D3DX_DEFAULT,      //mip filter
                             0xff00ff00,        //color key
                             NULL,              //source info
                             NULL,   
							 &MarioTextures[0]) ) )
    { 
		return false;
	}

	if( FAILED( D3DXCreateTextureFromFileExA( pDevice, 
		"textures\\Mario_left.bmp",
		128,
		128,
		D3DX_DEFAULT,NULL,
		D3DFMT_UNKNOWN,   
               D3DPOOL_MANAGED,   //memory class
                             D3DX_DEFAULT,      //filter
                             D3DX_DEFAULT,      //mip filter
                             0xff00ff00,        //color key
                             NULL,              //source info
                             NULL,   
							 &MarioTextures[1]) ) )
    { 
		return false;
	}

	CurrentMarioTexture = MarioTextures[0];
}
Beispiel #12
0
	void Image::ImageLoad()
	{
		//D3DXCreateTextureFromFileInMemoryEx(
		//	g_d3dDev,
		//	NULL,
		//	0,
		//	0,
		//	0,
		//	1,
		//	0,
		//	D3DFMT_A8R8G8B8,
		//	D3DPOOL_MANAGED,
		//	D3DX_FILTER_POINT,
		//	D3DX_FILTER_POINT,
		//	D3DCOLOR_ARGB(0, 255, 255, 255),
		//	NULL,
		//	NULL,
		//	(LPDIRECT3DTEXTURE9*)&this->tex);

		D3DXIMAGE_INFO info;

		D3DXGetImageInfoFromFileA(
			this->buf,
			&info);

		this->width = info.Width;
		this->height = info.Height;

		D3DXCreateTextureFromFileExA(
			g_d3dDev,
			this->buf,
			this->width,
			this->height,
			1,
			0,
			D3DFMT_A8R8G8B8,
			D3DPOOL_MANAGED,
			D3DX_FILTER_POINT,
			D3DX_FILTER_POINT,
			D3DCOLOR_ARGB(0, 255, 255, 255),
			NULL,
			NULL,
			(LPDIRECT3DTEXTURE9*)&this->tex);
	}
Beispiel #13
0
void RoundProcess::loadImage(const char* pszName, IDirect3DDevice9* pDev)
{
	return;
    D3DXIMAGE_INFO info;
    D3DXGetImageInfoFromFileA(pszName, &info);

    D3DXCreateTextureFromFileExA(pDev, pszName, info.Width, info.Height, 
        info.MipLevels, D3DUSAGE_DYNAMIC, info.Format, D3DPOOL_DEFAULT, D3DX_FILTER_TRIANGLE,  // D3DPOOL_DEFAULT²Å¿ÉÐС£¡£
        D3DX_FILTER_TRIANGLE, D3DCOLOR_ARGB(255,255,255,255), NULL, NULL, &m_pTexture);

    pDev->CreateVertexBuffer(6*sizeof(VertexS),
        D3DUSAGE_WRITEONLY,
        VertexS::FVF,
        D3DPOOL_MANAGED,
        &m_pVb,
        0);

    m_x = 0;
    m_y = 0;
    m_w = info.Width;
    m_h = info.Height;


    VertexS *pVec;
    m_pVb->Lock(0, sizeof(VertexS)*6, (void**)&pVec, 0);

    float fix = -0.5f;
    float z = 0.f;

    m_color = 0xffffffff;

    pVec[0] = VertexS(m_x + fix, m_y + fix, z, 1.0f, m_color, 0.0f, 0.0f);
    pVec[1] = VertexS(m_x + (float)info.Width + fix, m_y + fix, z, 1.0f, m_color, 1.0f, 0.0f);
    pVec[2] = VertexS(m_x + fix, m_y + (float)info.Height + fix, z, 1.0f, m_color, 0.0f, 1.0f);

    pVec[3] = VertexS(m_x + fix, m_y + (float)info.Height + fix, z, 1.0f, m_color, 0.0f, 1.0f);
    pVec[4] = VertexS(m_x + (float)info.Width + fix, m_y + fix, z, 1.0f, m_color, 1.0f, 0.0f);
    pVec[5] = VertexS(m_x + (float)info.Width + fix, m_y + (float)info.Height + fix, z, 1.0f, m_color, 1.0f, 1.0f);

    m_pVb->Unlock();
}
LPDIRECT3DTEXTURE9 CResourceManager::LoadTexture(char *path)
{
	if (textures[path] != NULL) return textures[path];

	D3DXCreateTextureFromFileExA(
		App::g_pd3dDevice,
		path,
		D3DX_DEFAULT_NONPOW2,
		D3DX_DEFAULT_NONPOW2,
		1,
		0,
		D3DFMT_UNKNOWN,
		D3DPOOL_MANAGED,
		D3DX_DEFAULT,
		D3DX_DEFAULT,
		NULL,
		NULL,
		NULL,
		&textures[path]	
		);

	return textures[path];
}
Beispiel #15
0
bool texture_image_load(void *data, const char *path, void *image_data)
{
   d3d_video_t *d3d = (d3d_video_t*)data;
   struct texture_image *out_img = (struct texture_image*)image_data;

   D3DXIMAGE_INFO m_imageInfo;

   out_img->pixels      = NULL;
   out_img->vertex_buf  = NULL;

   HRESULT ret = D3DXCreateTextureFromFileExA(d3d->dev,
         path, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8,
         D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, &m_imageInfo, NULL,
         &out_img->pixels);

   if(FAILED(ret))
   {
      RARCH_ERR("Error occurred during D3DXCreateTextureFromFileExA().\n");
      return false;
   }

   // create a vertex buffer for the quad that will display the texture
   ret = d3d->dev->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats),
         D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &out_img->vertex_buf);

   if (FAILED(ret))
   {
      RARCH_ERR("Error occurred during CreateVertexBuffer().\n");
      out_img->pixels->Release();
      return false;
   }

   out_img->width = m_imageInfo.Width;
   out_img->height = m_imageInfo.Height;

   return true;
}
Beispiel #16
0
bool renderchain_add_lut(void *data, const std::string &id,
      const std::string &path,
      bool smooth)
{
   renderchain_t *chain = (renderchain_t*)data;
   LPDIRECT3DTEXTURE lut;
   LPDIRECT3DDEVICE d3dr = chain->dev;

   RARCH_LOG("[D3D]: Loading LUT texture: %s.\n", path.c_str());

   if (FAILED(D3DXCreateTextureFromFileExA(
               d3dr,
               path.c_str(),
               D3DX_DEFAULT_NONPOW2,
               D3DX_DEFAULT_NONPOW2,
               0,
               0,
               D3DFMT_FROM_FILE,
               D3DPOOL_MANAGED,
               smooth ? D3DX_FILTER_LINEAR : D3DX_FILTER_POINT,
               0,
               0,
               NULL,
               NULL,
               &lut)))
      return false;

   d3dr->SetTexture(0, lut);
   D3DDevice_SetSamplerState_AddressU(d3dr, 0, D3DTADDRESS_BORDER);
   D3DDevice_SetSamplerState_AddressV(d3dr, 0, D3DTADDRESS_BORDER);
   d3dr->SetTexture(0, NULL);

   lut_info info = { lut, id, smooth };
   chain->luts.push_back(info);
   return true;
}
Beispiel #17
0
bool parseCodeImage(const char* pszPath)
{
    D3DXIMAGE_INFO info;
    HRESULT re = D3DXGetImageInfoFromFileA(pszPath, &info);
    if(re != S_OK)
        return false;


    IDirect3DTexture9 *pText = NULL;
    //D3DXCreateTextureFromFileA(g_pDevice, pszPath, &pText); //用没有 EX 的函数, 创建的纹理长宽会变成 2的 n次方
    re = D3DXCreateTextureFromFileExA(g_pDevice, pszPath, info.Width, info.Height, 
        info.MipLevels, 0/*D3DUSAGE_RENDERTARGET*/, info.Format, D3DPOOL_SYSTEMMEM, 
        D3DX_FILTER_TRIANGLE,D3DX_FILTER_TRIANGLE,D3DCOLOR_ARGB(255,0,0,0), NULL, NULL, &pText);

    FILE* pFile = fopen("D:/hehe.txt", "w");

    D3DLOCKED_RECT rc;
    pText->LockRect(0, &rc, NULL, 0);

    BYTE bR = 0, bG = 0, bB = 0;

    DWORD* pSrc = (DWORD*)rc.pBits;
    for (int i = 0; i < info.Height ; i++)
    {
        for (int j = 0; j < info.Width; j++)
        {
            bR = (*pSrc) >> 16;
            bG = (*pSrc) << 16 >> 24;
            bB = (*pSrc) & 0x000000ff;

           if (bR >= 205 && bG >= 205 && bB >= 205)
           {
                fprintf(pFile, "1");
           }
           else
           {
               fprintf(pFile, "8");
           }

           BYTE t = max( max(bR, bG), bB);

           *pSrc = t | t << 8 | t << 16;
               

            ++pSrc;

        }

        fprintf(pFile, "\r\n");
    }

    pText->UnlockRect(0);

    // 保存灰度图
    re = D3DXSaveTextureToFileA("D:/hehe.jpg", D3DXIFF_BMP, pText, NULL);

    
    pText->Release();

    fclose(pFile);


}
bool
CKind::GenerateTextures( string &path)
{
    char *pom = new char[ path.size( ) + 20];

    DWORD keyColor = 0xffffffff;

    /////////////////////////////////////////
    // create leaves textures
    /////////////////////////////////////////
    for( int i = 0; i < NUMBER_OF_PS_TEXTURES; i++)
    {
        // discard the old one
        if( m_textures[ 3][ i] != NULL)
            m_textures[ 3][ i]->Release( );

        sprintf( pom, "%s%d.png", &path[ 0], i);

        if( FAILED( D3DXCreateTextureFromFileExA( m_dev, pom, D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,NULL,D3DFMT_UNKNOWN,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,keyColor,NULL,NULL,&m_textures[ 3][ i]) ) )
        {
            MessageBox( 0, "Creation of texture failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
            return false;
        }
    }

    /////////////////////////////////////////
    // other levels textures
    ///////////////////////////////////////
    // level 0
    for( int i = 0; i < NUM_OF_SIMPLFD_TEXTRS0; i++)
    {
        // discard the old one
        if( m_textures[ 0][ i] != NULL)
            m_textures[ 0][ i]->Release( );

        sprintf( pom, "%slvl0Tex%d.png", &path[ 0], i);

        if( FAILED( D3DXCreateTextureFromFileExA( m_dev, pom, D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,NULL,D3DFMT_UNKNOWN,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,keyColor,NULL,NULL,&m_textures[ 0][ i]) ) )
        {
            MessageBox( 0, "Creation of texture failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
            return false;
        }
    }

    // level 1
    for( int i = 0; i < NUM_OF_SIMPLFD_TEXTRS1; i++)
    {
        // discard the old one
        if( m_textures[ 1][ i] != NULL)
            m_textures[ 1][ i]->Release( );

        sprintf( pom, "%slvl1Tex%d.png", &path[ 0], i);

        if( FAILED( D3DXCreateTextureFromFileExA( m_dev, pom, D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,NULL,D3DFMT_UNKNOWN,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,keyColor,NULL,NULL,&m_textures[ 1][ i]) ) )
        {
            MessageBox( 0, "Creation of texture failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
            return false;
        }
    }

    // level 2
    for( int i = 0; i < NUM_OF_SIMPLFD_TEXTRS2; i++)
    {
        // discard the old one
        if( m_textures[ 2][ i] != NULL)
            m_textures[ 2][ i]->Release( );

        sprintf( pom, "%slvl2Tex%d.png", &path[ 0], i);

        if( FAILED( D3DXCreateTextureFromFileExA( m_dev, pom, D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,NULL,D3DFMT_UNKNOWN,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,keyColor,NULL,NULL,&m_textures[ 2][ i]) ) )
        {
            MessageBox( 0, "Creation of texture failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
            return false;
        }
    }

    // crust texture
    sprintf( pom, "%scrust.png", &path[ 0]);

    if( FAILED( D3DXCreateTextureFromFile( m_dev, pom, &m_crustTexture) ) )
    {
        MessageBox( 0, "Creation of crust texture failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
        return false;
    }

    delete pom;

    return true;
}
Beispiel #19
0
bool CMSprite::LoadAImage(const char* pszName, IDirect3DDevice9 *pDevice)
{
    D3DXIMAGE_INFO info;
    D3DXGetImageInfoFromFileA(pszName, &info);

    D3DXCreateTextureFromFileExA(pDevice, pszName, info.Width, info.Height, 
        info.MipLevels, D3DUSAGE_DYNAMIC, info.Format, D3DPOOL_DEFAULT, D3DX_FILTER_TRIANGLE,  // D3DPOOL_DEFAULT才可行。。
        D3DX_FILTER_TRIANGLE, D3DCOLOR_ARGB(255,255,255,255), NULL, NULL, &m_pTexture);

    pDevice->CreateVertexBuffer(3*sizeof(Vertex3D),
        0/*D3DUSAGE_WRITEONLY*/,
        Vertex3D::FVF,
        D3DPOOL_DEFAULT/*D3DPOOL_MANAGED*/,
        &m_pVb,
        0);

    m_x = -1.0f;
    m_y = 0.0f;
    m_w = 1.0f;info.Width;
    m_h = 1.0f;info.Height;

    m_iw = 1.0f; info.Width;
    m_ih = 1.0f; info.Height;

    m_reClip.left = 0.f;
    m_reClip.top = 0.f;
    m_reClip.right = 1.0f;
    m_reClip.bottom = 1.0f;

    m_StretchX = 1.0f;
    m_StretchY = 1.0f;

    Vertex3D *pVec = NULL;
    if( FAILED(m_pVb->Lock(0, sizeof(Vertex3D)*/*6*/3, (void**)&pVec, 0) ) ) {
        MessageBoxA(NULL, "f", "f", NULL);
        return false;
    }

    float fix = /*0.0f; */  -0.5f;
    m_z = 1.0f;
    m_color = 0xffaaffff;

    // 注意坐标 
    /*
      y ^
        |
        |
        |
        ------> x
    */

     pVec[0] = Vertex3D(m_x  + fix, m_y + fix, m_z, 0xffff0000, 0.0f, 1.0f); // -1.0f, 0.0f
     pVec[1] = Vertex3D(m_x  + fix, m_y + m_h+ fix, m_z, 0xff00ff00, 0.0f, 0.0f); // -1.0f, 1.0f
     pVec[2] = Vertex3D(m_x + m_w + fix, m_y + m_h + fix, m_z, 0xffffffff, 1.0f, 0.0f); // 
//     float fixup = 1.0f;
//     pVec[0] = Vertex3D(-1.0f,-1.0f, fixup, 0xffff0000, 0.f, 0.f);
//     pVec[1] = Vertex3D(0.0f, 1.0f, fixup, 0xffffffff, 1.f, 1.f);
//     pVec[2] = Vertex3D(1.0f,-1.0f, fixup, 0xff0000ff, 0.f, 1.f);

    //pVec[3] = Vertex3D(m_x + m_w + fix, m_y + fix, m_z, m_color, 1.0f, 1.0f);

    m_pVb->Unlock();
    m_pTest = m_pVb;//test

	m_bDirty = true; //标记为脏

    return true;
}
Beispiel #20
0
//load image files
void dxInit::LoadSprite(std::string filename, LPDIRECT3DTEXTURE9 *texture){
	filename = "media//sprite//" + filename;
	D3DXCreateTextureFromFileExA(m_d3ddev, filename.c_str(), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 
									  D3DX_FROM_FILE, NULL, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
									  D3DX_DEFAULT, 0, NULL, NULL, texture);
}
LPDIRECT3DTEXTURE9 TextureManager::GetInstanceTexture(const char* filename, D3DXIMAGE_INFO* imageInfo /*= nullptr*/)
{
	auto iter = textureDataMap.find(filename);
	if (textureDataMap.find(filename) == textureDataMap.end( ))
	{
		bool isFaile = true;
		while (isFaile)
		{
			static char fullPath[256];
			static int count = 0;
			static const char* str;

			switch (count++)
			{
				case 0:
					str = TEXTURE_DIRECTORY;
					break;
				case 1:
					str = TEXTURE_DIRECTORY1;
					break;
				case 2:
					str = TEXTURE_DIRECTORY2;
					break;
				case 3:
					str = TEXTURE_DIRECTORY3;
					break;
				case 4:
					str = TEXTURE_DIRECTORY4;
					break;
				case 5:
					str = TEXTURE_DIRECTORY5;
					break;
				default:
					isFaile = false;
					count = 0;
					break;
			}
			strcpy_s(fullPath, str);
			strcat_s(fullPath, filename);

			if (SUCCEEDED(D3DXCreateTextureFromFileExA(
				GameManager::GetDevice( ),
				fullPath,
				D3DX_DEFAULT_NONPOW2,
				D3DX_DEFAULT_NONPOW2,
				D3DX_DEFAULT,
				0,
				D3DFMT_UNKNOWN,
				D3DPOOL_MANAGED,
				D3DX_FILTER_NONE,
				D3DX_DEFAULT,
				0,
				&textureDataMap[filename].second,
				nullptr,
				&textureDataMap[filename].first)))
			{
				isFaile = false;
				count = 0;
			}
		}
	}
	if (imageInfo)
	{
		*imageInfo = textureDataMap[filename].second;
	}
	return textureDataMap[filename].first;
}