clearing windows

I am unsure of how to use glScissor and glViewport to clear a portion of the window.

Well, you can’t use glViewport to clear part of a window; [aren’t affected by the [url=]viewport transform](Framebuffer - OpenGL Wiki clearing commands[/url).

The scissor test is respected by rendering commands. What exactly are you unsure about in how to use scissoring?

well I want to use glScissor to clear a polygon that I am texturing.

is there any command I can use to clear a polygon?

What do you mean by “clear a polygon?” Clearing is something that happens to the screen. By the time you’ve put a polygon on the screen, it’s not a polygon; it’s just a bunch of pixels.

If you want to render a scene without one particular polygon in it, then that’s what you need to do. You can’t undo a scene after the fact; you should just clear the screen and render everything else.

well I want to erase a polygon that I have rendered without clearing the entire screen I thought glScissor could work for me.

Not unless that polygon is an axis-aligned square. Also, even if you could, if there was something behind that polygon, this would not cause it to appear.

Remember: OpenGL is just a fancy triangle drawing system. Once it’s drawn, it’s not a polygon; it’s just a bunch of pixels. If you overwrite pixels, then their values are lost.

so can I use glScissor? I am a little confused.

I honestly don’t know how I can possibly explain it more explicitly.

The scissor test designates an axis-aligned rectangular area of the window. When the test is enabled, all attempts by rendering commands to write to pixels outside of that region will fail. Thus only pixels inside of that area will be affected by that rendering command.

Framebuffer clearing functions are rendering commands. Therefore, they are affected by the scissor test.

Given the two above facts, it naturally concludes that you can use the scissor test and clearing commands to clear an axis-aligned rectangular portion of the window, rather than the entire window.

You want to clear a polygon. The above gives you the ability to clear an axis-aligned rectangular area of the window.

Therefore, you can only use the above feature to clear a polygon if that polygon is “an axis-aligned rectangular area of the window”. If that polygon is a triangle, non-axis-aligned rectangle, an arbitrary quadrilateral, or any other kind of polygon, then you cannot use the scissor test and framebuffer clearing to clear it.

Then draw the exact same polygon again (with depth tests disabled), in whatever colour constitutes “clear” (e.g. your background colour).

This is something that comes up regularly enough, although it’s been a while since I’ve seen it.

Typically somebody only wants to change a small part of the scene (maybe they’re implementing an “undo” function in a modelling program) and it seems to them that it would be more efficient to only make that change rather than redraw the entire scene.

That’s not the case at all. With OpenGL, and GPUs in general, the best path is actually to clear, then redraw the entire scene except the item they wish to remove.

There are a number of reasons for this.

First of all you should be redrawing the entire scene every frame anyway. You should have some kind of “scene database”, a hierarchical tree, a list of items to be drawn, or whatever. To remove an item from the scene you just remove it from your scene database, and the next frame will come along and just not draw it. You don’t need any special-case code in your renderer for removing items.

Secondly neither OpenGL nor your graphics card maintains any information about what’s been overdrawn. So if you wish to remove a polygon from the scene, there’s no way of knowing if some other polygon had previously been behind it, and if so, what colours it had used. Once something has been overdrawn, the original information is gone - forever.

Thirdly a removed item could be of arbitrary shape and complexity. Maybe it’s just a simple flat polygon, but maybe it’s a complex model with interesting bits sticking out of it. Maybe it has some parts that blend with the background colour and some parts that don’t. There’s just no way that you can simply and cleanly remove such an item; just redrawing the scene without the item is easier.

So it’s not more efficient, it’s not even easier, and you end up writing a whole lot of messy special-case code when you could instead be just using your regular renderer with some insert/remove capability added to your scene database: it’s not even in your own interests to want to do this.

so I cannot use glScissor to clear a portion of a window, is there any command I can use?

At this stage you need to be more specific about exactly what it is you’re trying to do. Don’t even focus on clearing stuff, forget about glScissor, forget about how you’d like to solve the problem, just describe in general terms what the problem is.

The task “clear a portion of a window” and the task “clear a polygon” are not the same thing.

You can use the scissor test to clear an axis-aligned, rectangular portion of a window. But that’s the only shape it can clear. If your “portion” is not that shape, then you cannot use that to clear it.

If you want to clear a “portion” of the screen, and that portion is not an axis-aligned, rectangular region, then you need to explain how the “portion” in question is defined. Without that knowledge, it’s hard to give you a recommendation.

Also, what mhagain said.

well I am going to have to really think about my problem.

But we still don’t know what your problem is.

OK, let me try to put this as clear as I can. You say you want to clear a polygon on the screen, but you haven’t said why. You haven’t told us what you are actually trying to do. You’ve got a problem and you think you cna solve it by clearing a polygon on the screen, but what problem are you trying to solve by clearing a polygon on the screen?

If you at least tell us that, it’s possible that somebody might be able to come along with a quick and simple answer, or at worst tell you that you’ll just have to redraw the scene. So you need to tell us what you want to do, not how you want to do it.

ok, I will think about my question

hey carmine can you help me with my problem, let me know if you need me to restate my question.

hey carmine can you help me with my problem, let me know if you need me to restate my question.
The other guys have stated the options pretty clearly. Either redraw the entire scene leaving out the polygon you want to ‘clear’, or re-render only that polygon without calling glClear at the beginning of your draw routine. Can you post before and after pictures that demonstrate what you’re after?

hej pbivens,
I don’t know why all the fuss about why … I’ve sat down to pop the same question, and it turned out that it was the most resent question.
I can suggest why: If one does not take particular care on when to draw or not, the graphics card (judged by the ventilator) will come to work much harder than needed. I don’t use timed draws, but draws whenever something has changed … I’m currently doing some modeller where this trait seems appropriate. I work a lot with the mouse … draws helper-graphics whenever the cursor moves … and I have a short limit on how much I can do for every incremental move of the cursor. So’ I thought, probably like pbivens, that swapping only a rectangular part of the full buffer and refresh would be less demanding on the drawing. - Maybe some of us learned that somewhere in directx, anyway. It doesn’t seem as if there is such a part swap. Unless one would dive deep into the bawls of openGL.