This example is part of OpenSceneGraph cross-platform examples.
In this example we implement debug-broker's protocol to support remote debugging across platforms.
Note: this example requires 03.HTTPClient example knowledge.
Remote debugging assumes application and debug UI are located at different machines. The most widespread way to communicate between remote machines nowadays is to use HTTP(s) over TCP/IP.
We use debug-broker's protocol to implement remote debugging.
debug-broker is a mediator between debugged application (this example) and
debug UI (source of user input).
debug-broker has the following concepts:
- Debugger
- is a container of so-called debug pages
- usually represents a single application
- requires client code to call its
process()function regularly to perform requests
- Page
- is a container of so-called debug items
- usually represents a set of related items, e.g.,
Cameraproperties
- Item
- contains alterable entries
- usually represents properties, e.g.,
BackgroundColoritem forCamerapage - can be read-only or read-write
debug-broker accepts and replies in JSON format. We use
NLohmann's JSON to parse incoming JSON. Outgoing JSON
is currently composed manually.
Note: clone NLohmann's JSON alongside OpenSceneGraph cross-platfrom examples' repository.
debug-broker concepts are mapped to the following classes:
- Debugger
- is a container for
Pages - uses
HTTPClientinstance to communicate withdebug-broker - makes new request
- each second
- only after previous request has been completed
- is a container for
- Page
- is a container for
Page::Items
- is a container for
- Page::Item
- is an entry with alterable value
Client code:
- creates
Debuggerinstance (source code):this->debugger = new debug::Debugger(this->httpClient, name); - provides
debug-broker's address (source code):this->debugger->setBrokerURL("http://localhost:7999"); - regularly calls
Debugger'sprocess()function (source code):this->debugger->process();
Now that we covered prerequisites, it's time to debug.
Let's debug camera:
- alter background color
- retrieve camera's position and rotation
We can only get camera's position from camera manipulator. Install one (source code):
this->cameraManip = new osgGA::TrackballManipulator;
this->viewer->setCameraManipulator(this->cameraManip);
Create debug page to collect camera related items (source code):
- - - -
debug::Page debugPage;
- - - -
this->debugPage.title = "camera";
- - - -
To retrieve camera's position and rotation, we need to register
Postion/Rotation item with getter
(source code):
this->debugPage.addItem(
"Position/Rotation",
// Getter.
[&] {
- - - -
return
format::printfString(
"%f,%f,%f/%f,%f,%f",
pos.x(), pos.y(), pos.z(),
rot.x(), rot.y(), rot.z()
);
}
);
To alter background (camera) color, we need to register
BGColor item with both getter and setter
(source code):
this->debugPage.addItem(
"BGColor",
// Getter.
[&] {
- - - -
return format::printfString("%d,%d,%d", r, g, b);
},
// Setter.
[&](const std::string &value) {
- - - -
this->camera()->setClearColor(color);
}
);
Finally, add camera's debug page to Debugger
(source code):
this->debugger->addPage(this->debugPage);

Here's a web build of the example.
Now open debug UI and change background color to 255,0,0.