PDA

View Full Version : delete image



03-05-2002, 07:34 AM
is there a way to delete a polygon that has been drawn to the screen. I want to be able to move it and delete the polygon from its old position but i cant call glClear as this will clear other polygons which I want to remain.

Rajveer
03-05-2002, 07:43 AM
it would be better to just move it over using glTranslate(x, y, z)
specifying numbers for x, y and z for how much you'd like to move it in each direction.
Good luck!

03-05-2002, 07:55 AM
yes i do this but when i translate it i end up with 2 polygons and not 1 because im not calling glClear

Furrage
03-05-2002, 08:29 AM
No. There isn't a way as far as I know. A scene in OpenGL is additive, meaning you can add to the scene but you can't subtract. As such animators, etc. redraw the whole scene each time they want it to change. So that's what you'll have to do to get your shape moved.

Altenatively, you can redraw the background that was "under" the image over it, basically treating it like a sprite. I really have no idea how effective that would be though.

zeckensack
03-05-2002, 08:44 AM
Might be a job for the KTX_buffer_region extension. Should be pretty fast. But please note that that's not the way to do proper scene animation. As soon as you need to move your viewpoint it will stop working.

nexusone
03-05-2002, 08:45 AM
I think your problem is that you are not setting up your scene correctly.
You should be re-drawing the whole scene each time you move a object! And changing just the location of the object being moved.

Correct me if I am wrong but you are trying to move one object and leave the others stationary in your scene? But each time move the object a copy of the old object stays in the previous spot. Doing the above will correct that.


Originally posted by red:
is there a way to delete a polygon that has been drawn to the screen. I want to be able to move it and delete the polygon from its old position but i cant call glClear as this will clear other polygons which I want to remain.



[This message has been edited by nexusone (edited 03-05-2002).]

03-05-2002, 09:11 AM
ill try that so, what would be the best way to save information about all the objects, could i do it in a stack and just redraw the entire stack each time?

Furrage
03-05-2002, 09:49 AM
Normally all your drawing is in code. Typically for windows it's in the Paint function, or for glut it's your display callback. Thus everytime your screen is refreshed the code is called and the scene redrawn. So if you store the location of your objects in variables and refer to these variables in your drawing code, the image will automatically update each time the object is moved then the screen is redrawn.

If you are only changing a small part of the scene, then you might want to put the rest in a display list. Display lists show much faster than their equivalent in code.

nexusone
03-05-2002, 11:23 AM
Here is a example of how I handle it, though there are more advanced way's to do this.

You have a varible array called Objects
Each object in the array will have information about the object, like position, rotate, data to draw.

Here is a simple example:

Drawscene()
{
int i;
for(i=0; i < number_of_objects;i++)
{
glTranslate(Objects[i].x, Objects[i].y, Objects[i].z);
glRotate(Objects[i].x_axis, 1, 0, 0);
glRotate(Objects[i].y_axis, 1, 0, 0);
glRotate(Objects[i].z_axis, 1, 0, 0);
DrawObject(Objects[i].ObjectData);
}
glutSwapBuffers();
}

UpdateScene()
{
int i;
for(i=0; i < number_of_objects;i++)
{
if (Objects[i].status == 1) Only update objects that are moving. So we say moving objects have a status of 1, non-moving have a status of 0.
{
Update position
}
}
}



Originally posted by red:
ill try that so, what would be the best way to save information about all the objects, could i do it in a stack and just redraw the entire stack each time?