简体   繁体   中英

c++ opengGL: Draw polygon + image processing interior pixels

I am using opengl and c++ doing image processing. The idea is simple, I will load an image, draw a polygon by clicking and then apply an effect (desaturation for instance) only to the pixels in the interior of the polygon shape just created.

Can anyone give me any direction on how to limit the effect to the pixels within the interior of the polygon? Loading the image and drawing the polygon is not a problem

Supposing the following situation :

  • The picture on which you want to apply the effect takes the whole screen
  • The picture is rendered using opengl , probably through a simple shader, with the picture passed as a texture

You can do the following approach :

  • consider the screen as being a big texture
  • you draw a polygon, which will be rendered on top of the rendered texture
  • inside the polygon's vertices insert the uv's coresponding to the 2D coordinates on the screen (so from screen space to uv space (0 , 1 ) )
  • draw the picture normaly
  • on top of the picture draw your polygon using the same picture as texture, but with a different shader

So instead of trying to desaturate a specific region from your picture, create a polygon on top of that region with the same picture, and desaturate that new polygon.

This would help you in avoiding the stencil buffer.

Another approach would be to create the polygon, but draw it only on the stencil buffer, before the picture is drawn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM