Hello! I’m trying to create a texture by means of simple post-processing effect on the auxiliary viewport. Here’s the code
SharedPtr<Texture2D> Game::CreateTexture(int width, int height)
{
//Get the Resource Cache subsystem
ResourceCache* cache = GetSubsystem<ResourceCache>();
SharedPtr<Texture2D> renderTexture(new Texture2D(context_));
renderTexture->SetSize(width, height, Graphics::GetRGBFormat(), TEXTURE_RENDERTARGET);
renderTexture->SetFilterMode(FILTER_BILINEAR);
// Create the scene which will be rendered to a texture
rttScene_ = new Scene(context_);
// Create a camera for the render-to-texture scene.
rttCameraNode_ = rttScene_->CreateChild("Camera");
auto* rttCamera = rttCameraNode_->CreateComponent<Camera>();
RenderSurface* surface = renderTexture->GetRenderSurface();
SharedPtr<Viewport> rttViewport(new Viewport(context_, rttScene_, rttCameraNode_->GetComponent<Camera>()));
surface->SetViewport(0, rttViewport);
SharedPtr<RenderPath> effectRenderPath = rttViewport->GetRenderPath()->Clone();
effectRenderPath->Append(cache->GetResource<XMLFile>("PostProcess/BasicPP.xml"));
rttViewport->SetRenderPath(effectRenderPath);
surface->QueueUpdate();
return renderTexture;
}
I’ve created BasicPP.xml and the corresponding BasicPP.glsl which creates a simple gradient by using gl_FragColor. The effect is working as expected on the main viewport. Also, when I attach a .png texture to my sprite, it gets shown on the screen.
So what am I missing?