Я пытаюсь загрузить текстуру травы в свою игру с помощью функции DirectX::CreateWICTextureFromFile
, но каждый раз, когда я это делаю, функция, похоже, ничего не загрузит, он просто загружает черную текстуру. Функция успешно возвращает S_OK
, и я также назвал CoInitialize(NULL)
, прежде чем я на самом деле вызову функцию. Но это все еще не работает.Функция CreateWICTextureFromFile() на самом деле не загружает текстуру (Direct3D11, C++)
вниз ниже мое использование функции
// This is where i load the texture
void Load_Texture_for_Ground()
{
HRESULT status;
ID3D11ShaderResourceView * Texture;
CoInitialize(NULL);
status = DirectX::CreateWICTextureFromFile(device, L"AmazingGrass.jpg", NULL, &Texture);
if (Texture != NULL) // This returns true
{
MessageBox(MainWindow, L"The pointer points to the texture", L"MessageBox", MB_OK);
}
if (status == S_OK) //This returns true
{
MessageBox(MainWindow, L"The function succeeded", L"MessageBox", MB_OK);
}
CoUninitialize();
}
// This is where i actually load the texture onto an object, assuming i already declared all the variables in this function
void DrawTheGround()
{
DevContext->VSSetShader(VS, 0, 0);
DevContext->PSSetShader(PS, 0, 0);
DevContext->IASetVertexBuffers(
0,
1,
&GroundVertexBuffer,
&strides,
&offset
);
DevContext->IASetIndexBuffer(
IndexBuffer,
DXGI_FORMAT_R32_UINT,
0
);
/* Transforming the matrices*/
TransformedMatrix = GroundWorld * CameraView * CameraProjection ;
Data.WORLDSPACE = XMMatrixTranspose(GroundWorld);
Data.TRANSFORMEDMATRIX = XMMatrixTranspose(TransformedMatrix);
/* Updating the matrix in application's Constant Buffer*/
DevContext->UpdateSubresource(
ConstantBuffer,
0,
NULL,
&Data,
0,
0
);
DevContext->VSSetConstantBuffers(0, 1, &ConstantBuffer);
DevContext->PSSetShaderResources(0, 1, &Texture);
DevContext->PSSetSamplers(0, 1, &TextureSamplerState);
DevContext->DrawIndexed(6, 0, 0);
}
Что может быть не так? Почему функция не загружает текстуру?
вы должны вызвать CoInitialize (NULL); в начале вашего приложения и CoUninitialize в конце – marcinj
Это все равно не изменит, функция все равно ничего не загружает –
Можете ли вы отправить ссылку на ваш файл jpg? Я хотел бы попытаться воспроизвести вашу проблему. Вы можете показать источник для создания «GroundVertexBuffer». Кроме того, вы должны, как заметки marcinj, вызывать '' CoInitialize'' в начале вашего приложения, а не в начале функции. –