Buffer, attaching a camera to a buffer

i was trying to attach a camera to a hidden buffer, and render the image from a camera to the buffer, the camera renders well when i render it to the window then i can see it work well, but when i attach it to the buffer i cant see it. i tried writing show-buffers #t into config.prc file but i still could not get the window then i tried getting ram_image but it still did not work, can someone help me with it?
Thanks.

#include "stdafx.h" 
#include "pandaFramework.h" 
#include "pandaSystem.h" 
#include "displayregion.h" 
#include "genericAsyncTask.h" 
#include "asyncTaskManager.h" 
#include "eventHandler.h"    
#include "buttonThrower.h" 
#include "PNMImage.h" 
#include "texture.h" 
#include <cv.h>
#include <highgui.h>

using namespace cv;

PandaFramework framework; 
PT(AsyncTaskManager) taskMgr = AsyncTaskManager::get_global_ptr(); 
PT(ClockObject) globalClock = ClockObject::get_global_clock(); 

PT(Texture) ptex; 

NodePath camera; 
NodePath buffcam; 

NodePath pandaActor; 
WindowFramework *window;

PT(GraphicsOutput) buff;
PT(DisplayRegion) buffregion; 
PT(GraphicsWindow) buffwin;

int done;
IplImage *image;

AsyncTask::DoneStatus CopyTask(GenericAsyncTask* task, void* data) { 

	ptex = buff->get_texture();
	//ptex = window ->get_graphics_output()->get_texture();
	printf("Has Ram_image %d\n",ptex->has_ram_image());
	if(ptex->has_ram_image()==true)
	{	
		printf("Entered the loop\n");
		int width = ptex->get_x_size();
		int height = ptex ->get_y_size();
		image = cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,4);
		CPTA_uchar ram_image = ptex->get_ram_image(); 
		if(ram_image.empty())
		{
			printf("Leaving\n");
			return AsyncTask::DS_cont; 
		}
		const unsigned char *img = ram_image; 

		int ws = image -> widthStep;
		for(int i=0;i<2 * height;i++)
			for(int j=0;j<4 * width;j++)
				image->imageData[(i) * ws/2+ j/2] = img[(2 * height - i) * ws + j];

		cvShowImage("wind", image);
		cvReleaseImage(&image);

	}
	return AsyncTask::DS_cont; 
} 

int main(int argc, char *argv[]) { 

	framework.open_framework(argc, argv); 
	framework.set_window_title("My Panda3D Window"); 

	window = framework.open_window();

	camera = window->get_camera(0); 
	buffcam = window->make_camera();

	ptex = new Texture("tex");

	buff = window->get_graphics_output()->make_texture_buffer("my buffer",512,512);
	buffregion = buff->make_display_region();
	buffregion->set_camera(buffcam);
	buff->setup_render_texture(ptex,true,true);


	NodePath environ = window->load_model(framework.get_models(), "models/environment"); 
	environ.reparent_to(window->get_render()); 
	environ.set_scale(0.25 , 0.25, 0.25); 
	environ.set_pos(-8, 42, 0); 
	camera.set_pos(0,-20,3); 
	camera.set_hpr(0, 0, 0); 

	buff = window->get_graphics_output()->make_texture_buffer("my buffer",512,512);
	buff->set_sort(-100);


	pandaActor = window->load_model(framework.get_models(), "panda-model"); 
	pandaActor.set_scale(0.005); 
	pandaActor.reparent_to(window->get_render()); 

	cvNamedWindow( "wind", CV_WINDOW_AUTOSIZE );
	image = cvLoadImage( "C://Users//Public//Pictures//Sample Pictures//Desert.JPG");
	cvShowImage( "wind", image );


	window->load_model(pandaActor, "panda-walk4"); 
	window->loop_animations(0); 

	taskMgr->add(new GenericAsyncTask("Copy Task", &CopyTask, (void*) NULL)); 
	//buff->setup_render_texture(ptex,false,true);
	//window->get_graphics_output()->setup_render_texture(ptex,false,true); 
	framework.main_loop(); 


	framework.close_framework(); 
	return (0); 
}

got the problem
buff = window->get_graphics_output()->make_texture_buffer(“my buffer”,512,512);
line was written twice hence the buffer was getting changed.
Thanks anyway