Howto:CameraGroup talks
Jump to navigation
Jump to search
This article is a stub. You can help the wiki by expanding it. |
Prerequisites
- CameraGroupListener (see $FG_SRC/Viewer)
- PropertyList XML files
- http://wiki.flightgear.org/Nasal_library/io#read_properties.28.29
- http://wiki.flightgear.org/index.php?title=Howto:Configure_camera_view_windows&redirect=no
- https://sourceforge.net/p/flightgear/fgdata/ci/next/tree/Docs/README.multiscreen
- may need to add a new fgcommand and/or a listener based API to pick up live changes (try reset/re-init fgcommands first!)
Cameras
const char* MAIN_CAMERA = "main";
const char* FAR_CAMERA = "far";
const char* GEOMETRY_CAMERA = "geometry";
const char* SHADOW_CAMERA = "shadow";
const char* LIGHTING_CAMERA = "lighting";
const char* DISPLAY_CAMERA = "display";
APIs
Getting a handle to the viewer
#include <>
// ...
osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
Getting a handle to the default camera group
#include <Viewer/CameraGroup.hxx>
// ...
CameraGroup::getDefault();
Starting/stopping threading
#include <>
// ...
osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
viewer->startThreading();
viewer->stopThreading();
Getting a handle to the default camera group
#include <Viewer/CameraGroup.hxx>
// ...
CameraGroup::getDefault();
Adding a slave camera to the viewer
#include <>
// ...
osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
viewer->addSlave(camera, projection, view, useMasterSceneData);
// getViewer()->addSlave(camera, Matrixd::identity(), Matrixd::identity(), false);
Getting a handle to the default camera group
#include <Viewer/CameraGroup.hxx>
// ...
CameraGroup::getDefault();
Getting the texture of a buffer
#include <>
// ...
osg::Texture2D* CameraInfo::getBuffer(const std::string& k);
Camera setup
We can refer to $FG_SRC/Viewer/CameraGroup.cxx to see how the camera is set up:
Camera* camera = new Camera;
camera->setName("windowCamera");
camera->setAllowEventFocus(false);
camera->setGraphicsContext(window->gc.get());
camera->setViewport(new Viewport);
camera->setCullingMode(CullSettings::SMALL_FEATURE_CULLING
| CullSettings::VIEW_FRUSTUM_CULLING);
camera->setInheritanceMask(CullSettings::ALL_VARIABLES
& ~(CullSettings::CULL_MASK
| CullSettings::CULLING_MODE
| CullSettings::CLEAR_MASK
));
This setup is common to all camera modes supported by the CameraGroup manager.
RTT/FBO Setup
Note that we only need to look for "TextureRectangle" in CameraGroup.cxx to see how Tim is using that to set up a "TextureMap" with different RTT context for different cameras that render to a texture:
const SGPropertyNode* textureNode = cameraNode->getNode("texture");
if (textureNode) {
string texName = textureNode->getStringValue("name");
int tex_width = textureNode->getIntValue("width");
int tex_height = textureNode->getIntValue("height");
TextureRectangle* texture = new TextureRectangle;
texture->setTextureSize(tex_width, tex_height);
texture->setInternalFormat(GL_RGB);
texture->setFilter(Texture::MIN_FILTER, Texture::LINEAR);
texture->setFilter(Texture::MAG_FILTER, Texture::LINEAR);
texture->setWrap(Texture::WRAP_S, Texture::CLAMP_TO_EDGE);
texture->setWrap(Texture::WRAP_T, Texture::CLAMP_TO_EDGE);
camera->setDrawBuffer(GL_FRONT);
camera->setReadBuffer(GL_FRONT);
camera->setRenderTargetImplementation(Camera::FRAME_BUFFER_OBJECT);
camera->attach(Camera::COLOR_BUFFER, texture);
_textureTargets[texName] = texture;
}