Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Howto:CameraGroup talks

From FlightGear wiki
Jump to: navigation, search
This article is a stub. You can help the wiki by expanding it.
Screenshot showing procedurally added camera groups

Prerequisites

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;
    }

Background

Objective