I tried to create a hidden buffer and then render to it the code to attach a camera to it is like :
mybuffer = base.win.makeTextureBuffer("My Buffer", 512, 512)
mytexture = mybuffer.getTexture()
mybuffer.setSort(-100)
mycamera = base.makeCamera(mybuffer)
myscene = NodePath("My Scene")
mycamera.node().setScene(myscene)
but in c++ the window->make_camera() does not have a parameter for buffer.
Also i want the buffer to contain the same models i used for window i will get the texture by get_texture()
Can someone tell me how its done.
My code :
// 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"
#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 camera2;
NodePath pandaActor;
WindowFramework *window;
//GraphicsWindow window;
PT(GraphicsBuffer) buff;
PT(DisplayRegion) dRegion1;
int done;
IplImage *image;
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);
printf("%d\n",ptex);
ptex = window->get_graphics_window()->get_texture();
printf("%d\n",ptex);
if(done)
{
int width = ptex->get_x_size();
int height = ptex ->get_y_size();
image = cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,4);
const unsigned char *img = &(*(ptex->get_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);
}
done = 1;
//window->get_graphics_output()->get_texture()->get_ram_image().get_data();
// Error in the above lines NULL pointer error.
//ptex->get_x_size();
//bgrimg = ptex->get_ram_image().
//ptex->get_ram_image();
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();
window = framework.open_window();
buff = window->get_graphics_output()->make_texture_buffer("my buffer",512,512);
window->make_camera(buff);
dRegion1 = window->get_graphics_output()->make_display_region(.75,1,.75,1);
dRegion1->set_sort(10);
camera2 = window->make_camera();
dRegion1->set_camera(camera2);
camera2.set_pos_hpr(0,0,40,0,-90,0);
camera = window->get_camera(0); // Get the camera and store it
ptex = new Texture("tex");
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);
// Load our panda
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");
// cvNamedWindow( "wind", CV_WINDOW_AUTOSIZE );
cvShowImage( "wind", image );
// 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);
framework.main_loop();
framework.close_framework();
return (0);
}
I am able to get the texture for the window and then convert to an opencv based iplimage format and display it too, but in this i even get the displayregion output which i do not want in the copy so i was trying to create a hidden buffer render it to that buffer get its texture and finally display it into the window(i do not know how its done yet help would be appreciated here too.)
Thanks.