示例#1
0
void CloudShader::createBuffers(ID3D11Device* pd3dDevice)
{
	// Create the 3 constant buffers, using the same buffer descriptor to create all three
	D3D11_BUFFER_DESC Desc;
	ZeroMemory(&Desc, sizeof(Desc));
	Desc.Usage = D3D11_USAGE_DEFAULT;
	Desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	Desc.CPUAccessFlags = 0;
	Desc.MiscFlags = 0;

	Desc.ByteWidth = sizeof(CB_VS_PER_OBJECT);
	pd3dDevice->CreateBuffer(&Desc, NULL, &cbVSPerObject);
	DXUT_SetDebugName(cbVSPerObject, "CB_VS_PER_OBJECT_CLOUD");

	Desc.ByteWidth = sizeof(CB_PS_PER_OBJECT);
	pd3dDevice->CreateBuffer(&Desc, NULL, &cbPSPerObject);
	DXUT_SetDebugName(cbPSPerObject, "CB_PS_PER_OBJECT_CLOUD");

	// also initialize the wind textures
	D3DX11CreateShaderResourceViewFromFile(pd3dDevice,
		L"Media\\Grass\\Wind1.png",
		NULL, NULL,
		&txWind1,
		NULL);
	DXUT_SetDebugName(txWind1, "TEX_WIND1_CLOUD");

	D3DX11CreateShaderResourceViewFromFile(pd3dDevice,
		L"Media\\Grass\\Wind2.png",
		NULL, NULL,
		&txWind2,
		NULL);
	DXUT_SetDebugName(txWind2, "TEX_WIND2_CLOUD");
}
bool TextureArrayClass::Initialize(ID3D11Device* device, WCHAR* filename1, WCHAR* filename2, WCHAR* filename3)
{
	HRESULT result;


	// Load the first texture in.
	result = D3DX11CreateShaderResourceViewFromFile(device, filename1, NULL, NULL, &m_textures[0], NULL);
	if(FAILED(result))
	{
		return false;
	}

	// Load the second texture in.
	result = D3DX11CreateShaderResourceViewFromFile(device, filename2, NULL, NULL, &m_textures[1], NULL);
	if(FAILED(result))
	{
		return false;
	}

	// Load the third texture in.
	result = D3DX11CreateShaderResourceViewFromFile(device, filename3, NULL, NULL, &m_textures[2], NULL);
	if(FAILED(result))
	{
		return false;
	}
	return true;
}
bool TextureClass::Initialize(ID3D11Device* device, WCHAR* filename, WCHAR* filename2)
{
	HRESULT result;

	m_texture = new ID3D11ShaderResourceView*[2];

	// Load the texture in.
	result = D3DX11CreateShaderResourceViewFromFile(device, filename, NULL, NULL, &(m_texture[0]), NULL);
	if(FAILED(result))
	{
		return false;
	}
	
	if(filename2 != NULL)
	{
		result = D3DX11CreateShaderResourceViewFromFile(device, filename2, NULL, NULL, &(m_texture[1]), NULL);
		if(FAILED(result))
		{
			return false;
		}
	}
	else
	{
		m_texture[1] = 0;
	}
	return true;
}
bool LightingDemo2::init()
{
    if (RenderCore::init() == false)
    {
        return false;
    }

    mWaves.Init(160, 160, 1.0f, 0.03f, 5.0f, 0.3f);

    // Must init Effects first since InputLayouts depend on shader signatures.
    EffectMgr::initAll(md3dDevice);
    InputLayoutMgr::initAll(md3dDevice);
    RenderStateMgr::initAll(md3dDevice);

    HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"../Textures/grass.dds", 0, 0, &mGrassMapSRV, 0 ));
    HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"../Textures/water2.dds", 0, 0, &mWavesMapSRV, 0 ));
    HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"../Textures/WireFence.dds", 0, 0, &mBoxMapSRV, 0 ));
    HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"../Textures/cig_texture2.dds", 0, 0, &mCigMapSRV, 0 ));

    //buildSceneBuffers();
    buildSkull();
    buildCigar();
    buildBox();
    buildLand();
    buildWave();

    return true;
}
示例#5
0
void TreeBillboardApp::InitFX()
{
    // Must init Effects first since InputLayouts depend on shader signatures.
	Effects::InitAll(m_dxDevice.Get());
	InputLayouts::InitAll(m_dxDevice.Get());
	RenderStates::InitAll(m_dxDevice.Get());

	HR(D3DX11CreateShaderResourceViewFromFile(m_dxDevice.Get(), 
        "Textures/grass.dds", 0, 0, m_grassMapSRV.GetAddressOf(), 0 ));

    HR(D3DX11CreateShaderResourceViewFromFile(m_dxDevice.Get(), 
        "Textures/water2.dds", 0, 0, m_wavesMapSRV.GetAddressOf(), 0 ));

    HR(D3DX11CreateShaderResourceViewFromFile(m_dxDevice.Get(), 
        "Textures/WireFence.dds", 0, 0, m_boxMapSRV.GetAddressOf(), 0 ));

    std::vector<std::string> treeFilenames;
	treeFilenames.push_back("Textures/tree0.dds");
	treeFilenames.push_back("Textures/tree1.dds");
	treeFilenames.push_back("Textures/tree2.dds");
	treeFilenames.push_back("Textures/tree3.dds");

    //Create texture array view
    m_treeTextureMapArraySRV = dxHelper::CreateTexture2DArraySRV(
        m_dxDevice.Get(), m_dxImmediateContext.Get(), treeFilenames, DXGI_FORMAT_R8G8B8A8_UNORM);
}
示例#6
0
bool BlendApp::Init()
{
	if(!D3DApp::Init())
		return false;

	mWaves.Init(160, 160, 1.0f, 0.03f, 5.0f, 0.3f);

	// Must init Effects first since InputLayouts depend on shader signatures.
	BuildShaders();
	BuildInputLayout();
	RenderStates::InitAll(md3dDevice);

	HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice, 
		L"Textures/grass.dds", 0, 0, &mGrassMapSRV, 0 ));

	HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice, 
		L"Textures/water2.dds", 0, 0, &mWavesMapSRV, 0 ));

	HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice, 
		L"Textures/WireFence.dds", 0, 0, &mBoxMapSRV, 0 ));

	BuildLandGeometryBuffers();
	BuildWaveGeometryBuffers();
	BuildCrateGeometryBuffers();
	BuildConstBuffer();

	return true;
}
示例#7
0
//--------------------------------------------------------------------------------------
// JPE: Load Texture
//--------------------------------------------------------------------------------------
HRESULT loadTextures(ID3D11Device* d3d11Device)
{
	//LPCWSTR pathTexture = L"C:\\Users\\yapjpe\\Documents\\Visual Studio 2010\\Projects\\DirectXSamples\\Textures\\images.dds";
	LPCWSTR pathTexture = L"C:\\Users\\yapjpe\\Desktop\\tmp\\imagenes\\HexagonTile_DIFF.png";
	LPCWSTR pathNormalMap = L"C:\\Users\\yapjpe\\Desktop\\tmp\\imagenes\\mono_norm.jpg"; 
	LPCWSTR pathSpecularMap = NULL; // L"C:\\Users\\yapjpe\\Desktop\\tmp\\imagenes\\HexagonTile_SPEC.png";
	// jpg: circulo_norm  mono_norm cara_norm formas_norm  ice1_n  sandbag-diff sandbag-nor
	// png: rabbit-june5_2006-img_0075_nm.png HexagonTile_NRM HexagonTile_DIFF HexagonTile_SPEC

	HRESULT hr;
	hr = D3DX11CreateShaderResourceViewFromFile(d3d11Device, pathTexture,
		NULL, NULL, &m_texture, NULL);
	if (FAILED(hr))
	{
		return hr;
	}

	// Create a texture sampler state description.
	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.MipLODBias = 0.0f;
	samplerDesc.MaxAnisotropy = 1;
	samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
	samplerDesc.BorderColor[0] = 0;
	samplerDesc.BorderColor[1] = 0;
	samplerDesc.BorderColor[2] = 0;
	samplerDesc.BorderColor[3] = 0;
	samplerDesc.MinLOD = 0;
	samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

	// Create the texture sampler state.
	hr = d3d11Device->CreateSamplerState(&samplerDesc, &m_sampleState);
	if (FAILED(hr))
	{
		return hr;
	}

	// Carga el normal map.
	hr = D3DX11CreateShaderResourceViewFromFile(d3d11Device, pathNormalMap,
		NULL, NULL, &m_normalmap, NULL);
	if (FAILED(hr))
	{
		return hr;
	}

	// Carga el normal map.
	hr = D3DX11CreateShaderResourceViewFromFile(d3d11Device, pathSpecularMap,
		NULL, NULL, &m_specularmap, NULL);
	if (FAILED(hr))
	{
		return hr;
	}

	return hr;
}
示例#8
0
// конструктор модели с костями
AnimModel::AnimModel(wchar_t* binFilePath, wchar_t* textureFilePath, bool* result) {

	// инициализация переменных
	position = Const::spawnPoint; // координаты модели

	// загрузить модель из файла
	BRR(LoadAmimModelFromFile(binFilePath));

	// инициализация элементов после загрузки
	std::fill(curFrame.begin(), curFrame.end(), 0);
	std::fill(accumulation.begin(), accumulation.end(), 0.0f);
	std::fill(blendFactors.begin(), blendFactors.end(), 0.0f);
	blendFactors[0] = 1.0f;

	// создать матрицу порядка умножения финальных костей
	BRR(BuildOrder());

	// загрузить текстуру
	if (FAILED(D3DX11CreateShaderResourceViewFromFile(Mediator::pDev, textureFilePath, NULL, NULL, &pSRtexture, NULL))) {
		BRR(Mediator::errors->Push(textureFilePath));
		*result = false;
		return;
	}

	*result = true;

}
示例#9
0
void cPillar::Init(float x,float y,float z)
{
	cFBXObject::Init(L"FX/Basic.fx");

	vertices = LOADMANAGER->Pillar_Resource;

	mDirLights[0].Ambient = XMFLOAT4(0.3f, 0.3f, 0.3f, 1.0f);
	mDirLights[0].Diffuse = XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f);
	mDirLights[0].Specular = XMFLOAT4(0.6f, 0.6f, 0.6f, 16.0f);
	mDirLights[0].Direction = XMFLOAT3(0.707f, -0.707f, 0.0f);

	mDirLights[1].Ambient = XMFLOAT4(0.2f, 0.2f, 0.2f, 1.0f);
	mDirLights[1].Diffuse = XMFLOAT4(1.4f, 1.4f, 1.4f, 1.0f);
	mDirLights[1].Specular = XMFLOAT4(0.3f, 0.3f, 0.3f, 16.0f);
	mDirLights[1].Direction = XMFLOAT3(-0.707f, 0.0f, 0.707f);


	mDirLights[2].Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f);
	mDirLights[2].Diffuse = XMFLOAT4(0.2f, 0.2f, 0.2f, 1.0f);
	mDirLights[2].Specular = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f);
	mDirLights[2].Direction = XMFLOAT3(0.0f, -0.707f, -0.707f);


	mObjectMat.Ambient = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
	mObjectMat.Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
	mObjectMat.Specular = XMFLOAT4(0.2f, 0.2f, 0.2f, 16.0f);


	HR(D3DX11CreateShaderResourceViewFromFile(m_pD3dDevice,
		L"Textures/pillar.bmp", 0, 0, &mDiffuseMapSRV, 0));

	//D3D11_BUFFER_DESC vbd;
	ZeroMemory(&vbd, sizeof(D3D11_BUFFER_DESC));
	vbd.Usage = D3D11_USAGE_DEFAULT;
	vbd.ByteWidth = sizeof(PNT_Vertex)* vertices.size();
	//vbd.ByteWidth = sizeof(PNT_Vertex)* m_Animations[0].keyframe_vertices.size();
	vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	//vbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	vbd.MiscFlags = 0;
	vbd.StructureByteStride = 0;
	//D3D11_SUBRESOURCE_DATA vinitData;
	vinitData.pSysMem = &vertices[0];
	//vinitData.pSysMem = &m_Animations[0].keyframe_vertices[0];
	HR(m_pD3dDevice->CreateBuffer(&vbd, &vinitData, &m_VB));


	D3D11_RASTERIZER_DESC Desc;
	ZeroMemory(&Desc, sizeof(D3D11_RASTERIZER_DESC));
	Desc.FillMode = D3D11_FILL_SOLID;
	Desc.CullMode = D3D11_CULL_BACK;
	Desc.FrontCounterClockwise = true;////////////////////////////////////////////////////////////////////////////////////////////////////////
	Desc.DepthClipEnable = true;

	HR(m_pD3dDevice->CreateRasterizerState(&Desc, &m_RS));


	m_WorldMatrix._41 = x;
	m_WorldMatrix._42 = y;
	m_WorldMatrix._43 = z;
}
HRESULT GraphicsManager::CreateShaderResourceViewFromFile(ID3D11Device *device, ID3D11DeviceContext *dc, const wchar_t *filename, ID3D11ShaderResourceView **resourceView)
{
  HRESULT result = E_FAIL;

#ifdef OLD_DX_SDK
	//If not, then we have to load it!
	D3DX11_IMAGE_LOAD_INFO imageInfo;
	result = D3DX11CreateShaderResourceViewFromFile(device, filename, &imageInfo, NULL, resourceView, NULL);
#else
  ID3D11Texture2D *tex;
  result = CreateWICTextureFromFile(device, dc, filename, (ID3D11Resource **)&tex, resourceView);
  if (FAILED(result))
  {
    DirectX::TexMetadata md;
    DirectX::ScratchImage img;
    result = LoadFromDDSFile(filename, 0, &md, img);
    result = CreateShaderResourceView(device, img.GetImages(), img.GetImageCount(), md, resourceView);
  }
#endif

  if (FAILED(result))
  {
    printf("There was a problem loading \"%s\"\n", filename);
  }

	return result;
}
//Initialise Particle System
bool CParticleSystem::Initialise(ID3D11Device* device, std::string mFileName, std::string mFileType, std::string textureLocation)
{
	bool result;

	//Texture Location
	std::string textureRelativePath = TextureFinder(textureLocation, mFileName, mFileType);

	if (FAILED(D3DX11CreateShaderResourceViewFromFile(device, textureRelativePath.c_str(), NULL, NULL, &m_Texture[0], NULL)))
	{
		//Output Error Message 
		OutputDebugString("Unable to Load Texture: ");
		OutputDebugString(textureRelativePath.c_str());
		OutputDebugString("\n");
		return false;
	}

	//Initialise Particles in System
	result = InitialiseParticleSystem();
	if (!result)
	{
		return false;
	}

	//Initialise Buffers
	result = InitialiseBuffers(device);
	if (!result)
	{
		return false;
	}

	return true;
}
示例#12
0
bool Shader::loadTexture(const wchar_t* name, ID3D11Device* pDevice) {
	HRESULT hr = D3DX11CreateShaderResourceViewFromFile(pDevice, name, NULL, NULL, &m_pTexture, NULL);
	if(FAILED(hr)) {
		Log::get()->err("Не удалось загрузить текстуру %ls", name);
		return false;
	}

	D3D11_SAMPLER_DESC samplerDesc;
	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.MipLODBias = 0.0f;
	samplerDesc.MaxAnisotropy = 1;
	samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
	samplerDesc.BorderColor[0] = 0;
	samplerDesc.BorderColor[1] = 0;
	samplerDesc.BorderColor[2] = 0;
	samplerDesc.BorderColor[3] = 0;
	samplerDesc.MinLOD = 0;
	samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

	hr = pDevice->CreateSamplerState(&samplerDesc, &m_pSampleState);
	if(FAILED(hr)) {
		Log::get()->err("Не удалось создать sample state");
		return false;
	}

	return true;
}
示例#13
0
bool Object::InitializeBuffers(ID3D11Device* device, ID3D11DeviceContext* deviceContext, vector<Vertex>* vertices, LPCSTR textureFilename)
{
	vertexCount = vertices->size();

	Vertex *verts = new Vertex[vertexCount];
	for (int i = 0; i < vertexCount; i++)
		verts[i] = vertices->at(i);

	BUFFER_INIT_DESC vertexBufferDesc;
	vertexBufferDesc.ElementSize	=	sizeof(Vertex);
	vertexBufferDesc.InitData		=	verts;
	vertexBufferDesc.NumElements	=	vertices->size();
	vertexBufferDesc.Type			=	VERTEX_BUFFER;
	vertexBufferDesc.Usage			=	BUFFER_DEFAULT;
	
	vertexBuffer = new ObjectBuffer();
	if(FAILED(vertexBuffer->Init(device, deviceContext, vertexBufferDesc)))
		::MessageBox(0, "Initializing vertex buffer failed! [ObjLoader]", "Error", MB_OK);


	D3D11_INPUT_ELEMENT_DESC inputDesc[]	=	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXTURECOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0}
	};

	if(D3DX11CreateShaderResourceViewFromFile(device, textureFilename, 0, 0, &mShaderResourceView, 0 ))
		::MessageBox(0, "Failed to create shader resource! [Model->bthcolor]", "Error", MB_OK);
	Effects::Shader_ShadowFX->SetTexture(mShaderResourceView, "shaderTexture");

	return true;
}
void HandleShaderFiles(const char* a_szFilename)
{
	const char* pEnd = strchr(a_szFilename,'\0');
	while((*pEnd) != '.')
	{
		pEnd--;
	}
	char szExtension[32];
	strncpy_s(szExtension,pEnd,strlen(pEnd) + 1);
	

	if(strstr(szExtension,".hlsl"))
	{
		pkShader->LoadFromFile(a_szFilename);
		m_pScene->UpdateProperties();
	}
	else if(strstr(szExtension,".jpg") || strstr(szExtension,".png") || strstr(szExtension,".bmp") || strstr(szExtension,".tif"))
	{
		ID3D11ShaderResourceView* NewTexture = nullptr;
		D3DX11CreateShaderResourceViewFromFile(lcRenderer::GetDevice(),a_szFilename,nullptr,nullptr,&NewTexture,nullptr);

		if(NewTexture)
		{
			CubeTexture = NewTexture;
			return;
		}
	}
}
bool BoxApp::Init()
{
	if(!D3DApp::Init())
		return false;
	GetWindowRect(mhMainWnd,&rc);
	int midX= (rc.right+rc.left)/2;
	int midY= (rc.top+rc.bottom)/2;
	mLastMousePos.x = midX;
	mLastMousePos.y = midY;
	SetCursorPos(midX,midY);
	ClipCursor(&rc);
	w = new World();
	w->Init(md3dDevice,this);

	cam = new Camera();
	cam->Init(&mView, w->playerShip);

	//SetCapture(mhMainWnd);
	ShowCursor(false);

	BuildGeometryBuffers();
	BuildFX();
	BuildVertexLayout();

	HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice,L"Assets/skybox.dds",0,0, &mCubeMapSRV,0));
	CubeMap = mFX->GetVariableByName("gCubeMap")->AsShaderResource();

	CubeMap->SetResource(mCubeMapSRV);
	return true;
}
void EnemyTurnState::Init()
{
	mInventory = new Inventory();
	mInventory->createItemVectors();
	mInventory->CreateEnemyVectors();

	mFont = ((InClassProj*)mStateMachine)->GetFont();

	Next = false;

	md3dDevice = ((InClassProj*)mStateMachine)->GetDevice();
	md3dImmediateContext = ((InClassProj*)mStateMachine)->GetContext();
	mTransparentBS = ((InClassProj*)mStateMachine)->GetTransparentBS();
	mFontDS = ((InClassProj*)mStateMachine)->GetFontDS();

	mBattleScreen = new Sprite::Frame();
	ID3D11ShaderResourceView* image;
	D3DX11CreateShaderResourceViewFromFile(md3dDevice, L"Textures/PostBattleScreen.png",
		0, 0, &image, 0);
	mBattleScreen->imageWidth = 1900;
	mBattleScreen->imageHeight = 1000;
	mBattleScreen->x = 0;
	mBattleScreen->y = 0;
	mBattleScreen->image = image;
	mBattleScreen->Terrain = 1;
	mBattleScreen->Level = 1;
	mBattleScreen->Direction = 1;

	mBattleScreenVector.push_back(mBattleScreen);
	Sprite::Frame* test = mBattleScreenVector[0];
	mScreenToDraw = new Tile(XMVectorSet(950.0f, 500.0f, 0.0f, 1.0f), XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f), 1900, 1000, 0.0f, mBattleScreenVector, 1.0f, md3dDevice);

}
bool TextureClass::Initialize(ID3D11Device * device,WCHAR *filename)
{
	HRESULT result;
	result = D3DX11CreateShaderResourceViewFromFile(device,filename,NULL,NULL,&m_texture,NULL);
	if(FAILED(result))
	{
		MessageBox(NULL,L"CreateShaderResource Failed!",L"Error - TextureClass",MB_OK);
		return false;
	}
	D3D11_SAMPLER_DESC sampDesc;
	ZeroMemory(&sampDesc,sizeof(D3D11_SAMPLER_DESC));
	sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
	sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	sampDesc.MinLOD = 0;
	sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
	result = device->CreateSamplerState(&sampDesc,&m_SamplerState);
	if(FAILED(result))
	{
		MessageBox(NULL,L"Create SamplerState Failed!",L"Error - TextureClass",MB_OK);
		return false;
	}
	return true;
}
void PlayerTurnState::Init()
{
	mPlace = new TilePlacementState(mStateMachine);
	
	col = mPlace->GetCurrCol();
	row = mPlace->GetCurrRow();

	Tile::Frame* playerTile = new Tile::Frame();
	ID3D11ShaderResourceView* image;
	D3DX11CreateShaderResourceViewFromFile(mStateMachine->GetDevice(), L"Textures/playerTile.png",
		0, 0, &image, 0);
	playerTile->imageWidth = 250;
	playerTile->imageHeight = 250;
	playerTile->x = 0;
	playerTile->y = 0;
	playerTile->image = image;
	playerTile->Terrain = 2;
	playerTile->Level = 5;
	playerTile->Direction = 24;
	playerTile->isUp = true;
	playerTile->isDown = true;
	playerTile->isLeft = true;
	playerTile->isRight = true;
	mPlayerTile.push_back(playerTile);

	PlayerPos.x = (col - 125) * 250;
	PlayerPos.y = (row - 125) * 250;
	PlayerTile = new Tile(XMVectorSet(PlayerPos.x, PlayerPos.y, 0.0f, 1.0f), XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f), 250, 250, 0.0f, mPlayerTile, 1.0f, mStateMachine->GetDevice());
}
void FBXObj::LoadNormal(ID3D11Device* dev, wchar_t* filename)
{
	ID3D11ShaderResourceView* texture;
	HR(D3DX11CreateShaderResourceViewFromFile(dev, 
        filename, 0, 0, &texture, 0 ));
	mNormalArray.push_back(texture);
}
// テクスチャロード
int LoadTexture( TCHAR *szFileName, TEX_PICTURE *pTexPic, int nWidth, int nHeight,
				 int nTexWidth, int nTexHeight )
{
    HRESULT						hr;
	D3DX11_IMAGE_LOAD_INFO		liLoadInfo;
	ID3D11Texture2D				*pTexture;

	ZeroMemory( &liLoadInfo, sizeof( D3DX11_IMAGE_LOAD_INFO ) );
	liLoadInfo.Width = nTexWidth;
	liLoadInfo.Height = nTexHeight;
	liLoadInfo.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	liLoadInfo.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

	hr = D3DX11CreateShaderResourceViewFromFile( g_pd3dDevice, szFileName, &liLoadInfo,
												 NULL, &( pTexPic->pSRViewTexture ), NULL );
    if ( FAILED( hr ) ) {
        return hr;
    }
	pTexPic->pSRViewTexture->GetResource( ( ID3D11Resource ** )&( pTexture ) );
	pTexture->GetDesc( &( pTexPic->tdDesc ) );
	pTexture->Release();

	pTexPic->nWidth = nWidth;
	pTexPic->nHeight = nHeight;

	return S_OK;
}
示例#21
0
ID3D11ShaderResourceView* TextureMgr::getTexture( std::wstring& texName )
{
    std::map<std::wstring, ID3D11ShaderResourceView*>::const_iterator cIter; 
    cIter = mSRV.find(texName);
    if (cIter != mSRV.end())
    {
        return (*cIter).second;
    }
    else
    {
        ID3D11ShaderResourceView* srv = 0;
        for (UINT i = 0; i < mPath.size(); ++i)
        {
            std::wstring dir = mPath[i] + texName;


            D3DX11_IMAGE_LOAD_INFO info;
            info.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
            HRESULT hr = D3DX11CreateShaderResourceViewFromFile(mDevice, dir.c_str(), &info, 0, &srv, 0 );
            if(FAILED(hr))											
                continue;

            mSRV.insert(std::pair<std::wstring, ID3D11ShaderResourceView*>(texName, srv));
            mIdMap.push_back(texName);
            return srv;
        }
    }
    // Texture not found
    return 0;
}
示例#22
0
void GameWon::Init(ID3D11Device* device, UINT16 clientW, UINT16 clientH)
{
	Sprite::Frame* BGFrame = new Sprite::Frame();
	ID3D11ShaderResourceView* BGimage;
	D3DX11CreateShaderResourceViewFromFile(device, L"Textures/WinBackground.png", 0, 0, &BGimage, 0);
	//bg frame
	BGFrame->imageWidth = 1024;
	BGFrame->imageHeight = 768;
	BGFrame->x = 0;
	BGFrame->y = 0;
	BGFrame->image = BGimage;
	std::vector<Sprite::Frame*> bgFrame;
	bgFrame.push_back(BGFrame);

	mBG = new Sprite(XMVectorSet(clientW / 2.0f, clientH / 2.0f, 0.0f, 0.0f), XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f),
		1024.0f, 768.0f, 1.0f, bgFrame, 0.25f, device, 0.0f);

	//Try Again? bounding box
	tryAgainBB.pos = XMFLOAT2(314.0f, 394.0f);
	tryAgainBB.height = 66.0f;
	tryAgainBB.width = 390.0f;

	//Quit bounding box
	quitBB.pos = XMFLOAT2(426.0f, 458.0f);
	quitBB.height = 66.0f;
	quitBB.width = 166.0f;
}
示例#23
0
Player::Player(ID3D11Device* device)
{
	XMMATRIX I = XMMatrixIdentity();
	XMStoreFloat4x4(&mPlayerWorld, I);
	XMStoreFloat4x4(&mTexTransform, I);
	XMStoreFloat4x4(&mView, I);
	XMStoreFloat4x4(&mProj, I);



	XMMATRIX PlayerScale = XMMatrixScaling(3.0f, 1.0f, 3.0f);
	XMMATRIX PlayerOffset = XMMatrixTranslation(0.0f, 5.0f, 0.0f);
	XMStoreFloat4x4(&mPlayerWorld, XMMatrixMultiply(PlayerScale, PlayerOffset));

	mPlayerMat.Ambient = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
	mPlayerMat.Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
	mPlayerMat.Specular = XMFLOAT4(0.6f, 0.6f, 0.6f, 16.0f);


	HR(D3DX11CreateShaderResourceViewFromFile(device,
		L"Textures/WoodCrate02.dds", 0, 0, &mDiffuseMapSRV, 0));

	pdevice = device;

	buildBuffers();


}
示例#24
0
void Tree::init(const char* filename, ID3D11Device* g_device, ID3D11DeviceContext* g_context)
{
	
	Mesh::init(filename, g_device, g_context);
	
	_leaves.init("", g_device, g_context);

	//////////////////////////
	bFire = false;

	m_numSubsets = 1;

	//////////////////////////
	


	createEffect("../Desert_Island/shaders/tree.fxo", g_device);

	fx_m_World				= getFX()->GetVariableByName("m_World")->AsMatrix();
	fx_m_WorldViewProj		= getFX()->GetVariableByName("m_WorldViewProj")->AsMatrix();
	fx_m_L_ViewProj			= getFX()->GetVariableByName("m_L_ViewProj")->AsMatrix();
	
	fx_tex_shadow_map		= getFX()->GetVariableByName("tex_shadow_map")->AsShaderResource();

	fx_lights				= getFX()->GetVariableByName("lights");

	fx_num_lights			= getFX()->GetVariableByName("num_lights")->AsScalar();

	fx_pEye					= getFX()->GetVariableByName("pEye")->AsVector();
	fx_bShadowed			= getFX()->GetVariableByName("bShadowed")->AsScalar();
	fx_bUsePCSS				= getFX()->GetVariableByName("bUsePCSS")->AsScalar();

	///////////

	HRESULT hr = D3DX11CreateShaderResourceViewFromFile(g_dev(), L"../Desert_island/media/tree_heightmap.jpg", 0, 0, &srv_heightmap, 0);
	if (FAILED(hr))
		MessageBoxA(0, "Error creating tree heightmap srv", 0, 0);

	
	
	///////////

	// Input layout - Vertex IA
	D3D11_INPUT_ELEMENT_DESC vertex_layout[] = {
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0,  DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TANGENT", 0,  DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEX_COORDS", 0,  DXGI_FORMAT_R32G32_FLOAT, 0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0 }
	};

	D3DX11_PASS_DESC passDesc;
	ID3DX11EffectTechnique* tech = getFX()->GetTechniqueByIndex(0);
	tech->GetPassByIndex(0)->GetDesc(&passDesc);

	hr = createInputLayout(g_dev(), vertex_layout, 4, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize);
	if (FAILED(hr))
		MessageBoxA(0, "Error creating tree IA", 0, 0);

}
示例#25
0
void DxTexture::InitialiseFromFile(ID3D11Device* device)
{
    if(FAILED(D3DX11CreateShaderResourceViewFromFile(device,
              m_texture.Path().c_str(), 0, 0, &m_view, 0)))
    {
        Logger::LogError("DirectX: Failed to create texture " + m_texture.Path());
    }
}
示例#26
0
  void Texture::InitDX11(ID3D11Device* _g_pd3dDevice)
  {
    // Load the Texture
    std::wstring widestr = std::wstring(_path.begin(), _path.end());
    const wchar_t* widecstr = widestr.c_str();

    D3DX11CreateShaderResourceViewFromFile( _g_pd3dDevice, widecstr, NULL, NULL, &_g_pTextureRV, NULL );
  }
示例#27
0
void DxManager::CreateStaticMesh(StaticMesh* mesh)
{
	MaloW::Array<MeshStrip*>* strips = mesh->GetStrips();

	for(int i = 0; i < strips->size(); i++)
	{
		MeshStrip* strip = strips->get(i);

		BUFFER_INIT_DESC bufferDesc;
		bufferDesc.ElementSize = sizeof(Vertex);
		bufferDesc.InitData = strip->getVerts();
		
		
		// Last face black, should +1 this to solve it.
		bufferDesc.NumElements = strip->getNrOfVerts();

		bufferDesc.Type = VERTEX_BUFFER;
		bufferDesc.Usage = BUFFER_DEFAULT;
		
		Buffer* verts = new Buffer();
		if(FAILED(verts->Init(Dx_Device, Dx_DeviceContext, bufferDesc)))
			MaloW::Debug("Initiate Buffer Failed in DxManager");

		Buffer* inds = NULL;
		if(strip->getIndicies())
		{
			BUFFER_INIT_DESC bufferInds;
			bufferInds.ElementSize = sizeof(int);
			bufferInds.InitData = strip->getIndicies();
			bufferInds.NumElements = strip->getNrOfIndicies();
			bufferInds.Type = INDEX_BUFFER;
			bufferInds.Usage = BUFFER_DEFAULT;
	
			inds = new Buffer();
			if(FAILED(inds->Init(Dx_Device, Dx_DeviceContext, bufferInds)))
				MaloW::Debug("CreateIndsBuffer Failed");
		}

		ID3D11ShaderResourceView* texture = NULL;
		if(strip->GetTexturePath() != "")
		{
			D3DX11_IMAGE_LOAD_INFO loadInfo;
			ZeroMemory(&loadInfo, sizeof(D3DX11_IMAGE_LOAD_INFO));
			loadInfo.BindFlags = D3D11_BIND_SHADER_RESOURCE;
			loadInfo.Format = DXGI_FORMAT_BC1_UNORM;
			if(FAILED(D3DX11CreateShaderResourceViewFromFile(Dx_Device, strip->GetTexturePath().c_str(), &loadInfo, NULL, &texture, NULL)))
				MaloW::Debug("Failed to load texture " + strip->GetTexturePath());
		}

		Object3D* obj = new Object3D(verts, inds, texture, mesh->GetTopology()); 
		strip->SetRenderObject(obj);
	}

	mesh->RecreateWorldMatrix(); 
	
	RendererEvent* re = new RendererEvent("Add Mesh", mesh, NULL);
	this->PutEvent(re);
}
HRESULT InitFont11( ID3D11Device* pd3d11Device, ID3D11InputLayout* pInputLayout )
{
	HRESULT hr = S_OK;
	CHAR str[MAX_PATH] = "UI\\Font.dds";
	//V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"UI\\Font.dds" ) );

	if (pd3d11Device->GetFeatureLevel() < D3D_FEATURE_LEVEL_10_0 ) {

		D3DX11_IMAGE_INFO dii;
		D3DX11GetImageInfoFromFile( str, NULL, &dii, NULL );

		D3DX11_IMAGE_LOAD_INFO dili;
		dili.BindFlags = D3DX11_DEFAULT;
		dili.CpuAccessFlags = D3DX11_DEFAULT;
		dili.Depth = D3DX11_DEFAULT;
		dili.Filter = D3DX11_DEFAULT;
		dili.FirstMipLevel = 0;
		dili.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		dili.Height = D3DX11_DEFAULT;
		dili.MipFilter = D3DX11_DEFAULT;
		dili.MipLevels = 1;
		dili.MiscFlags = D3DX11_DEFAULT;
		dili.pSrcInfo = &dii;
		dili.Usage = D3D11_USAGE_DEFAULT ;
		dili.Width = D3DX11_DEFAULT;

		 D3DX11CreateShaderResourceViewFromFile( pd3d11Device, str, &dili, NULL, &g_pFont11, &hr) ;
	}
	else
	{
		 D3DX11CreateShaderResourceViewFromFile( pd3d11Device, str, NULL, NULL, &g_pFont11, &hr);
	}

#if defined(PROFILE) || defined(DEBUG)
	if (g_pFont11)
	{
		ID3D11Resource *pRes = NULL;
		g_pFont11->GetResource( &pRes );		
		SAFE_RELEASE( pRes );
	}    	
#endif

	g_pInputLayout11 = pInputLayout;
	return hr;
}
示例#29
0
bool LevelDisplay::setTextures( ID3D11Device* device, LPCWSTR floorTexturePath, float floorClip, 
                                                      LPCWSTR wallTexturePath, float wallClip,
                                                      LPCWSTR ceilingTexturePath, float ceilingClip)
{
    HRESULT hr;

    //Release the current textures first
    ReleaseCOM( mFloorTexture );
    ReleaseCOM( mWallTexture );

    //Try to create the ones passed in
    hr = D3DX11CreateShaderResourceViewFromFile( device,
        floorTexturePath, 0, 0, &mFloorTexture, 0 );

    if( FAILED(hr) ){
        LOG_ERRO << "Unable to load floor texture: " << LOG_WC_TO_C(floorTexturePath) << LOG_ENDL;
        return false;
    }

    hr = D3DX11CreateShaderResourceViewFromFile( device,
        wallTexturePath, 0, 0, &mWallTexture, 0 );

    if( FAILED(hr) ){
        LOG_ERRO << "Unable to load wall texture: " << LOG_WC_TO_C(wallTexturePath) << LOG_ENDL;
        return false;
    }

    hr = D3DX11CreateShaderResourceViewFromFile( device,
        ceilingTexturePath, 0, 0, &mCeilingTexture, 0 );

    if( FAILED(hr) ){
        LOG_ERRO << "Unable to load wall texture: " << LOG_WC_TO_C(wallTexturePath) << LOG_ENDL;
        return false;
    }

    mFloorClip = floorClip;
    mWallClip = wallClip;
    mCeilingClip = 1.0f;

    mFloorTileRows = static_cast<int>( 1.0f / floorClip );

    LOG_INFO << "Loaded Level Floor Texture: " << LOG_WC_TO_C(floorTexturePath) << LOG_ENDL;
    LOG_INFO << "Loaded Level Wall Texture: " << LOG_WC_TO_C(wallTexturePath) << LOG_ENDL;
    return true;
}
示例#30
0
void EFighter::Init(ID3D11Device* device,World* w, XMFLOAT3 startPos, Mesh* m)
{
	mesh=m;
	pos = XMFLOAT3(startPos.x, startPos.y, startPos.z);
	
	scale = XMFLOAT3(.25,.25,.25);
	active = false;
	//pos.y + 5;
	up = XMFLOAT3(0,1,0);
	right = XMFLOAT3(-1,0,0);
#pragma region meshing

	XMVECTOR scaleVect=  XMLoadFloat3(&scale);
	XMStoreFloat4x4(&mWorldNoTransl,XMMatrixIdentity()*XMMatrixScalingFromVector(scaleVect));
	//XMStoreFloat4x4(&mWorldNoTransl,XMMatrixIdentity());


	vertNum = mesh->numInd;


	D3D11_BUFFER_DESC vbd;
	vbd.Usage = D3D11_USAGE_IMMUTABLE;
	vbd.ByteWidth = sizeof(Vertex) * mesh->numVerts;
	vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vbd.CPUAccessFlags = 0;
	vbd.MiscFlags = 0;
	vbd.StructureByteStride = 0;
	D3D11_SUBRESOURCE_DATA vinitData;
	vinitData.pSysMem = mesh->vertices;
	HR(device->CreateBuffer(&vbd, &vinitData, &vertexBuffer));

	D3D11_BUFFER_DESC ibd2;
	ibd2.Usage = D3D11_USAGE_IMMUTABLE;
	ibd2.ByteWidth = sizeof(UINT) * mesh->numInd;
	ibd2.BindFlags = D3D11_BIND_INDEX_BUFFER;
	ibd2.CPUAccessFlags = 0;
	ibd2.MiscFlags = 0;
	ibd2.StructureByteStride = 0;
	D3D11_SUBRESOURCE_DATA iinitData2;
	iinitData2.pSysMem = mesh->indices;
	HR(device->CreateBuffer(&ibd2, &iinitData2, &indexBuffer));

	XMMATRIX I = XMMatrixIdentity();
	XMStoreFloat4x4(&mWorld, I);

	mat.Ambient = XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f);
	mat.Diffuse = XMFLOAT4(0.77f, 0.77f, 1.0f, 1.0f);
	mat.Specular = XMFLOAT4(0.8f, 0.8f, 0.8f, 16.0f);
#pragma endregion

	worldPTR = w;

	HR(D3DX11CreateShaderResourceViewFromFile(device,mesh->texturePath,0,0,&mDiffuseSRV,0));


}