59. ... Create Vertex Buffer ... 60. 61. d3dResult = D3DX11CreateShaderResourceViewFromFile( d3dDevice_, 62. 63. \, 0, 0, &colorMap_, 0 ); 64. 65. if( FAILED( d3dResult ) ) 66. 67. { 68. 69. DXTRACE_MSG( \ texture image!\ ); 70. 71. return false; 72. 73. } 74. 75. D3D11_SAMPLER_DESC colorMapDesc; 76.
77. ZeroMemory( &colorMapDesc, sizeof( colorMapDesc ) ); 78. 79. colorMapDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; 80. 81. colorMapDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; 82. 83. colorMapDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; 84. 85. colorMapDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; 86. 87. colorMapDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; 88. 89. colorMapDesc.MaxLOD = D3D11_FLOAT32_MAX; 90.
91. d3dResult = d3dDevice_->CreateSamplerState( &colorMapDesc, 92. 93. &colorMapSampler_ ); 94. 95. if( FAILED( d3dResult ) ) 96. 97. { 98. 99. DXTRACE_MSG( \olor map sampler state!\ ); 100. 101. return false; 102. 103. } 104. 105. return true; 106. 107. } 108. 109. void TextureDemo::UnloadContent( )
110. 111. { 112. 113. if( colorMapSampler_ ) colorMapSampler_->Release( ); 114. 115. if( colorMap_ ) colorMap_->Release( ); 116. 117. if( solidColorVS_ ) solidColorVS_->Release( ); 118. 119. if( solidColorPS_ ) solidColorPS_->Release( ); 120. 121. if( inputLayout_ ) inputLayout_->Release( ); 122. 123. if( vertexBuffer_ ) vertexBuffer_->Release( ); 124. 125. colorMapSampler_ = 0;
126. 127. colorMap_ = 0; 128. 129. solidColorVS_ = 0; 130. 131. solidColorPS_ = 0; 132. 133. inputLayout_ = 0; 134. 135. vertexBuffer_ = 0; 136. 137. }
UnloadContent函数释放了新对象,而
LoadContent函数进行了纹理图像的加载。我们可以使用Direct3D中的
D3DX11CreateShaderResourceViewFromFile函数(这个函数名是不是略长啊,哈哈),来加载一个纹理然后在一个简单的调用之中创建着色器资源视图。这个函数在我们想毕其功于一役的