Ejemplo n.º 1
0
	void SPTexture::Load( SPString setPath )
	{
		D3DXIMAGE_INFO i;
		//PALETTEENTRY p; Don't know why we cannot make use of both palette and info.
		// Ether of them is used.

		// Open texture file.
		SPFilePtr file = SPFileManager::GetSingleton()->OpenFile(setPath);
		
		if (!file)
		{
			SPLogHelper::WriteLog(L"[SPGraphics] WARNING: Failed to open file: " + setPath);
			return;
		}

		// Read file data.
		LONGLONG length = file->GetFileLength();
		char* pData = new char[(unsigned int)length];
		
		if (!file->Read(pData, (DWORD)length))
		{
			SPLogHelper::WriteLog(L"[SPGraphics] WARNING: Failed to read file: " + setPath);
			return;
		}		

		SPGameManager::GetSingleton()->GetGame()->LockDrawing();

		// Create texture from memory.
		HRESULT hr = D3DXCreateTextureFromFileInMemoryEx(
			SPDevice::GetSingleton()->GetD3DDevice(), 
			pData, (UINT)length,
			D3DX_DEFAULT_NONPOW2,
			D3DX_DEFAULT_NONPOW2,
			D3DX_FROM_FILE,	0,
			D3DFMT_A8R8G8B8,
			D3DPOOL_MANAGED,
			D3DX_FILTER_TRIANGLE, 
			D3DX_FILTER_TRIANGLE,
			D3DCOLOR_RGBA(0,0,0,0),
			&i, NULL,
			&texture);

		SPGameManager::GetSingleton()->GetGame()->UnlockDrawing();

		// Close texture file.
		SPFileManager::GetSingleton()->CloseFile(setPath);
		delete [] pData;
		pData = NULL;
		if (FAILED(hr))
		{
			texture = NULL;
			return;
		}
	
		path = setPath;
		height = i.Height;
		width = i.Width;
		format = D3DFMT_A8R8G8B8;
	}
Ejemplo n.º 2
0
	bool SPInputManager::SetCursor( SPString path )
	{
		SPFilePtr file = SPFileManager::GetSingleton().OpenFile(path);

		if (!file)
		{
			return false;
		}

		LONGLONG length = file->GetFileLength();
		char* pData = new char[length];
		file->Read(pData, length);

		wchar_t tname[10];		
		_wtmpnam_s(tname, 10);

		SPString name = SPString(tname);// + path.substr(path.find_last_of(L".") + 1);

		HANDLE newFile = CreateFile(name.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL,
			CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

		if (newFile == INVALID_HANDLE_VALUE)
		{
			return false;
		}

		DWORD numOfByte;
		if(FALSE == WriteFile(newFile, pData, length, &numOfByte, NULL))
		{ 
			delete [] pData;
			SPFileManager::GetSingleton().CloseFile(path);
			CloseHandle(newFile);
			DeleteFile(name.c_str());
			return false;
		}

		CloseHandle(newFile);
		HCURSOR cursor = LoadCursorFromFile(name.c_str());
		if (!cursor)
		{
			DWORD err = GetLastError();
			delete [] pData;
			SPFileManager::GetSingleton().CloseFile(path);
			CloseHandle(newFile);
			DeleteFile(name.c_str());
			return false;
		}

		SPWindow::GetSingleton().SetCursor(cursor);

		DeleteFile(name.c_str());

		delete [] pData;
		SPFileManager::GetSingleton().CloseFile(path);
		//CloseHandle(newFile);

		return true;
	}
Ejemplo n.º 3
0
	bool SPPixelShaderCore::Load( SPString path )
	{
		name = path;

		SPFilePtr file = SPFileManager::GetSingleton().OpenFile(path);

		if (!file)
		{
			SPLogHelper::WriteLog(L"[SPShader] WARNING: Failed to open shader file: " + path);
			return false;
		}

		ID3DXBuffer* shaderBuffer = NULL;
		ID3DXBuffer* errorBuffer = NULL;
		LONGLONG length = file->GetFileLength();
		char* pData = new char[(UINT)length];

		if(!file->Read(pData, (DWORD)length))
		{
			SPLogHelper::WriteLog(L"[SPShader] WARNING: Failed to read shader file: " + path);
			return false;
		}

		// Compile shader files.
		HRESULT hr = D3DXCompileShader(
			pData, (UINT)length, 0, 0, "Main", "ps_2_0", D3DXSHADER_DEBUG,
			&shaderBuffer, &errorBuffer, &constantTable);

		delete [] pData;
		SPFileManager::GetSingleton().CloseFile(path);

		if (errorBuffer)
		{
			SPLogHelper::WriteLog(L"[SPShader] WARNING: There is error in shader file: " + path);
			SPLogHelper::WriteLog("[SPShader] Message: " + string((char*)errorBuffer->GetBufferPointer()));
			errorBuffer->Release();
		}

		if (FAILED(hr))
		{
			SPLogHelper::WriteLog(L"[SPShader] WARNING: Failed to compile shader file: " + path);
			return false;
		}

		// Create pixel shader.
		hr = SPDevice::GetSingleton().GetD3DDevice()->CreatePixelShader(
			(DWORD*)shaderBuffer->GetBufferPointer(), &pixelShader);

		if (FAILED(hr))
		{
			SPLogHelper::WriteLog(L"[SPShader] WARNING: Failed to create pixel shader");

			if (shaderBuffer)
			{
				shaderBuffer->Release();
				shaderBuffer = NULL;
			}

			return false;
		}

		shaderBuffer->Release();
		shaderBuffer = NULL;

		return true;
	}
Ejemplo n.º 4
0
	BOOL SPFileSourceFilter::ReadTheFile(LPCTSTR lpszFileName)
	{
		//DWORD dwBytesRead;

		// Open the requested file

		wstring wName = lpszFileName;
		SPString name = SPString(wName.begin(), wName.end());

		SPFilePtr file = SPFileManager::GetSingleton().OpenFile(name);

		if (!file)
		{
			SPLogHelper::WriteLog(L"[DShow] WARNING: Failed to open video file: " + name);
			return FALSE;
		}

		//HANDLE hFile = CreateFile(lpszFileName,
		//	GENERIC_READ,
		//	FILE_SHARE_READ,
		//	NULL,
		//	OPEN_EXISTING,
		//	0,
		//	NULL);

		//if (hFile == INVALID_HANDLE_VALUE) 
		//{
		//	DbgLog((LOG_TRACE, 2, TEXT("Could not open %s\n"), lpszFileName));
		//	return FALSE;
		//}

		// Determine the file size
		//ULARGE_INTEGER uliSize;
		//uliSize.LowPart = GetFileSize(hFile, &uliSize.HighPart);

		PBYTE pbMem = new BYTE[(unsigned int)file->GetFileLength()];

		if (pbMem == NULL) 
		{
			//CloseHandle(hFile);
			SPLogHelper::WriteLog("[DShow] WARNING: Failed to create buffer!");
			SPFileManager::GetSingleton().CloseFile(name);
			return FALSE;
		}

		// Read the data from the file
		//if (!ReadFile(hFile,
		//	(LPVOID) pbMem,
		//	uliSize.LowPart,
		//	&dwBytesRead,
		//	NULL) ||
		//	(dwBytesRead != uliSize.LowPart))
		//{
		//	DbgLog((LOG_TRACE, 1, TEXT("Could not read file\n")));

		//	delete [] pbMem;
		//	CloseHandle(hFile);
		//	return FALSE;
		//}
		if(!file->Read(pbMem, (DWORD)file->GetFileLength()))
		{
			delete [] pbMem;
			SPLogHelper::WriteLog("[DShow] WARNING: Failed to read file!");
			SPFileManager::GetSingleton().CloseFile(name);
			return FALSE;
		}

		// Save a pointer to the data that was read from the file
		m_pbData = pbMem;
		//m_llSize = (LONGLONG)uliSize.QuadPart;
		m_llSize = file->GetFileLength();

		// Close the file
		//CloseHandle(hFile);

		SPFileManager::GetSingleton().CloseFile(name);

		return TRUE;
	}
Ejemplo n.º 5
0
	SPString SPFontHelper::GetFontNameFromFile(SPString path)
	{
		SPFilePtr file;
		SPString result;

		file = SPFileManager::GetSingleton()->OpenFile(path);

		if (file)
		{
			TT_OFFSET_TABLE ttOffsetTable;
			file->Read(&ttOffsetTable, sizeof(TT_OFFSET_TABLE));
			ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
			ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
			ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);

			//check is this is a true type font and the version is 1.0
			if(ttOffsetTable.uMajorVersion != 1 || ttOffsetTable.uMinorVersion != 0)
			{
				return result;
			}

			TT_TABLE_DIRECTORY tblDir;
			BOOL bFound = FALSE;
			SPString tempString;

			for(int i = 0; i < ttOffsetTable.uNumOfTables; i++)
			{
				file->Read(&tblDir, sizeof(TT_TABLE_DIRECTORY));

				char* buffer = new char[5];
				strncpy_s(buffer, 5, tblDir.szTag, 4);
				string s = buffer;
				delete [] buffer;
				buffer = NULL;
				if(s == "name")
				{
					bFound = TRUE;
					tblDir.uLength = SWAPLONG(tblDir.uLength);
					tblDir.uOffset = SWAPLONG(tblDir.uOffset);
					break;
				}
			}

			if(bFound)
			{
				file->SetPosition(tblDir.uOffset);
				TT_NAME_TABLE_HEADER ttNTHeader;
				file->Read(&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER));
				ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
				ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
				TT_NAME_RECORD ttRecord;
				bFound = FALSE;

				for(int i=0; i<ttNTHeader.uNRCount; i++)
				{
					file->Read(&ttRecord, sizeof(TT_NAME_RECORD));
					ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
					if(ttRecord.uNameID == 1)
					{
						ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
						ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
						int nPos = file->GetPosition();
						file->SetPosition(tblDir.uOffset + ttRecord.uStringOffset + ttNTHeader.uStorageOffset);

						char* buffer = new char[ttRecord.uStringLength + 1];
						file->Read(buffer, ttRecord.uStringLength);
						string s = buffer;
						delete [] buffer;
						buffer = NULL;
						if(s.size() > 0)
						{
							result = SPStringHelper::ToWString(s);
							break;
						}
						file->SetPosition(nPos);
					}
				}			
			}
			
			SPFileManager::GetSingleton()->CloseFile(path);
		}

		return result;
	}