PDA

View Full Version : clearing windows



pbivens
05-23-2015, 06:03 PM
I am unsure of how to use glScissor and glViewport to clear a portion of the window.

Alfonse Reinheart
05-23-2015, 06:35 PM
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=https://www.opengl.org/wiki/Vertex_Post-Processing#Viewport_transform]viewport transform (https://www.opengl.org/wiki/Framebuffer#Buffer_clearingframebuffer clearing commands[/url).

The scissor test (https://www.opengl.org/wiki/Scissor_Test) is respected by rendering commands. What exactly are you unsure about in how to use scissoring?

pbivens
05-23-2015, 06:44 PM
well I want to use glScissor to clear a polygon that I am texturing.

pbivens
05-23-2015, 06:47 PM
is there any command I can use to clear a polygon?

Alfonse Reinheart
05-23-2015, 08:22 PM
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.

pbivens
05-23-2015, 08:57 PM
well I want to erase a polygon that I have rendered without clearing the entire screen I thought glScissor could work for me.

Alfonse Reinheart
05-23-2015, 09:13 PM
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.

pbivens
05-24-2015, 10:46 AM
so can I use glScissor? I am a little confused.

Alfonse Reinheart
05-24-2015, 12:34 PM
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.

GClements
05-24-2015, 12:47 PM
well I want to erase a polygon that I have rendered without clearing the entire screen
Then draw the exact same polygon again (with depth tests disabled), in whatever colour constitutes "clear" (e.g. your background colour).

mhagain
05-24-2015, 01:33 PM
well I want to erase a polygon that I have rendered without clearing the entire screen I thought glScissor could work for me.

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.

pbivens
05-24-2015, 02:21 PM
so I cannot use glScissor to clear a portion of a window, is there any command I can use?

mhagain
05-24-2015, 02:35 PM
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.

Alfonse Reinheart
05-24-2015, 02:38 PM
so I cannot use glScissor to clear a portion of a window, is there any command I can use?

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.

pbivens
05-25-2015, 02:23 PM
well I am going to have to really think about my problem.

mhagain
05-26-2015, 08:48 AM
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.

pbivens
05-26-2015, 10:25 AM
ok, I will think about my question

pbivens
05-30-2015, 04:07 PM
hey carmine can you help me with my problem, let me know if you need me to restate my question.

Carmine
05-30-2015, 10:01 PM
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?

CarstenT
05-31-2015, 09:38 AM
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.


cheers

pbivens
05-31-2015, 04:35 PM
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?
thanks carmine, well I tried leaving out the glClear command but it does not work. any more suggestions?

Alfonse Reinheart
05-31-2015, 08:52 PM
thanks carmine, well I tried leaving out the glClear command but it does not work. any more suggestions?

We can't suggest something if we don't understand the problem. Please answer the questions mhagain asked if you want more suggestions.

pbivens
06-03-2015, 09:44 PM
well I have made some progress. I can get the bullet to hit the bug and erase the bug, but it erases all the bugs and does not redraw them. here is my code


void bug_coll()
{
if (bugcoll == false)
{
draw_Scene_bug();
}

}

void drawScene()
{
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

drawScene_ship();

drawScene_bullet();

bug_coll();

// draw_Scene_bug();

collision();

glutSwapBuffers();
}

well when I press the space bar and shoot the bullet the program erases all the bugs and does not redraw them all, I want it to erase only one bug. here is the code that draws the bugs


void draw_Scene_bug()
{
bugcoll = true;

glEnable(GL_TEXTURE_2D);//bug
glBindTexture(GL_TEXTURE_2D, _textureId_three);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

for (float i = -8.5f; i <= 7.5f; i += 2.0f)
{
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_POLYGON);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(i, 9.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(i, 10.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(i + 1.0f, 10.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(i + 1.0f, 9.0f, 0.0f);
glEnd();
}
glDisable(GL_TEXTURE_2D);
}

pbivens
06-05-2015, 10:46 AM
I have made some progress, can I please get a little help

pbivens
06-07-2015, 02:03 PM
I have almost solved my problem, I just need some suggestions.

Alfonse Reinheart
06-08-2015, 09:01 AM
I have almost solved my problem, I just need some suggestions.

That would require that you explain the problem correctly, as mhagain suggested, so that we could understand it enough to respond. Virtually every post you've made in this thread has been one line (followed sometimes by a block of code). That's not enough information for us to be able to help you.

We're not telepathic; we can't read your mind. All we have to go on is what you said.

pbivens
06-18-2015, 10:52 AM
well I am thinking about a proper question

pbivens
06-18-2015, 09:46 PM
Well I have made a little progress.
First I clear the screen.
Second I draw the space ship.
Third I draw the bullet.
Fourth I check to see if the bug sprite is hit.
Fifth I draw the collision sprite.

However when I hit the space bar to shoot the bullet the bug sprites disappear.

My question is how do I get the bullet to hit the bug sprite and then erase the bug sprite.

Here is the code I am using.



void bug_coll()
{
if (bugcoll == false)
{
draw_Scene_bug();
}

}

void drawScene()
{
glClear(GL_COLOR_BUFFER_BIT);

drawScene_ship();

drawScene_bullet();

bug_coll();

collision();

glutSwapBuffers();
}

let me know if you need any more explanation

pbivens
06-19-2015, 05:50 PM
also when I move the space ship from left to right or right to left using the arrow keys the sprites disappear also

pbivens
06-19-2015, 05:59 PM
well I added the draw_Scene_bug() command line that draws the bugs but the collision does not erase the bug sprite permanently.

pbivens
06-19-2015, 06:01 PM
here is the appended code I am using


void bug_coll()
{
if (bugcoll == false)
{
draw_Scene_bug();
}

}

void drawScene()
{
glClear(GL_COLOR_BUFFER_BIT);

drawScene_ship();

drawScene_bullet();

bug_coll();

draw_Scene_bug();

collision();

glutSwapBuffers();
}

pbivens
06-21-2015, 01:58 PM
can you help me carmine?

pbivens
06-24-2015, 06:16 PM
can I please get some help

pbivens
06-28-2015, 03:15 PM
well I am so close to solving my problem I just need a little help

Dark Photon
06-29-2015, 06:59 PM
You didn't actually ask a question.

pbivens
07-03-2015, 06:43 PM
well I am studying c++ I am reading a book and I am doing the exercises in the back of the chapters, I am doing this to brush up on my programming skills before I work on my game again.

NeveHanter
07-04-2015, 03:29 PM
You're using old OpenGL version (prior OpenGL 3.x) which are deprecated from long time. I'll highly suggest using modern OpenGL instead and start learning from www(dot)learnopengl(dot)com (as for now it's best modern OpenGL tutorial I've found). In later part of this tutorial you'll find step-by-step guide about how to write 2D pong game using modern OpenGL and you'll have chance to see how to make "bricks" disappear and how to construct a fully working game using modern OpenGL.

pbivens
07-04-2015, 04:36 PM
well I am stopping working on my game until I learn c++ better, thanks for all the help.