PDA

View Full Version : save current window drawing before clear?



Loderunner
02-18-2010, 02:38 PM
So I have a collection of different trignometric shapes being drawn and updated constantly. I just incorporated a panning-zoom out system from http://www.nigels.com/glt/gltzpr/

The problem is that to pan properly I need to call
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
If the clear isn't called the drawing is just copied onto itself.
If clear IS called then the drawing keeps clearing and only drawing the newest part (think of a 2d map that only displays the newest segment and location instead of the previous history)

Is there a way to save the entire current image and then run the clear so that the image can be panned?
Thanks,

ZbuffeR
02-18-2010, 03:09 PM
hmm you want to both clear and keep the current framebuffer ? make up your mind :)

Loderunner
02-18-2010, 03:27 PM
Well, this is what happens when i dont clear:
http://img708.imageshack.us/img708/2180/screenshot1w.png

I want to be able to move the image while clearing the old image. Was wondering if there was a way to save the current data somewhere and move it, clearing the old data.

ZbuffeR
02-19-2010, 12:32 AM
glCopyTexSubImage2d the current framebuffer to a texture, then render the texture at a different place.

Loderunner
02-19-2010, 05:31 PM
Hmm, I dont think that this would really help me.
Here are selected pieces of code:

//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(600, 600);

//Create the window
glutCreateWindow("2D map");
glutDisplayFunc(display);
//
/*------init panning-------------*/
zprInit();
zprSelectionFunc(drawScene); /* Selection mode draw function */
zprPickFunc(pickScene);
/*------end panning--------------*/
glutTimerFunc(100, update, 0); //Add a timer


void display(void)
{
/* Initialise OpenGL Lighting and material structure */
GLERROR;
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
GLERROR;
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
drawScene();
glutSwapBuffers();

GLERROR;
}


void drawScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
//glLoadIdentity(); //Reset the drawing perspective

glPushMatrix();
glTranslatef(0.0f, 0.0f, -5.0f); //Move forward 5 units into visible region



if((prevcoord[0]!=coordinates[0])&&(prevcoord[1]!=coordinates[1])){ //this if statement accounts for transmission lag
glPushMatrix(); //Save the current state of transformations
glPushName(1);
glColor3ub(255,255,255); //white
glBegin(GL_LINE_STRIP);
glVertex3f(prevcoord[0],prevcoord[1],prevcoord[2]);//initial line co-ordinate, needs to be updated to init GPSlocation
glVertex3f(coordinates[0],coordinates[1],coordinates[2]);
glEnd();
glPopName();
glPopMatrix();


//draws the red triangle with the current location of the igv
glPushMatrix(); //save previous translate and color
glPushName(2);
//glClear(GL_DEPTH_BUFFER_BIT);
glTranslatef(coordinates[0],coordinates[1],coordinates[2]);
glRotatef((360/(2*PI))*atan2(coordinates[1],coordinates[0]),coordinates[0],coordinates[1],coordinates[2]); //does rotation calc
//glRotatef((360/(2*PI))*atan2(coordinates[1],coordinates[0]),1,1,1); //does rotation calc
glColor3ub(255,0,0); //set to red
glBegin(GL_TRIANGLES);
glVertex2f(0,.05);
glVertex2f(0,-.05);
glVertex2f(.05,0);
glEnd();
glPopName();
glPopMatrix(); //restore previous translate and color
}

//this section erases the old triangle and overwrites it with a green dot
if((prevcoord[0]!=coordinates[0])&&(prevcoord[1]!=coordinates[1])){ //this if statement accounts for transmission lag
glPushMatrix(); //save previous translate and color
glPushName(3);
glTranslatef(prevcoord[0],prevcoord[1],prevcoord[2]);
glRotatef((360/(2*PI))*atan2(prevcoord[1],prevcoord[0]),prevcoord[0],prevcoord[1],prevcoord[2]);
//glRotatef((360/(2*PI))*atan2(prevcoord[1],prevcoord[0]),1,1,1);
glColor3ub(0,0,0); //set black
glBegin(GL_TRIANGLES);
glVertex2f(0,.05);
glVertex2f(0,-.05);
glVertex2f(.05,0);
glEnd();
glColor3ub(0,255,0); //set sphere to green
glutSolidSphere(.02,15,15); //radius, slices,stacks
glPopName();
glPopMatrix(); //restore previous translate and color
}
glPopMatrix();
glutSwapBuffers();
}

Any suggestions?

Loderunner
02-19-2010, 05:33 PM
notice this specific line:

//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);

if glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
is uncommented then it pans properly but only draws one line segment, one triangle and one green dot and erases the previous history

Loderunner
02-21-2010, 01:41 PM
any suggestions anyone? =)