Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: save current window drawing before clear?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    16

    save current window drawing before clear?

    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,

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: save current window drawing before clear?

    hmm you want to both clear and keep the current framebuffer ? make up your mind

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    16

    Re: save current window drawing before clear?

    Well, this is what happens when i dont clear:
    http://img708.imageshack.us/img708/2...reenshot1w.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.

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: save current window drawing before clear?

    glCopyTexSubImage2d the current framebuffer to a texture, then render the texture at a different place.

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    16

    Re: save current window drawing before clear?

    Hmm, I dont think that this would really help me.
    Here are selected pieces of code:
    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

    Code :
    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;
    }

    Code :
    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?

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    16

    Re: save current window drawing before clear?

    notice this specific line:
    Code :
       	//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

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    16

    Re: save current window drawing before clear?

    any suggestions anyone? =)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •