Jump to content
  • Advertisement
Sign in to follow this  
lonewolff

Problems rendering to texture

This topic is 985 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys,

 

I am currently trying to work out how to render a scene to a texture and then render it back to a quad on the back buffer (with the view of adding post effects later on).

 

I think I am on the right track, but I am only receiving a blank render window.

 

The aim (for this test) is to render a quad that has its own texture to a quad in the middle of the screen (this part is ok, if I draw it direct to the backbuffer). This gets drawn to its own render target texture.

 

This texture then becomes the texture for the final quad that I am drawing to the backbuffer.

 

I think I am pretty close. I'll supply the render phase of the code, to save having a massive wall of code (to start with) :)

 

// Working with the texture as a render target
float clearColour2[4] = { 1.0f, 0.0f, 0.0f, 1.0f }; // Making this red to stand out
d3dContext->ClearRenderTargetView(renderTextureView, clearColour2);
d3dContext->OMSetRenderTargets(1, &renderTextureView, 0); 
 
// Set the texture as the target
d3dContext->PSSetShaderResources(0, 1, &srv); // Texture the upcoming quad with a premade bitmap (working ok)
 
// Render the premade bitmap texture to the quad
unsigned int stride = sizeof(Float9);
unsigned int offset = 0;
d3dContext->IASetInputLayout(d3dInputLayout);
d3dContext->IASetVertexBuffers(0, 1, &d3dVertexBuffer, &stride, &offset);
d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
d3dContext->Draw(nVerts, 0);
 
 
// Working with the backbuffer now
float clearColour[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; // Clearing the backbuffer to black
d3dContext->ClearRenderTargetView(d3dBackBuffer, clearColour);
d3dContext->OMSetRenderTargets(1, &d3dBackBuffer, 0); 
 
// Set the backbuffer as the target
d3dContext->PSSetShaderResources(0, 1, &srv2); // This contains (should anyway) the 'texture target' from the previous bit
 
// Render the 'texture target' to the final quad
unsigned int stride2 = sizeof(Float9);
unsigned int offset2 = 0;
d3dContext->IASetInputLayout(d3dInputLayout);
d3dContext->IASetVertexBuffers(0, 1, &d3dVertexBuffer2, &stride2, &offset2);
d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
d3dContext->Draw(nVerts2, 0);?
 
 
// Present the frame
d3dSwapChain->Present(nPresentationInterval, 0);

 

 

If you could cast an eye over this and let me know if I am on the right path, that would be awesome.

 

Thanks in advance :)

 

Share this post


Link to post
Share on other sites
Advertisement
I have been using the debug layer, it's not reporting anything bad happening though.

I must admit that I don't know about VS graphics debugger though. Didn't know there was such a thing.

Share this post


Link to post
Share on other sites

Thanks man, looking at it now. [edit - Looks to be on the similar lines to PIX, definitely looking further into this]

 

With the task at hand, does it look like I am on the right track?

Edited by DarkRonin

Share this post


Link to post
Share on other sites

Nothing in the code above immediately struck me as being wrong, so what you've written will be pretty close to correct. Unfortunately there's at least 10 pretty common reasons for a triangle/quad not drawing, so understanding how to use the GPU debugger will help you help yourself going forward.

Share this post


Link to post
Share on other sites

No probs, thanks for the advice once again smile.png

 

Good to know I have the concept right. Must be something I have missed (obviously smile.png)

 

Will check out the GPU debugger. The more of my own troubleshooting I can do the more solid the understanding becomes.

 

 

[edit]

With the link you provided (https://msdn.microsoft.com/en-us/library/hh708964.aspx), I am guessing this doesn't relate to 'Community Edition'? As there doesn't seem to be a 'Graphics Diagnostics' toolbar.

 

[edit 2]

Found it - It is in the 'Debug' menu.

Edited by DarkRonin

Share this post


Link to post
Share on other sites

From what I am seeing in the debugger, the first draw to the texture is correct. The preview shows up a red background with the textured quad correctly drawn.

 

So, the problem seems to lie in the second section of code.

 

Interesting stuff. Thanks for putting me on to the Graphical Debugger ajmiles smile.png

 

 

[edit]

I can see that the quad is rendering correctly on the final draw but it doesn't seem to be using the texture though. I am using the same shader for both, so that should be ok.

 

rendertotex.png

Edited by DarkRonin

Share this post


Link to post
Share on other sites

Hmmm, odd. In reshuffling some things and cleaning out some bits of code it is now auto-magically working.

 

I must have been extremely close to the mark then. But, not quite sure what I did to get it across the line.

 

Thanks again ajmiles, you have taught me some new essential items for debugging :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!