Ejemplo n.º 1
0
int main()
{
	SetConsoleTitle("Test");
	while((hwnd = FindWindow(NULL,"Test"))==NULL);
	hdc = GetDC(hwnd);
	GetClientRect(hwnd,&g_rect);
	buffer = CreateCompatibleDC(hdc);
	g_bitmap = CreateCompatibleDC(hdc);
	bmp = CreateCompatibleBitmap(hdc,g_rect.right,g_rect.bottom);;

	TGA::TgaData m;
	try
	{
//		tgaTest.tga
		TGA::TgaLoader::getLoader().loadFile("tgaTest.tga",&m);
		printf("Succeed so far.\r\n");
		for(int i=0;i<m.getHeight();i++)
		{
			for(int j=0;j<m.getWidth();j++)
			{
				auto& color = m.getColDataPtr()[i * m.getWidth() + j];
				pixDraw(buffer,j,i,color.r,color.g,color.b);
			}
		}
	}
	catch(const std::exception& e)
	{
		printf("%s\r\n",e.what());
	}
	BitBlt(hdc,0,0,g_rect.right - g_rect.left,g_rect.bottom - g_rect.top,buffer,0,0,SRCCOPY);
	return 0;
}
Ejemplo n.º 2
0
HRESULT TextureObject::LoadFile(ID3D11Device* device,
	ID3D11DeviceContext* context,
	MutableString&& filename)
{
	HRESULT hr;
	if (SRV != nullptr)
	{
		return E_FAIL;
	}
	std::string filePath = filename.getMultiByteString();
	if (TGA::TgaLoader::getLoader().judgeTga(filePath.c_str()))
	{
		TGA::TgaData data;
		TGALOAD(filePath.c_str(), &data);
		long pixelCount = long(data.getHeight()) * long(data.getWidth());

		hr = LoadMemory(device, context, data.getWidth(), data.getHeight(), 
			data.getColDataPtr(),
			sizeof(XMFLOAT4)* pixelCount);
		if (FAILED(hr))
		{
			return E_FAIL;
		}
	}
	else
	{
		hr = D3DX11CreateShaderResourceViewFromFile(
			device, 
			filename.getWideString().c_str(),
			nullptr,
			nullptr,
			&SRV,
			nullptr);
		if (FAILED(hr))
		{
			return E_FAIL;
		}
	}
	is_init = true;
	return S_OK;
}