Offscreen GraphicsBuffer Example Question

Hi,

I’m new to Panda3D. I’d like to implement an offscreen graphics buffer for some custom rendering I’m experimenting with. I’ve read through the rendering documentation. Is there an example (preferably C++ but Python is OK) that shows how to do this?

Cheers,

Chris

The Teapot on TV sample program shows how to do this. It is Python but the API is quite similar for C++. If you run into any specific issues, we’ll be happy to help.

Thanks for the help.

Here’s what I’d like to do:

  1. Render the scene into an offscreen buffer using colours that are different to those in the main window and using a different camera direction.

  2. Read back some of the pixels from the offscreen buffer.

I need to do this regularly as the app runs but not necessarily for every frame - something like once a second would be ok.

So, the first thing I need to do is create an offscreen output buffer?

Here’s what I’ve tried:

string bufferName(“myBuffer”);
GraphicsOutput* buffer;
buffer = GraphicsEngine::make_buffer(window, bufferName, 0, 100, 100);

When I add this code to the first C++ example in the manual I get the following error:

Panda3D_C++_Test.cpp:21: error: no matching function for call to ‘GraphicsEngine::make_buffer(WindowFramework*&, std::string&, int, int, int)’
/Applications/Panda3D/1.6.2/include/graphicsEngine.I:121: note: candidates are: GraphicsOutput* GraphicsEngine::make_buffer(GraphicsStateGuardian*, const std::string&, int, int, int)
make: *** [test.o] Error 1

How do I get the GraphicsStateGuardian* or is there another way to do this?

Pass window->get_graphics_window() as first parameter to make_buffer.

I tried what was suggested however I’m still getting an error:

Panda3D_C++_Test.cpp: In function ‘int main(int, char**)’:
Panda3D_C++_Test.cpp:21: error: no matching function for call to ‘GraphicsEngine::make_buffer(GraphicsWindow*, const std::string&, int, int, int)’
/Applications/Panda3D/1.6.2/include/graphicsEngine.I:121: note: candidates are: GraphicsOutput* GraphicsEngine::make_buffer(GraphicsStateGuardian*, const std::string&, int, int, int)
make: *** [test.o] Error 1

BTW, I’m working on OSX however my MacBook only has an Intel GMA 950 graphics processor. I set the renderer to tinydisplay as this was the only one I could get to work. Could this be a problem?

Here’s the full source code I’m using:

#include “pandaFramework.h”
#include “pandaSystem.h”

PandaFramework framework;

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

// Open a new window framework
framework.open_framework(argc, argv);

// Set the window title to My Panda3D Window
framework.set_window_title("Panda3D Sound Source Occlusion Test");

// Open the window
WindowFramework *window = framework.open_window();

// Here is room for your own code.
const string bufferName("myBuffer");

GraphicsOutput* buffer; 
buffer = GraphicsEngine::make_buffer(window->get_graphics_window(), bufferName, 0, 100, 100);   

// Do the main loop, equal to run() in python
framework.main_loop();

// Close the window framework
framework.close_framework();

return (0);

}

Oh, sorry, I misread. It should be window->get_graphics_window()->get_gsg().

I’m still getting errors:

Panda3D_C++_Test.cpp:23: error: cannot call member function ‘GraphicsOutput* GraphicsEngine::make_buffer(GraphicsStateGuardian*, const std::string&, int, int, int)’ without object
make: *** [test.o] Error 1

Here’s the code:

GraphicsWindow* gw = window->get_graphics_window();
GraphicsStateGuardian* gsg = gw->get_gsg();

GraphicsOutput* buffer;
buffer = GraphicsEngine::make_buffer(gsg, bufferName, 0, 100, 100);

You’re calling it as if it were a static method. Try something like:

PT(GraphicsWindow) gw = window->get_graphics_window();
PT(GraphicsStateGuardian) gsg = gw->get_gsg();

PT(GraphicsOutput) buffer;
buffer = gsg->get_engine()->make_buffer(gsg, bufferName, 0, 100, 100);