加载图片到D3D11Texture2D

#include "stdafx.h"
#include "LoadPicture.h"
#include 
#include 
#include 

#pragma comment(lib,"D3DX11.lib")
#pragma comment(lib,"D3D11.lib")


bool LoadTexture()
{

	ID3D11Texture2D * pTexture2D = NULL;
	D3D11_TEXTURE2D_DESC dec;
	UINT createDeviceFlags = 0;
   #if  defined(DEBUG) || defined(_DEBUG)
	createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; 
   #endif
	D3D_FEATURE_LEVEL featureLevel; ID3D11Device *  md3dDevice; 
	ID3D11DeviceContext*  md3dImmediateContext; 
	
	HRESULT  hr = D3D11CreateDevice(0,                     //  默认显示适配器    
		D3D_DRIVER_TYPE_HARDWARE ,    0,                     //  不使用软件设备    
		createDeviceFlags ,    0, 0,               //  默认的特征等级数组    
		D3D11_SDK_VERSION,    &  md3dDevice ,    & featureLevel,    &  md3dImmediateContext);
	

	HRESULT result;
	D3DX11_IMAGE_LOAD_INFO loadInfo;
	ZeroMemory(&loadInfo, sizeof(D3DX11_IMAGE_LOAD_INFO));
	loadInfo.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	loadInfo.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	loadInfo.MipLevels = D3DX11_DEFAULT; //这时会产生最大的mipmaps层。 
	loadInfo.MipFilter = D3DX11_FILTER_LINEAR;
	result=D3DX11CreateTextureFromFile(md3dDevice, "C:\\Users\\Administrator\\Desktop\\logo.png", &loadInfo, NULL, (ID3D11Resource**)(&pTexture2D), NULL);
	pTexture2D->GetDesc(&dec);

	if (result)
		return true;
	else
		return false;
}

你可能感兴趣的:(Win)