About setup_render_texture

I was trying to use the setup_render_texture method, always it gives a null pointer error can someone tell what am i doing incorrectly?
Any help would be greatly appreciated.

// MovingPanda.cpp : Defines the entry point for the console application. 
// 

#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"


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

NodePath camera; 

NodePath pandaActor; 
WindowFramework *window;
PT(Texture) ptex;

void event_button_down (const Event* evenmt, void* data) ; 
// Task to move the camera 
AsyncTask::DoneStatus SpinCameraTask(GenericAsyncTask* task, void* data) { 
	double time = globalClock->get_real_time(); 
	double angledegrees = time * 6.0; 
	double angleradians = angledegrees * (3.14 / 180.0); 

	// Using PNMImage too slow    
	//	 PNMImage pImage;
	//	 window->get_graphics_output()->get_screenshot(pImage);	


	//    ptex->get_ram_image().get_data();
	window->get_graphics_output()->get_texture()->get_ram_image().get_data();
	// Error in the above lines NULL pointer error.

	pandaActor.set_pos(10*cos(angleradians),10*sin(angleradians),0); 
	pandaActor.set_hpr(180+angledegrees,0,0); 
	return AsyncTask::DS_cont; 
} 

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

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

	// Open the window 

	window = framework.open_window(); 
	camera = window->get_camera(0); // Get the camera and store it 

	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,0,3); 
	camera.set_hpr(0, 0, 0); 

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

	// Load the walk animation 
	window->load_model(pandaActor, "panda-walk4"); 
	window->loop_animations(0); 

	taskMgr->add(new GenericAsyncTask("Spins the camera", &SpinCameraTask, (void*) NULL)); 
	//window->get_graphics_output()->setup_render_texture(ptex,false,true);
	//did not work
	framework.main_loop(); 


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

You forgot to set ptex to a new texture.

Thanks, got that working, but now i do not know how is the data actually stored in the ptex->get_ram_image().get_data() after this how do i get the image out of it, i was attempting to convert it to an iplimage as required in opencv so i made the call

cvInitMatHeader( &Mat, ptex->get_ram_image().get_data().size(),ptex->get_ram_image().get_data().size(), CV_8SC4, ptex->get_ram_image().get_data() , CV_AUTOSTEP );

some documentation for this call

InitMatNDHeader

Initializes multi-dimensional array header
void cvInitMatNDHeader( CvMatND* mat, int dims, int* size, int type, void* data=0 );

mat
Pointer to the array header to be initialized.
rows
Number of rows in the matrix.
cols
Number of columns in the matrix.
type
Type of the matrix elements.
data
Optional data pointer assigned to the matrix header.

The function cvInitMatNDHeader initializes already allocated CvMatND structure.
present at:http://www710.univ-lyon1.fr/~bouakaz/OpenCV-0.9.5/docs/ref/OpenCVRef_BasicFuncs.htm
Can someone tell what next??
Thanks

The data is stored as triples of BGR, or possibly quadruples of BGRA, depending on whether there is an alpha channel provided.

You can determine the precise layout of the data by examining the Texture properties, specifically get_x_size(), get_y_size(), get_num_components(), get_component_width(), get_component_type(), and get_format().

You can also use get_ram_image_as() to pre-convert the image to a particular format you’re prepared to handle, but this involves an extra processing step.

You should probably call get_ram_image() only once and save the result, rather than calling it repeatedly in the same function call.

David