Howto:CameraGroup talks: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(experiments ...)
 
m (+ Template:Stub; + Headings; cat: Core development projects)
 
(19 intermediate revisions by one other user not shown)
Line 1: Line 1:
cameras.xml
{{stub}}
 
[[File:Procedural-CameraGroups.png|thumb|Screenshot showing procedurally added camera groups]]
 
== 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 ==
<syntaxhighlight lang="c++">
    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";
</syntaxhighlight>
 
== APIs ==
=== Getting a handle to the viewer ===
<syntaxhighlight lang="c++">
#include <>
// ...
osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
</syntaxhighlight>
 
=== Getting a handle to the default camera group ===
<syntaxhighlight lang="c++">
#include <Viewer/CameraGroup.hxx>
// ...
CameraGroup::getDefault();
</syntaxhighlight>
 
=== Starting/stopping threading ===
<syntaxhighlight lang="c++">
#include <>
// ...
osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
viewer->startThreading();
viewer->stopThreading();
 
</syntaxhighlight>
 
=== Getting a handle to the default camera group ===
<syntaxhighlight lang="c++">
#include <Viewer/CameraGroup.hxx>
// ...
CameraGroup::getDefault();
</syntaxhighlight>
 
=== Adding a slave camera to the viewer ===
<syntaxhighlight lang="c++">
#include <>
// ...
osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
viewer->addSlave(camera, projection, view, useMasterSceneData);
// getViewer()->addSlave(camera, Matrixd::identity(), Matrixd::identity(), false);
 
</syntaxhighlight>
 
=== Getting a handle to the default camera group ===
<syntaxhighlight lang="c++">
#include <Viewer/CameraGroup.hxx>
// ...
CameraGroup::getDefault();
</syntaxhighlight>
 
=== Getting the texture of a buffer ===
<syntaxhighlight lang="c++">
#include <>
// ...
osg::Texture2D* CameraInfo::getBuffer(const std::string& k);
</syntaxhighlight>
 
== Camera setup ==
We can refer to $FG_SRC/Viewer/CameraGroup.cxx to see how the camera is set up:
 
<syntaxhighlight lang="cpp">
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
                                  ));
 
</syntaxhighlight>
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:
 
<syntaxhighlight lang="cpp">
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;
    }
</syntaxhighlight>
 
== Background ==
 
== Objective ==
 
<!--
== Experiments ==
$FG_HOME/cameras.xml
 
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<camera>
<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
 
<camera n="1">
     <host-name type="string"></host-name>
     <host-name type="string"></host-name>
     <display>0</display>
     <display>0</display>
Line 11: Line 144:
     <fullscreen type="bool">false</fullscreen>
     <fullscreen type="bool">false</fullscreen>
</camera>
</camera>
</PropertyList>
</syntaxhighlight>
</syntaxhighlight>


Open the [[Nasal Console]]:
Open the [[Nasal Console]]:
Line 18: Line 153:
<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
var path = getprop("/sim/fg-home") ~ "/cameras.xml";
var path = getprop("/sim/fg-home") ~ "/cameras.xml";
io.read_properties(path, "/sim/rendering");
io.read_properties(path, "/sim/rendering/camera-group");
</syntaxhighlight>
</syntaxhighlight>
-->
[[Category:Core development projects]]

Latest revision as of 21:51, 18 August 2019

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