D3D12 - 渲染图像的基础知识 [英] D3D12 - Basics of Rendering Images

查看:328
本文介绍了D3D12 - 渲染图像的基础知识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名试图学习C ++ / DirectX的Java程序员。我使用的是"D3D12 Win32 Game"。模板,下面我已经包含了模板中所有看似相关的代码部分。我正在尝试进行基本的仓库模拟,其中调色板图像的多个
实例被绘制到屏幕并移动。



用于绘制调色板.png图像到屏幕,我希望有一些类似于Java中的drawImage方法,在那里我传递图像文件和x,y坐标。在C ++中,它似乎在Game :: CreateDevice中加载图像,通过调用m_spriteBatch-> Draw在Game :: Render
中绘制它,并设置coords在Game :: CreateResources中使用变量m_screenPos绘制。
如何修改此代码以在不同的坐标下创建多个调色板图像?我是否需要以某种方式为每个调色板设置不同的m_screenPos变量?

I'm a Java programmer trying to learn C++/DirectX. I'm using the "D3D12 Win32 Game" template, below I've included all the seemingly relevant portions of the code in the template. I'm trying to make a basic warehouse simulation where multiple instances of a palette image are drawn to the screen and moved around.

For drawing a palette.png image to the screen, I was hoping there was something similar to the drawImage method in Java, where I pass it the image file and the x,y coords. In C++, it seems to load the image in Game::CreateDevice, draw it in Game::Render by calling m_spriteBatch->Draw, and sets the coords to draw at in Game::CreateResources with the variable m_screenPos. How can I modify this code to create multiple palette images each at different coords? Would I need to somehow have a different m_screenPos variable for each palette?

另外,我可以通过将m_spriteBatch作为参数传递给另一个类中的方法来访问m_spriteBatch->在Game :: Render之外绘制吗?
如果是这样,我该如何传递它?它的类型是std :: unique_ptr< DirectX :: SpriteBatch>。

Also, can I access m_spriteBatch->Draw outside of Game::Render by passing m_spriteBatch as a parameter to a method in a different class? If so, how do I pass it? It's of type std::unique_ptr<DirectX::SpriteBatch>.

谢谢! (对不起,如果我在错误的部分发布了这个)

Thanks! (sorry if I posted this in the wrong section)

//Game::Render()
m_spriteBatch->Begin(m_commandList.Get());

m_spriteBatch->Draw(m_resourceDescriptors->GetGpuHandle(Descriptors::Palette),
                    GetTextureSize(m_texture.Get()),
                    m_screenPos, nullptr, Colors::White, 0.f, m_origin);

m_spriteBatch->End();

//----------

//Game::CreateResources
m_screenPos.x = backBufferWidth / 2.f;
m_screenPos.y = backBufferHeight / 2.f;

//----------

//Game.h
enum Descriptors
{
  Palette,
  Count
};
std::unique_ptr<DirectX::SpriteBatch> m_spriteBatch;

//----------

//Game::CreateDevice
resourceUpload.Begin();

DX::ThrowIfFailed(
  CreateWICTextureFromFile(m_d3dDevice.Get(), resourceUpload, L"res/textures/palette.png",
  m_texture.ReleaseAndGetAddressOf(), false));

CreateShaderResourceView(m_d3dDevice.Get(), m_texture.Get(),
                         m_resourceDescriptors->GetCpuHandle(Descriptors::Palette));

RenderTargetState rtState(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_D32_FLOAT);

SpriteBatchPipelineStateDescription pd(rtState);
m_spriteBatch = std::make_unique<SpriteBatch>(m_d3dDevice.Get(), resourceUpload, pd);

XMUINT2 PaletteSize = GetTextureSize(m_texture.Get());

m_origin.x = float(PaletteSize.x / 2);
m_origin.y = float(PaletteSize.y / 2);

auto uploadResourcesFinished = resourceUpload.End(m_commandQueue.Get());

uploadResourcesFinished.wait();

推荐答案

您好SC-Toronto,

Hi SC-Toronto,

感谢您在此发布。

您能否提供有关您项目的更多信息?它是桌面应用程序还是UWP / Android应用程序?

Could you please provide more information about your project? Is it a desktop application or UWP/Android application?

如果您的应用程序是UWP / Android应用程序,我将帮助您将其移至UWP论坛。

If your application is an UWP/Android application, I will help you move it to UWP forum.

>> 如何修改此代码以在不同的线上创建多个调色板图像?

>> 我可以访问m_spriteBatch->通过将m_spriteBatch作为参数传递给另一个类中的方法,在Game :: Render之外绘制?
如果是这样,我该如何通过?

据我所知,你无法实现这一点。

As far as I know, you couldn't implement this.

如果您想学习Direct 3D的一些基本知识,请参考下面的这些文档和示例。

If you want to learn some basic knowledge of Direct 3D, please refer to these documents and samples below.

https://msdn.microsoft.com/en-us/library/windows/desktop/ dn899121(v = vs.85).aspx

https:/ /github.com/Microsoft/DirectX-Graphics-Samples

最好的问候,

Sera Yu

Best Regards,
Sera Yu


这篇关于D3D12 - 渲染图像的基础知识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆