# Spatial Reality Displayに表示されている映像を取得してみよう
このページでは、Spatial Reality Displayに表示されている映像について取得する方法を説明します。取得した映像の利用方法については、[サンプルアプリ](/Products/Developer-Spatial-Reality-display/jp/develop/UnrealEngine/Samples.html) を参考にしてください。
## 事前準備
- Spatial Reality Display SettingsがPCにインストールされていること。インストールしていない場合は [Setup Spatial Reality Display Settings](/Products/Developer-Spatial-Reality-display/jp/develop/Setup/SetupSRRuntime.html) を参照してください。
- The Epic Games LauncherとUnreal Engine、Visual Studio がインストールされていること。
- [Unreal EngineでC++を利用](https://dev.epicgames.com/documentation/ja-jp/unreal-engine/unreal-engine-cpp-quick-start) できる状態になっていること。
## 結合画像の取得方法
SRDisplayPluginに定義されている `OnSRDRenderTextureCompletedDelegate` を設定することで、描画のタイミングで、Spatial Reality Displayに表示されている混合画像を取得できます。
1. `OnSRDRenderTextureCompletedDelegate` に設定する関数の準備をします。第1引数が `FRHICommandListImmediate&`、第2引数が `FTextureRHIRef` となる関数を定義してください。
:::note
Unreal Engine 4.27を利用している場合は、第2引数は `FTexture2DRHIRef` としてください。
:::
```cpp
void RenderingSRDisplay2DWindow(FRHICommandListImmediate& RHICmdList, FTextureRHIRef SrcTexture);
```
2. `FSRDisplaySystem` から `OnSRDRenderTextureCompletedDelegate` を取得し、前のステップで定義した関数を設定します。`OnSRDRenderTextureCompletedDelegate` への設定方法については、[マルチキャスト デリゲート](https://dev.epicgames.com/documentation/ja-jp/unreal-engine/multicast-delegates-in-unreal-engine) を参照してください。例では、`AddRaw()` を利用します。
```cpp
srdisplay_module::FSRDisplaySystem* SRDisplaySystem = USRDisplayFunctionLibrary::GetSRDisplaySystem();
FOnSRDRenderTextureCompletedDelegate& OnSRDRenderTextureCompletedDelegate = SRDisplaySystem->GetSRDRenderTextureCompletedDelegate();
OnSRDRenderTextureCompletedDelegate.AddRaw(FSample2DWindow::GetPlayWindow(), &FSample2DWindow::RenderingSRDisplay2DWindow);
```
3. Spatial Reality Displayに描画されるタイミングで、`OnSRDRenderTextureCompletedDelegate` に設定した関数が呼びだされます。第2引数が結合画像のテクスチャとなります。