Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How do I run an OpenGL shader on just a portion of an off screen texture and leave the rest of the texture unmodified? Are there any calls that restrict the sampled pixels to just a rectangle or do I have to filter out the rectangle in the shader code?

share|improve this question
    
What are you actually trying to achieve? This sounds a bit like a problem you might be creating by using the wrong strategy when rendering to (or using the) render texture. –  Mario Jan 18 at 11:21
add comment

1 Answer 1

up vote 2 down vote accepted

Yes, you can restrict rendering to just a rectangle by using either the viewport rect or the scissor rect. These can be set by the glViewport and glScissor calls, respectively.

The distinction is that setting the viewport will pretend that the viewport is the entire render target. Any geometry you render will be scaled down to the viewport; the viewport will always extend from -1 to 1 in NDC (post-projective) coordinates. The scissor rect, on the other hand, doesn't rescale any geometry or alter any coordinates - it simply suppresses rendering to any pixels outside the rect.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.