コード例 #1
0
LPDIRECT3DSURFACE9 LoadSurface(char *filename, D3DCOLOR transcolor)
{
    LPDIRECT3DSURFACE9 image = NULL;
    D3DXIMAGE_INFO info;
    HRESULT result;
    
    result = D3DXGetImageInfoFromFile(filename, &info);

    result = d3ddev->CreateOffscreenPlainSurface(
        info.Width,
        info.Height,
        D3DFMT_X8R8G8B8,
        D3DPOOL_DEFAULT,
        &image,
        NULL);

    result = D3DXLoadSurfaceFromFile(
        image,
        NULL,
        NULL,
        filename,
        NULL,
        D3DX_DEFAULT,
        transcolor,
        NULL);

    return image;
}
コード例 #2
0
//Loads the given file into a texture (I use textures for the sprites to allow transparency)
LPDIRECT3DTEXTURE9 GameWindow::Load_Texture(LPCWSTR filename){  
    LPDIRECT3DTEXTURE9 texture = NULL;

    //get width and height from bitmap file
    D3DXIMAGE_INFO info;
    HRESULT result = D3DXGetImageInfoFromFile(filename, &info);
    if (result != D3D_OK) return NULL;
    //create the new texture by loading a bitmap image file
	D3DXCreateTextureFromFileEx( 
        m_d3ddev,                //Direct3D device object
        filename,				 //bitmap filename
        info.Width,            //bitmap image width
        info.Height,           //bitmap image height
        1,                     //mip-map levels (1 for no chain)
        D3DPOOL_DEFAULT,       //the type of surface (standard)
        D3DFMT_UNKNOWN,        //surface format (default)
        D3DPOOL_DEFAULT,       //memory class for the texture
        D3DX_DEFAULT,          //image filter
        D3DX_DEFAULT,          //mip filter
        D3DCOLOR_XRGB(255,0,255),            //color key for transparency
        &info,                 //bitmap file info (from loaded file)
        NULL,                  //color palette
        &texture );            //destination texture

    //make sure the bitmap textre was loaded correctly
    if (result != D3D_OK) return NULL;

	return texture;
}
コード例 #3
0
ファイル: Texture.cpp プロジェクト: ryanaleksander/NMGAME
HRESULT Texture::loadFromFile(LPD3DXSPRITE spriteHandle, LPWSTR filePath, D3DXCOLOR color)
{
    HRESULT			result;

    result = D3DXGetImageInfoFromFile(filePath, &this->_imageInfo);
    if (result != D3D_OK)
    {
        return result;
    }

    LPDIRECT3DDEVICE9 _device = DeviceManager::getInstance()->getDevice();
    spriteHandle->GetDevice(&_device);

    result = D3DXCreateTextureFromFileEx(
                 _device,
                 filePath,
                 this->_imageInfo.Width,
                 this->_imageInfo.Height,
                 1,
                 D3DUSAGE_DYNAMIC,
                 D3DFMT_UNKNOWN,
                 D3DPOOL_DEFAULT,
                 D3DX_DEFAULT,
                 D3DX_DEFAULT,
                 color,
                 &this->_imageInfo,
                 nullptr,
                 &this->_texture);

    _color = color;

    return result;
}
コード例 #4
0
ファイル: Graphics.cpp プロジェクト: gejben/Pathfinding
	bool LoadTexture(std::string filename, Texture *te, D3DCOLOR transcolor) {
		LPDIRECT3DTEXTURE9 texture = NULL;

		D3DXIMAGE_INFO info;
		HRESULT result = D3DXGetImageInfoFromFile(filename.c_str(), &info);
		if(result != D3D_OK) {
			return false;
		}

		result = D3DXCreateTextureFromFileEx(device, filename.c_str(), info.Width,
																				 info.Height, 1, D3DPOOL_DEFAULT, D3DFMT_UNKNOWN, 
																				 D3DPOOL_DEFAULT, D3DX_DEFAULT,
																				 D3DX_DEFAULT, transcolor, &info, NULL, &texture);

		if(result != D3D_OK) {
			return false;
		}

		textureList.push_back(texture);

		te->height = info.Height;
		te->width = info.Width;
		te->textureIndex = textureList.size() - 1;
		te->imageLoaded = true;
		te->color = 0xffffffff;

		return true;
	}
コード例 #5
0
ファイル: Texture.cpp プロジェクト: d3ru/hsjdgal-sdw
bool Texture::init(std::string fileName, D3DCOLOR color)
{
	HRESULT result; // take a value return
	
	result = D3DXGetImageInfoFromFile(fileName.c_str(), &_infoImage);
	if (result != D3D_OK)
	{
		_texture = NULL;
		return false;
	}
	// create a new Texture by loading bitmap image file
	result = D3DXCreateTextureFromFileEx(
		_d3ddv, // directx Device
		fileName.c_str(), // bitmap file
		_infoImage.Width, //bitmap image width
		_infoImage.Height, //bitmap image Height
		1,
		D3DPOOL_DEFAULT, // type of the surface
		D3DFMT_UNKNOWN, //surface format
		D3DPOOL_DEFAULT, // memory class for the texture
		D3DX_DEFAULT, //image filter
		D3DX_DEFAULT, //mip filter
		color, // color key for transparency
		&_infoImage,//bitmap file information
		NULL, //color palette
		&_texture //destination Texture
		);
	if (result != D3D_OK)
	{
		_texture = NULL;
		return false;
	}
	return  true;
}
コード例 #6
0
ファイル: Texture.cpp プロジェクト: doanhtdpl/mario-uit
// Get texture
LPDIRECT3DTEXTURE9 CTexture::GetTexture(string _filename)
{
	HRESULT result;
	
	// Get image from file
	result = D3DXGetImageInfoFromFile(_filename.c_str(), &m_info);
	if (FAILED(result))
	{
		return NULL;
	}
	
	// Create texture from file >>Ex
	result = D3DXCreateTextureFromFileEx(
		m_pd3ddevice, //device
		_filename.c_str(), //file name
		m_info.Width,  //width of image
		m_info.Height, //height of image
		1, // 
		D3DPOOL_DEFAULT, //
		D3DFMT_UNKNOWN,	 //format
		D3DPOOL_DEFAULT, //
		D3DX_DEFAULT, 
		D3DX_DEFAULT,
		D3DCOLOR_XRGB(250,100,100), // color key
		&m_info, //info image
		NULL,
		&m_texture); //texture

	if (FAILED(result))
	{
		return NULL; // FAILED is declared in WinError.h
	}
	//
	return m_texture;
}
コード例 #7
0
ファイル: Graphics.cpp プロジェクト: gejben/Pathfinding
	bool LoadSprite(std::string filename, Texture &texture, D3DCOLOR transcolor) {
		LPDIRECT3DTEXTURE9 d9texture = NULL;

		D3DXIMAGE_INFO info;
		HRESULT result = D3DXGetImageInfoFromFile(filename.c_str(), &info);
		if(result != D3D_OK) {
			return false;
		}

		result = D3DXCreateTextureFromFileEx(device, filename.c_str(), info.Width,
																				 info.Height, 1, D3DPOOL_DEFAULT, 
																				 D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, 
																				 D3DX_DEFAULT,D3DX_DEFAULT,
																				 transcolor, &info, NULL, &d9texture);

		if(result != D3D_OK) {
			return false;
		}

		textureList.push_back(d9texture);

		//ts up parameters in sprite for successfull load and for being a 
		//single-frame sprite that will not be animated
		texture.height = info.Height;
		texture.width = info.Width;
		texture.textureIndex = textureList.size() - 1;
		texture.imageLoaded = true;

		return true;
	}
コード例 #8
0
LPDIRECT3DTEXTURE9 LoadTexture (char* fileName, D3DCOLOR transColor) {
    LPDIRECT3DTEXTURE9 texture = NULL;
    D3DXIMAGE_INFO info;
    HRESULT hr;

    hr = D3DXGetImageInfoFromFile(fileName, &info);
    if (hr != D3D_OK)
        return NULL;

    hr = D3DXCreateTextureFromFileEx(
        d3dDev, 
        fileName, 
        info.Width, 
        info.Height, 
        1, 
        D3DPOOL_DEFAULT, 
        D3DFMT_UNKNOWN, 
        D3DPOOL_DEFAULT, 
        D3DX_DEFAULT, 
        D3DX_DEFAULT, 
        transColor, 
        &info, 
        NULL, 
        &texture);

    if (hr != D3D_OK)
        return NULL;

    return texture;
}
コード例 #9
0
void OnInitial(DEVICEINSTANCE *device)
{
	XInputEnable(true);

	D3DXMATRIX projection;
	D3DXMatrixPerspectiveFovLH(&projection, D3DX_PI / 4, 800 / 600.0f, 1.0f, 10000.0f);
	device->d3dDevice->SetTransform(D3DTS_PROJECTION, &projection);

	D3DXLoadMeshFromX(L"skybox.x", 0, device->d3dDevice, nullptr, nullptr, nullptr, nullptr, &skybox);

	D3DXCreateTextureFromFile(device->d3dDevice, L"sky copy.png", &texture);

	D3DXCreateTextureFromFile(device->d3dDevice, L"terrain_01.jpg", &heightMap);
	D3DXCreateTextureFromFile(device->d3dDevice, L"terrain_02.jpg", &heightMapTexture);

	D3DXIMAGE_INFO heightMapInfo = { 0, };
	D3DXGetImageInfoFromFile(L"terrain_01.jpg", &heightMapInfo);
	terrainWidth = heightMapInfo.Width; terrainHeight = heightMapInfo.Height;

	D3DCOLOR * colors;
	D3DLOCKED_RECT lockedRect = { 0, };
	RECT rect = { 0, 0, terrainWidth, terrainHeight };
	terrainVertices = new TerrainVertex[numOfVertices = terrainWidth * terrainHeight];
	heightMap->LockRect(0, &lockedRect, &rect, 0);
	colors = (D3DCOLOR*)lockedRect.pBits;
	TerrainVertex * tempVertices = terrainVertices;
	for (int x = 0; x < terrainHeight; x++)
	{
		for (int z = 0; z < terrainWidth; z++)
		{
			int location = x * terrainWidth + z;
			*tempVertices = TerrainVertex(
				(x - terrainWidth / 2) * 5.0f, (colors[location] & 0xff) * 5.0f / 2,
				(z - terrainWidth / 2) * 5.0f,
				z / (float)terrainWidth, x / (float)terrainHeight
				);
			tempVertices++;
		}
	}
	heightMap->UnlockRect(0);
	heightMap->Release();

	terrainIndices = new int[numOfIndices = (terrainWidth - 1) * (terrainHeight - 1) * 2 * 3];
	struct Polygon { int index[3]; } *tempIndices = (Polygon*)terrainIndices;

	for (int z = 0; z < terrainHeight - 1; z++)
	{
		for (int x = 0; x < terrainWidth - 1; x++)
		{
			(*tempIndices).index[0] = z * terrainWidth + x;
			(*tempIndices).index[1] = z * terrainWidth + (x + 1);
			(*tempIndices).index[2] = (z + 1) * terrainWidth + x;
			tempIndices++;
			(*tempIndices).index[0] = (z + 1) * terrainWidth + x;
			(*tempIndices).index[1] = z * terrainWidth + (x + 1);
			(*tempIndices).index[2] = (z + 1) * terrainWidth + (x + 1);
			tempIndices++;
		}
	}
}
コード例 #10
0
LPDIRECT3DTEXTURE9 LoadTexture(char *filename, D3DCOLOR transcolor)
{
    LPDIRECT3DTEXTURE9 texture = NULL;

    D3DXIMAGE_INFO info;

    HRESULT result;
    
    result = D3DXGetImageInfoFromFile(filename, &info);

	D3DXCreateTextureFromFileEx( 
        d3ddev,      
        filename, 
        info.Width,
        info.Height,
        1,
        D3DPOOL_DEFAULT,
        D3DFMT_UNKNOWN,
        D3DPOOL_DEFAULT,
        D3DX_DEFAULT,
        D3DX_DEFAULT,
        transcolor,
        &info,
        NULL,
        &texture );

    return texture;
}
コード例 #11
0
FrkTexture* FrkContent::LoadTexture(string path)
{
	this->m_hMytexture = new FrkTexture();
	LPDIRECT3DTEXTURE9 texture = NULL;
	D3DXIMAGE_INFO info;
	HRESULT hr;
	ZeroMemory(&info, sizeof(info));
	//l?y thông tin v? hình ?nh
	hr = D3DXGetImageInfoFromFile(path.c_str(), &info);
	if (hr != D3D_OK)
		return NULL;
	//t?o texture
	hr = D3DXCreateTextureFromFileEx(this->m_hGame->GetDevice(),
		path.c_str(),
		info.Width,
		info.Height,
		1,
		D3DUSAGE_DYNAMIC,
		D3DFMT_UNKNOWN,// t? ??ng ch?n format phù h?p
		D3DPOOL_DEFAULT, //Ch?n b? nh? ?? l?u t? ??ng
		D3DX_DEFAULT,//Ch?n tham s? m?c ??nh
		D3DX_DEFAULT,//Ch?n tham s? m?c ??nh
		D3DCOLOR_XRGB(255, 255, 255),
		&info,//thông tin hình ?nh
		NULL,
		&texture);

	if (hr != D3D_OK)
		return 0;
	this->m_hMytexture->SetImage(texture);
	this->m_hMytexture->SetHeight(info.Height);
	this->m_hMytexture->SetWidth(info.Width);
	return m_hMytexture;
}
コード例 #12
0
////////////////////////////////////////////////////////////////
//
// CFileTextureItem::CreateUnderlyingData
//
// From file
//
////////////////////////////////////////////////////////////////
void CFileTextureItem::CreateUnderlyingData(const SString& strFilename, bool bMipMaps, uint uiSizeX, uint uiSizeY, ERenderFormat format)
{
    assert(!m_pD3DTexture);

    D3DXIMAGE_INFO imageInfo;
    if (FAILED(D3DXGetImageInfoFromFile(strFilename, &imageInfo)))
        return;

    D3DFORMAT D3DFormat = (D3DFORMAT)format;
    int       iMipMaps = bMipMaps ? D3DX_DEFAULT : 1;
    if (uiSizeX != D3DX_DEFAULT)
        imageInfo.Width = uiSizeX;
    if (uiSizeY != D3DX_DEFAULT)
        imageInfo.Height = uiSizeY;

    m_uiSizeX = imageInfo.Width;
    m_uiSizeY = imageInfo.Height;
    m_uiSurfaceSizeX = imageInfo.Width;
    m_uiSurfaceSizeY = imageInfo.Height;

    if (imageInfo.ResourceType == D3DRTYPE_VOLUMETEXTURE)
    {
        // It's a volume texture!
        if (FAILED(D3DXCreateVolumeTextureFromFileEx(m_pDevice, strFilename, uiSizeX, uiSizeY, D3DX_DEFAULT, iMipMaps, 0, D3DFormat, D3DPOOL_MANAGED,
                                                     D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DVolumeTexture9**)&m_pD3DTexture)))
            return;
    }
    else if (imageInfo.ResourceType == D3DRTYPE_CUBETEXTURE)
    {
        // It's a cubemap texture!
        if (FAILED(D3DXCreateCubeTextureFromFileEx(m_pDevice, strFilename, uiSizeX, iMipMaps, 0, D3DFormat, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0,
                                                   NULL, NULL, (IDirect3DCubeTexture9**)&m_pD3DTexture)))
            return;
    }
    else
    {
        // It's none of the above!

        // If size not specified, try to use exact image size to prevent blurring
        if (uiSizeX == D3DX_DEFAULT)
            uiSizeX = D3DX_DEFAULT_NONPOW2;
        if (uiSizeY == D3DX_DEFAULT)
            uiSizeY = D3DX_DEFAULT_NONPOW2;

        if (FAILED(D3DXCreateTextureFromFileEx(m_pDevice, strFilename, uiSizeX, uiSizeY, iMipMaps, 0, D3DFormat, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0,
                                               NULL, NULL, (IDirect3DTexture9**)&m_pD3DTexture)))
            return;

        // Update surface size if it's a normal texture
        D3DSURFACE_DESC desc;
        ((IDirect3DTexture9*)m_pD3DTexture)->GetLevelDesc(0, &desc);
        m_uiSurfaceSizeX = desc.Width;
        m_uiSurfaceSizeY = desc.Height;
    }

    // Calc memory usage
    m_iMemoryKBUsed = CRenderItemManager::CalcD3DResourceMemoryKBUsage(m_pD3DTexture);
}
コード例 #13
0
ファイル: Surface.cpp プロジェクト: vgck/archive
bool Surface::loadSurface(LPDIRECT3DDEVICE9 device, std::string filename)
{
	imageScale = 100; //set our image scale to 100%
	//record the height and width

	HRESULT hResult;
	// Get the width and height of the image
	D3DXIMAGE_INFO imageInfo;
	hResult = D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo);
	if FAILED (hResult){
		return false;
	}

	height = imageInfo.Height;
	width = imageInfo.Width;

	//create the Off Screen Surface
	hResult = device->CreateOffscreenPlainSurface(width, //surface width
		height, //surface height
		D3DFMT_A8R8G8B8, //surface format, D3DFMT_A8R8G8B8 is a 32 bit format with 8 alpha bits
		D3DPOOL_DEFAULT, //create it in the default memory pool
		&surface, //the pointer to our surface 
		NULL
		);

	if (FAILED(hResult))
		return false;

	//load the surface from the a file
	hResult = D3DXLoadSurfaceFromFile(surface, //the surface we just created
		NULL, //palette entry, NULL for non 256 color formats
		NULL, //dest rect, NULL for the whole surface
		filename.c_str(), // the file we wish to load
		NULL, // Source Rect, NULL for the whole file
		D3DX_DEFAULT, //Filter 
		0, // Color key, color that should be used as transparent.
		NULL // pointer to a D3DXIMAGE_INFO structure, for holding info about the image.
		);

	if (FAILED(hResult))
		return false;

	//set rects
	destRect.left = 0;
	destRect.top = 0;
	destRect.bottom = destRect.top + height;
	destRect.right = destRect.left + width;

	srcRect.left = 0;
	srcRect.top = 0;
	srcRect.bottom = destRect.top + height;
	srcRect.right = destRect.left + width;

	return true;
}
コード例 #14
0
ファイル: GERenderingObjects.cpp プロジェクト: bvk76/demos
void GESprite::loadFromFile(const char* Filename)
{
    D3DXCreateSprite(d3ddev, &sSprite);
    D3DXCreateTextureFromFile(d3ddev, Filename, &sTexture);

    D3DXIMAGE_INFO d3dImageInfo;
    D3DXGetImageInfoFromFile(Filename, &d3dImageInfo);

    vCenter.x = d3dImageInfo.Width / 2.0f;
    vCenter.y = d3dImageInfo.Height / 2.0f;
    vCenter.z = 0.0f;
}
コード例 #15
0
ファイル: Surface.cpp プロジェクト: AaronDnz/xbmc
bool CSurface::CreateFromFile(const char *Filename, FORMAT format)
{
  // get the info from the file
	D3DXIMAGE_INFO info;
	if (S_OK != D3DXGetImageInfoFromFile(Filename, &info))
    return false;

  if (!Create(info.Width, info.Height, format))
    return false;

	bool success = (S_OK == D3DXLoadSurfaceFromFile(m_surface, NULL, NULL, Filename, NULL, D3DX_FILTER_NONE, 0, NULL));
  ClampToEdge();
  return success;
}
コード例 #16
0
bool CTexture::LoadFile()
{
	LPDIRECT3DDEVICE9 l_device = CORE->GetRenderManager()->GetDevice();	
	HRESULT tex = D3DXCreateTextureFromFile(l_device, m_FileName.c_str(), &m_Texture);

  D3DXIMAGE_INFO pSrcInfo;
	HRESULT info = D3DXGetImageInfoFromFile(m_FileName.c_str(), &pSrcInfo);	
	
	m_Width = pSrcInfo.Width;
	m_Height = pSrcInfo.Height;
	
	int type = pSrcInfo.ImageFileFormat;
	return (tex==D3D_OK);
}
コード例 #17
0
ファイル: CEnemy1.cpp プロジェクト: kjngstars/GameProject2015
void CEnemy1::InitializeTexture(IDirect3DDevice9* pD3DDevice)
{
	if (CEnemy1::texture != nullptr)
		CEnemy1::texture->Release();

	D3DXIMAGE_INFO info;
	HR(D3DXGetImageInfoFromFile("./Content/Enemies/Enemy1.png", &info));
	HR(D3DXCreateTextureFromFileEx(
		pD3DDevice, "./Content/Enemies/Enemy1.png",
		info.Width, info.Height, D3DX_DEFAULT, 0,
		D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
		D3DX_DEFAULT, D3DX_DEFAULT,
		0, &info, 0, &CEnemy1::texture));
}
コード例 #18
0
/*
	loadTexture - This method loads a texture with a path/file name key into
	the GPU memory. It registers the path/file name in the wchar_t table and
	returns the corresponding index. Once the texture is created, it loads
	it into the map.
*/
unsigned int DirectXTextureManager::loadTexture(wstring key)
{
	// USED FOR READING BITMAP FILE INFO
    D3DXIMAGE_INFO info;

	// CONVERT THE FILE NAME INTO A WINDOW LONG CHAR wchar_t (LPCWSTR)
	LPCWSTR fileName = key.c_str();

    // GET THE IMAGE SIZE FROM THE IMAGE FILE
    HRESULT result = D3DXGetImageInfoFromFile(fileName, &info);

	// IF THE IMAGE FILE WAS FOUND
	if (result == S_OK)
	{
		// GET THE COLOR KEY, WE'LL NEED THIS FOR LOADING OUR IMAGE
		D3DCOLOR colorKey = ((DirectXGraphics*)graphics)->getColorKey();

		LPDIRECT3DDEVICE9 graphicsDevice = ((DirectXGraphics*)graphics)->getGraphicsDevice();
		LPDIRECT3DTEXTURE9 textureToLoad;

		// CREATE A NEW TEXTURE
		result = D3DXCreateTextureFromFileEx(
			graphicsDevice,		// GPU
			fileName,			// BITMAP FILE PATH/NAME
			info.Width,			// BITMAP IMAGE WIDTH
			info.Height,		// BITMAP IMAGE HEIGHT
			1,					// MIP-MAP LEVELS (1 FOR NO CHAIN)
			D3DPOOL_DEFAULT,	// THE TYPE OF SURFACE (STANDARD)
			D3DFMT_UNKNOWN,		// SURFACE FORMAT (DEFAULT)
			D3DPOOL_DEFAULT,	// MEMORY CLASS FOR THE TEXTURE
			D3DX_DEFAULT,		// IMAGE FILTER
			D3DX_DEFAULT,		// MIP FILTER
			colorKey,			// COLOR KEY
			&info,				// BITMAP FILE INFO
			NULL,				// COLOR PALETTE
			&textureToLoad );	// THE TEXTURE WE ARE CREATING AND LOADING

		// PUT OUR LOADED TEXTURE INTO OUR MAP
		textures[fileName] = textureToLoad;

		// NOW PUT THE KEY IN THE wchar_t TABLE
		int indexOfTexture = wstringTable.putWStringInTable(fileName);

		// AND RETURN THE TEXTURE'S ID
		return indexOfTexture;
	}
	else
		return -1;
}
コード例 #19
0
void Bitmap::Load(char* file)
{
	if (!surface)
	{
		D3DXGetImageInfoFromFile(file, &imageInfo);
		m_pd3dDevice->CreateOffscreenPlainSurface(imageInfo.Width, imageInfo.Height, m_d3dsdBackBuffer.Format, D3DPOOL_SYSTEMMEM, &surface, NULL);
	}

	if (SUCCEEDED(D3DXLoadSurfaceFromFile(surface, NULL, NULL, file, NULL, D3DX_FILTER_NONE, 0, NULL)))
		bitmapLoaded=true;
	
	assert(surface);

	assert(bitmapLoaded);
}
コード例 #20
0
Sprite::Sprite(LPD3DXSPRITE SpriteHandler, char* Path, int Width, int Height, int Count, int SpritePerRow)
{
    D3DXIMAGE_INFO info;
    HRESULT result;

    this->_Image = NULL;
    this->_SpriteHandler = SpriteHandler;
    this->_Width = Width;
    this->_Height = Height;
    this->_Count = Count;
    this->_SpritePerRow = SpritePerRow;
    this->_Index = 0;

    this->_CurrentSpriteLocation.x = 0.0f;
    this->_CurrentSpriteLocation.y = 0.0f;
    this->_CurrentSpriteLocation.z = 0.0f;

    result = D3DXGetImageInfoFromFile(Path, &info);
    if (result != D3D_OK)
    {
        int i = 10;
    }

    LPDIRECT3DDEVICE9 d3ddv;
    SpriteHandler->GetDevice(&d3ddv);

    result = D3DXCreateTextureFromFileEx(
                 d3ddv,
                 Path,
                 info.Width,
                 info.Height,
                 1,
                 D3DUSAGE_DYNAMIC,
                 D3DFMT_UNKNOWN,
                 D3DPOOL_DEFAULT,
                 D3DX_DEFAULT,
                 D3DX_DEFAULT,
                 D3DCOLOR_XRGB(88, 1, 0),
                 &info,
                 NULL,
                 &_Image);

    if (result != D3D_OK)
    {
        int i = 10;
    }

}
コード例 #21
0
ファイル: ccUnit.cpp プロジェクト: arlukin/dev
HRESULT ccUnit::loadUnit()
{
	//
	// Create surfaces.
	//

	HRESULT hr;
	IDirect3DSurface9 *ppBackBuffer;
	if (SUCCEEDED(hr = m_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &ppBackBuffer)))
	{
		D3DSURFACE_DESC d3dsDesc;
		ppBackBuffer->GetDesc(&d3dsDesc);		
				
		char fileName[] = "..//units//armbulldog.bmp";
		
		if (FAILED(hr = D3DXGetImageInfoFromFile(
			fileName,
			&m_srcInfo)))
			return hr;

		m_unitSize.cx = m_srcInfo.Width;
		m_unitSize.cy = m_srcInfo.Height;

		m_unitRect.right  += m_unitSize.cx;
		m_unitRect.bottom += m_unitSize.cy;
				
		if (FAILED(hr = m_pd3dDevice->CreateOffscreenPlainSurface(
			m_srcInfo.Width, m_srcInfo.Height, d3dsDesc.Format, D3DPOOL_DEFAULT, &m_pUnitImage, NULL)))
			return hr;				

		if (FAILED(hr = D3DXLoadSurfaceFromFile(          
			m_pUnitImage,
			NULL,
			NULL,
			fileName,
			NULL,
			D3DX_FILTER_NONE,
			0x7B97FF,
			&m_srcInfo
		)))
			return hr;
		
	}
	SAFE_RELEASE(ppBackBuffer);

	return S_OK;
}
コード例 #22
0
CSprite::CSprite(LPD3DXSPRITE SpriteHandler, LPWSTR FilePath, int Width, int Height, int Count, int SpritePerRow)
{
    D3DXIMAGE_INFO info;
    HRESULT result;

    _Image = NULL;
    _SpriteHandler = SpriteHandler;

    _Width = Width;
    _Height = Height;
    _Count = Count;
    _SpritePerRow = SpritePerRow;
    _Index = 0;

    result = D3DXGetImageInfoFromFile(FilePath, &info);
    if (result != D3D_OK)
    {
        //trace(L"[ERROR] Failed to get information from image file '%s'", FilePath);
        return;
    }

    LPDIRECT3DDEVICE9 d3ddv;
    SpriteHandler->GetDevice(&d3ddv);

    result = D3DXCreateTextureFromFileEx(
                 d3ddv,
                 FilePath,
                 info.Width,
                 info.Height,
                 1,
                 D3DUSAGE_DYNAMIC,
                 D3DFMT_UNKNOWN,
                 D3DPOOL_DEFAULT,
                 D3DX_DEFAULT,
                 D3DX_DEFAULT,
                 D3DCOLOR_XRGB(255, 0, 255), // 176, 224, 248
                 &info,
                 NULL,
                 &_Image);

    if (result != D3D_OK)
    {
        //trace(L"[ERROR] Failed to create texture from file '%s'", FilePath);
        return;
    }
}
コード例 #23
0
ファイル: texture_manager.cpp プロジェクト: boxp/Pendulum
//**************************************************************************
//内部参照用ロード関数
//**************************************************************************
//イメージファイルからDxTextureをロード  (簡易版)
HRESULT TextureManager::LoadTextureFromFile(DxTexture* tex,const string& fName,const string& path)
{
	HRESULT hr=S_OK;
	string  str = path + fName;

	D3DXGetImageInfoFromFile(str.c_str(),&tex->info);

	if(FAILED(D3DXCreateTextureFromFile(this->dev,str.c_str(),&tex->lpTex)))
	{
		return E_FAIL;
	}

	//ファイル名の設置
	tex->file_name += fName;

  return S_OK;
}
コード例 #24
0
/** Load the given bitmap file into a surface; returns a pointer to said surface */
LPDIRECT3DSURFACE9 DirectXStuff::loadSurface(string bitmapName)
{
	LPDIRECT3DSURFACE9 image = NULL;

	//Get width and height of bitmap file
	D3DXIMAGE_INFO info;
	HRESULT result = D3DXGetImageInfoFromFile(bitmapName.c_str(), &info);

	if (result != D3D_OK) { //Unsuccessful
		return NULL;
	}

	//Create a surface for the image
	result = d3ddev->CreateOffscreenPlainSurface(
		info.Width, //surface height
		info.Height, //surface width
		D3DFMT_X8R8G8B8, //image format
		D3DPOOL_DEFAULT, //memory pool to use
		&image, //pointer to surface
		NULL //reserved (always NULL)
	);

	if (result != D3D_OK) {
		return NULL;
	}

	//load bitmap file into the surface we just created
	result = D3DXLoadSurfaceFromFile(
		image, //Destination surface
		NULL, //destination palette
		NULL, //destination rectangle
		bitmapName.c_str(), //source bitmap file name
		NULL, //source rectangle
		D3DX_DEFAULT, //controls how image is filtered
		D3DCOLOR_XRGB(0, 0, 0), //for transparancy (0 for none)
		NULL); //source image info (usually NULL)

	//make sure file was loaded okay
	if (result != D3D_OK) { 
		return NULL;
	}

	return image;
}
コード例 #25
0
ファイル: graphics.cpp プロジェクト: Danice123/DungeonCrawler
//=============================================================================
// Load the texture into default D3D memory (normal texture use)
// For internal engine use only. Use the TextureManager class to load game textures.
// Pre: filename is name of texture file.
//      transcolor is transparent color
// Post: width and height = size of texture
//       texture points to texture
// Returns HRESULT
//=============================================================================
HRESULT Graphics::loadTexture(const char *filename, COLOR_ARGB transcolor,
                                UINT &width, UINT &height, LP_TEXTURE &texture)
{
    // The struct for reading file info
    D3DXIMAGE_INFO info;
    result = E_FAIL;

    try{
        if(filename == NULL)
        {
            texture = NULL;
            return D3DERR_INVALIDCALL;
        }
    
        // Get width and height from file
        result = D3DXGetImageInfoFromFile(filename, &info);
        if (result != D3D_OK)
            return result;
        width = info.Width;
        height = info.Height;
    
        // Create the new texture by loading from file
        result = D3DXCreateTextureFromFileEx( 
            device3d,           //3D device
            filename,           //image filename
            info.Width,         //texture width
            info.Height,        //texture height
            1,                  //mip-map levels (1 for no chain)
            0,                  //usage
            D3DFMT_UNKNOWN,     //surface format (default)
            D3DPOOL_DEFAULT,    //memory class for the texture
            D3DX_DEFAULT,       //image filter
            D3DX_DEFAULT,       //mip filter
            transcolor,         //color key for transparency
            &info,              //bitmap file info (from loaded file)
            NULL,               //color palette
            &texture );         //destination texture

    } catch(...)
    {
        throw(GameError(gameErrorNS::FATAL_ERROR, "Error in Graphics::loadTexture"));
    }
    return result;
}
コード例 #26
0
	void DirectXTexture::loadFromFile(const std::string& _filename)
	{
		destroy();
		mTextureUsage = TextureUsage::Default;
		mPixelFormat = PixelFormat::R8G8B8A8;
    
		std::string fullname = DirectXDataManager::getInstance().getDataPath(_filename);

		D3DXIMAGE_INFO info;
		D3DXGetImageInfoFromFile(fullname.c_str(), &info);

		if (info.Format == D3DFMT_A8R8G8B8)
		{
			mPixelFormat = PixelFormat::R8G8B8A8;
			mNumElemBytes = 4;
		}
		else if (info.Format == D3DFMT_R8G8B8)
		{
			mPixelFormat = PixelFormat::R8G8B8;
			mNumElemBytes = 3;
		}
		else if (info.Format == D3DFMT_A8L8)
		{
			mPixelFormat = PixelFormat::L8A8;
			mNumElemBytes = 2;
		}
		else if (info.Format == D3DFMT_L8)
		{
			mPixelFormat = PixelFormat::L8;
			mNumElemBytes = 1;
		}
		else
		{
			//exception
		}

		mSize.set(info.Width, info.Height);
		if (FAILED(D3DXCreateTextureFromFile(mpD3DDevice, fullname.c_str(), &mpTexture)))
		{
			char buf[1024];
			sprintf(buf, "texture = %s\nloaded failed!", _filename.c_str());
			MessageBox(0, buf, 0, MB_ICONERROR);
		}
	}
コード例 #27
0
    void DirectXTexture::loadFromFile(const std::string& _filename)
    {
        destroy();
        mTextureUsage = TextureUsage::Default;
        mPixelFormat = PixelFormat::R8G8B8A8;
        mNumElemBytes = 4;

        std::string fullname = DirectXDataManager::getInstance().getDataPath(_filename);

        D3DXIMAGE_INFO info;
        D3DXGetImageInfoFromFile(fullname.c_str(), &info);

        if (info.Format == D3DFMT_A8R8G8B8)
        {
            mPixelFormat = PixelFormat::R8G8B8A8;
            mNumElemBytes = 4;
        }
        else if (info.Format == D3DFMT_R8G8B8)
        {
            mPixelFormat = PixelFormat::R8G8B8;
            mNumElemBytes = 3;
        }
        else if (info.Format == D3DFMT_A8L8)
        {
            mPixelFormat = PixelFormat::L8A8;
            mNumElemBytes = 2;
        }
        else if (info.Format == D3DFMT_L8)
        {
            mPixelFormat = PixelFormat::L8;
            mNumElemBytes = 1;
        }

        mSize.set(info.Width, info.Height);
        HRESULT result = D3DXCreateTextureFromFile(mpD3DDevice, fullname.c_str(), &mpTexture);
        if (FAILED(result))
        {
            MYGUI_PLATFORM_EXCEPT("Failed to load texture '" << _filename <<
                "' (error code " << result <<
                "): size '" << mSize <<
                "' format '" << info.Format << "'."
                );
        }
    }
コード例 #28
0
LPDIRECT3DSURFACE9 LoadSurface(char* fileName, D3DCOLOR transColor) {
    LPDIRECT3DSURFACE9 image = NULL;
    D3DXIMAGE_INFO info;
    HRESULT hr;

    hr = D3DXGetImageInfoFromFile(fileName, &info);
    if (hr != D3D_OK)
        return NULL;

    hr = d3dDev->CreateOffscreenPlainSurface(info.Width, info.Height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &image, NULL);
    if (hr != D3D_OK)
        return NULL;

    hr = D3DXLoadSurfaceFromFile(image, NULL, NULL, fileName, NULL, D3DX_DEFAULT, transColor, NULL);
    if (hr != D3D_OK)
        return NULL;

    return image;
}
コード例 #29
0
ファイル: Sprite.cpp プロジェクト: nguyenhaidang94/GameMario
Sprite::Sprite(LPD3DXSPRITE SpriteHandler, LPWSTR Path, double Width, double Height, int Count, int SpritePerRow, D3DCOLOR TransparentColor)
{
	D3DXIMAGE_INFO info;
	HRESULT result;

	_Image = NULL;
	_SpriteHandler = SpriteHandler;

	_Width = Width;
	_Height = Height;
	_Count = Count;
	_SpritePerRow = SpritePerRow;

	result = D3DXGetImageInfoFromFile(Path, &info);
	if (result != D3D_OK)
	{
		return;
	}

	LPDIRECT3DDEVICE9 d3ddv;
	SpriteHandler->GetDevice(&d3ddv);

	result = D3DXCreateTextureFromFileEx(
		d3ddv,
		Path,
		info.Width, 
		info.Height,
		1,				//Mipmap levels
		D3DUSAGE_DYNAMIC,
		D3DFMT_UNKNOWN,
		D3DPOOL_DEFAULT,
		D3DX_DEFAULT,
		D3DX_DEFAULT,
		TransparentColor,		// Transparent color
		&info,				// Image information
		NULL,
		&_Image);			// Result
	if (result != D3D_OK)
	{
		return;
	}
}
コード例 #30
0
//=============================================================================
// loadTexture
//=============================================================================
HRESULT Graphics::loadTexture(const char *filename, COLOR_ARGB transcolor, UINT &width, UINT &height, LP_TEXTURE &texture)
{
    // The struct for reading file info
    D3DXIMAGE_INFO info;
    result = E_FAIL;
    try {
        if (filename == NULL)
        {
            texture = NULL;
            return D3DERR_INVALIDCALL;
        }

        // Get width and height from file
        result = D3DXGetImageInfoFromFile(filename, &info);
        if (result != D3D_OK)
            return result;
        width = info.Width;
        height = info.Height;

        // Create the new texture by loading from file
        result = D3DXCreateTextureFromFileEx(device3d,
                                             filename,
                                             info.Width,
                                             info.Height,
                                             1,
                                             0,
                                             D3DFMT_UNKNOWN,
                                             D3DPOOL_DEFAULT,
                                             D3DX_DEFAULT,
                                             D3DX_DEFAULT,
                                             transcolor,
                                             &info,
                                             NULL,
                                             &texture);

    }
    catch (...)
    {
        throw(GameError(gameErrorNS::FATAL_ERROR, "Error in Graphics::loadTexture"));
    }
    return result;
}