I would like to know if it is possible to erase parts of any drawing in OpenGL? Lets say I have drawn two lines with my mouse and those lines are overlapping at some points.
Is it possible to erase just one line? Is there a more or less simple approach?
OpenGL does not store what you draw. If you draw a line in OpenGL, then OpenGL will take that line, perform various math operations on it, and write pixels into a framebuffer that makes the shape of a line. OpenGL does not remember that you drew a line; all OpenGL can do is write pixels to the framebuffer.
The general idea is that it is up to the user of OpenGL to remember what they drew. So if you draw two lines, you should remember the coordinates you gave for those two lines. Therefore, if you want to "erase" a line, what you do is clear the screen and redraw everything except that line.
This isn't as silly as it may sound. Many OpenGL applications are constantly redrawing the screen. They show a frame, draw a new frame, then show that frame, etc. This provides the possibility for animation: changing what gets drawn and where it gets drawn from frame to frame. This creates the illusion of movement.
You can use glLogicOp with GL_XOR
, then repaint the line to erase it. It's not a general solution, but it is a good fit for marquee selection or mouse tool overlays, where it was traditionally used. Note that you'll need to either use single-buffering, or copy between the back and the front buffer rather than swapping them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With