1998-07-06 02:42:36 +00:00
|
|
|
// splash.cxx -- draws the initial splash screen
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started July 1998. (With a little looking
|
|
|
|
// at Freidemann's panel code.) :-)
|
|
|
|
//
|
|
|
|
// Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1998-07-06 02:42:36 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2007-05-03 18:12:29 +00:00
|
|
|
#include <osg/BlendFunc>
|
|
|
|
#include <osg/Camera>
|
|
|
|
#include <osg/Depth>
|
|
|
|
#include <osg/Geometry>
|
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/NodeCallback>
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
#include <osg/StateSet>
|
|
|
|
#include <osg/Switch>
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
#include <osgUtil/CullVisitor>
|
|
|
|
#include <osgText/Text>
|
|
|
|
#include <osgDB/ReadFile>
|
1998-07-06 02:42:36 +00:00
|
|
|
|
2004-11-18 19:53:00 +00:00
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
2000-02-16 23:01:03 +00:00
|
|
|
#include <simgear/debug/logstream.hxx>
|
2000-12-04 05:26:40 +00:00
|
|
|
#include <simgear/math/sg_random.h>
|
2001-03-25 14:20:12 +00:00
|
|
|
#include <simgear/misc/sg_path.hxx>
|
1998-07-06 02:42:36 +00:00
|
|
|
|
2005-07-07 21:43:22 +00:00
|
|
|
#include <GUI/new_gui.hxx>
|
|
|
|
|
The following changes were made to flightgear-0.7.5 code to implement the follow
ing features:
a) ADA Flight model - ADA.cxx, ADA.hxx, flight.hxx
b) Fighter a/c HUD - flight.hxx, hud.hxx, hud.cxx, cockpit.cxx, hud_ladr.c
xx, hud_card.cxx
c) 3-window display - options.hxx, options.cxx, viewer.cxx
d) Moving objects (ship) - main.cxx
e) Patches - main.cxx
ADA.cxx, ADA.hxx
--------------------------
Interface to the external ADA flight dynamics package.
flight.hxx
----------
Included prototypes for accepting additional data fron the External flight
model for fighter aircraft HUD
Hud.hxx
-------
Included prototypes for accepting additional data for fighter HUD from Exernal F
light model.
Defined FIGHTER_HUD pre-processor directive to enable compilation of fighter hud
code.
hud.cxx, cockpit.cxx, hud_ladr.cxx, hud_card.cxx
---------------------------------------
Included code to initialise additional reticles/text for fighter HUD which is co
nditionally
compiled if FIGHTER_HUD is defined.
options.hxx
-----------
Added window_offset, and function to retrieve its value for 3 windows
options.cxx
-----------
Changed few options to suit ADA/CEF projection system/screens and checks for win
dow offset.
views.cxx
---------
Added code to retrieve view offset for window.
Main.cxx
--------
Added code to load and move an aircraft carrier.
Patch to enable clouds from command line until Curtis fixes it. By default cloud
s are disabled.
2000-10-19 19:46:13 +00:00
|
|
|
#include "globals.hxx"
|
2001-01-13 22:06:39 +00:00
|
|
|
#include "fg_props.hxx"
|
1998-07-06 02:42:36 +00:00
|
|
|
#include "splash.hxx"
|
2006-01-28 13:38:28 +00:00
|
|
|
#include "renderer.hxx"
|
2007-05-03 18:12:29 +00:00
|
|
|
#include "fg_os.hxx"
|
2004-03-31 21:10:32 +00:00
|
|
|
|
2007-05-03 18:12:29 +00:00
|
|
|
class FGSplashUpdateCallback : public osg::Drawable::UpdateCallback {
|
|
|
|
public:
|
|
|
|
FGSplashUpdateCallback(osg::Vec4Array* colorArray, SGPropertyNode* prop) :
|
|
|
|
_colorArray(colorArray),
|
|
|
|
_colorProperty(prop),
|
|
|
|
_alphaProperty(fgGetNode("/sim/startup/splash-alpha", true))
|
|
|
|
{ }
|
|
|
|
virtual void update(osg::NodeVisitor*, osg::Drawable*)
|
|
|
|
{
|
|
|
|
FGColor c(0, 0, 0);
|
|
|
|
if (_colorProperty) {
|
|
|
|
c.merge(_colorProperty);
|
|
|
|
(*_colorArray)[0][0] = c.red();
|
|
|
|
(*_colorArray)[0][1] = c.green();
|
|
|
|
(*_colorArray)[0][2] = c.blue();
|
|
|
|
}
|
|
|
|
(*_colorArray)[0][3] = _alphaProperty->getFloatValue();
|
|
|
|
_colorArray->dirty();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
osg::ref_ptr<osg::Vec4Array> _colorArray;
|
|
|
|
SGSharedPtr<const SGPropertyNode> _colorProperty;
|
|
|
|
SGSharedPtr<const SGPropertyNode> _alphaProperty;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FGSplashTextUpdateCallback : public osg::Drawable::UpdateCallback {
|
|
|
|
public:
|
|
|
|
FGSplashTextUpdateCallback(const SGPropertyNode* prop) :
|
|
|
|
_textProperty(prop),
|
|
|
|
_alphaProperty(fgGetNode("/sim/startup/splash-alpha", true)),
|
|
|
|
_styleProperty(fgGetNode("/sim/gui/style[0]", true))
|
|
|
|
{}
|
|
|
|
virtual void update(osg::NodeVisitor*, osg::Drawable* drawable)
|
|
|
|
{
|
|
|
|
assert(dynamic_cast<osgText::Text*>(drawable));
|
|
|
|
osgText::Text* text = static_cast<osgText::Text*>(drawable);
|
|
|
|
|
|
|
|
FGColor c(1.0, 0.9, 0.0);
|
|
|
|
c.merge(_styleProperty->getNode("colors/splash-font"));
|
|
|
|
float alpha = _alphaProperty->getFloatValue();
|
|
|
|
text->setColor(osg::Vec4(c.red(), c.green(), c.blue(), alpha));
|
|
|
|
|
|
|
|
const char* s = _textProperty->getStringValue();
|
|
|
|
if (s && fgGetBool("/sim/startup/splash-progress", true))
|
|
|
|
text->setText(s);
|
|
|
|
else
|
|
|
|
text->setText("");
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SGSharedPtr<const SGPropertyNode> _textProperty;
|
|
|
|
SGSharedPtr<const SGPropertyNode> _alphaProperty;
|
|
|
|
SGSharedPtr<const SGPropertyNode> _styleProperty;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FGSplashContentProjectionCalback : public osg::NodeCallback {
|
|
|
|
public:
|
|
|
|
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
|
|
|
{
|
|
|
|
assert(dynamic_cast<osgUtil::CullVisitor*>(nv));
|
|
|
|
osgUtil::CullVisitor* cullVisitor = static_cast<osgUtil::CullVisitor*>(nv);
|
|
|
|
|
|
|
|
// adjust the projection matrix in a way that preserves the aspect ratio
|
|
|
|
// of the content ...
|
|
|
|
const osg::Viewport* viewport = cullVisitor->getViewport();
|
|
|
|
float viewportAspect = float(viewport->height())/float(viewport->width());
|
|
|
|
|
|
|
|
float height, width;
|
|
|
|
if (viewportAspect < 1) {
|
|
|
|
height = 1;
|
|
|
|
width = 1/viewportAspect;
|
|
|
|
} else {
|
|
|
|
height = viewportAspect;
|
|
|
|
width = 1;
|
2005-05-06 09:08:44 +00:00
|
|
|
}
|
1998-07-06 02:42:36 +00:00
|
|
|
|
2007-05-03 18:12:29 +00:00
|
|
|
osg::RefMatrix* matrix = new osg::RefMatrix;
|
|
|
|
matrix->makeOrtho2D(-width, width, -height, height);
|
2007-05-02 18:49:31 +00:00
|
|
|
|
2007-05-03 18:12:29 +00:00
|
|
|
// The trick is to have the projection matrix adapted independent
|
|
|
|
// of the scenegraph but dependent on the viewport of this current
|
|
|
|
// camera we cull for. Therefore we do not put that projection matrix into
|
|
|
|
// an additional camera rather than from within that cull callback.
|
|
|
|
cullVisitor->pushProjectionMatrix(matrix);
|
|
|
|
traverse(node, nv);
|
|
|
|
cullVisitor->popProjectionMatrix();
|
|
|
|
}
|
|
|
|
};
|
2007-05-02 18:49:31 +00:00
|
|
|
|
2007-05-03 18:12:29 +00:00
|
|
|
static osg::Node* fgCreateSplashCamera()
|
2007-05-02 18:49:31 +00:00
|
|
|
{
|
2007-05-03 18:12:29 +00:00
|
|
|
const char* splash_texture = fgGetString("/sim/startup/splash-texture");
|
|
|
|
SGSharedPtr<SGPropertyNode> style = fgGetNode("/sim/gui/style[0]", true);
|
|
|
|
|
|
|
|
SGPath tpath( globals->get_fg_root() );
|
|
|
|
if (splash_texture == NULL || !strcmp(splash_texture, "")) {
|
|
|
|
// load in the texture data
|
|
|
|
int num = (int)(sg_random() * 5.0 + 1.0);
|
|
|
|
char num_str[5];
|
|
|
|
snprintf(num_str, 4, "%d", num);
|
|
|
|
|
|
|
|
tpath.append( "Textures/Splash" );
|
|
|
|
tpath.concat( num_str );
|
2008-10-14 06:11:44 +00:00
|
|
|
tpath.concat( ".png" );
|
2007-05-03 18:12:29 +00:00
|
|
|
} else
|
|
|
|
tpath.append( splash_texture );
|
|
|
|
|
|
|
|
osg::Texture2D* splashTexture = new osg::Texture2D;
|
|
|
|
splashTexture->setImage(osgDB::readImageFile(tpath.c_str()));
|
|
|
|
|
|
|
|
osg::Camera* camera = new osg::Camera;
|
|
|
|
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
|
|
|
camera->setProjectionMatrix(osg::Matrix::ortho2D(-1, 1, -1, 1));
|
|
|
|
camera->setViewMatrix(osg::Matrix::identity());
|
|
|
|
camera->setRenderOrder(osg::Camera::POST_RENDER, 10000);
|
|
|
|
camera->setClearMask(0);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
camera->setCullingActive(false);
|
|
|
|
|
|
|
|
osg::StateSet* stateSet = camera->getOrCreateStateSet();
|
|
|
|
stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF);
|
|
|
|
stateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
|
|
|
|
stateSet->setAttribute(new osg::BlendFunc);
|
|
|
|
stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
|
|
|
|
stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
|
|
|
|
stateSet->setAttribute(new osg::Depth(osg::Depth::ALWAYS, 0, 1, false));
|
|
|
|
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
|
|
|
|
|
|
|
|
|
|
|
osg::Geometry* geometry = new osg::Geometry;
|
|
|
|
geometry->setSupportsDisplayList(false);
|
|
|
|
|
|
|
|
osg::Vec3Array* vertexArray = new osg::Vec3Array;
|
|
|
|
vertexArray->push_back(osg::Vec3(-1, -1, 0));
|
|
|
|
vertexArray->push_back(osg::Vec3( 1, -1, 0));
|
|
|
|
vertexArray->push_back(osg::Vec3( 1, 1, 0));
|
|
|
|
vertexArray->push_back(osg::Vec3(-1, 1, 0));
|
|
|
|
geometry->setVertexArray(vertexArray);
|
|
|
|
osg::Vec4Array* colorArray = new osg::Vec4Array;
|
|
|
|
colorArray->push_back(osg::Vec4(0, 0, 0, 1));
|
|
|
|
geometry->setColorArray(colorArray);
|
|
|
|
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
|
|
|
|
geometry->addPrimitiveSet(new osg::DrawArrays(GL_POLYGON, 0, 4));
|
|
|
|
geometry->setUpdateCallback(new FGSplashUpdateCallback(colorArray,
|
|
|
|
style->getNode("colors/splash-screen")));
|
|
|
|
|
|
|
|
osg::Geode* geode = new osg::Geode;
|
|
|
|
geode->addDrawable(geometry);
|
|
|
|
|
|
|
|
stateSet = geode->getOrCreateStateSet();
|
|
|
|
stateSet->setRenderBinDetails(1, "RenderBin");
|
|
|
|
camera->addChild(geode);
|
|
|
|
|
|
|
|
|
|
|
|
// The group is needed because of osg is handling the cull callbacks in a
|
|
|
|
// different way for groups than for a geode. It does not hurt here ...
|
|
|
|
osg::Group* group = new osg::Group;
|
|
|
|
group->setCullCallback(new FGSplashContentProjectionCalback);
|
|
|
|
camera->addChild(group);
|
|
|
|
|
|
|
|
geode = new osg::Geode;
|
|
|
|
stateSet = geode->getOrCreateStateSet();
|
|
|
|
stateSet->setRenderBinDetails(2, "RenderBin");
|
|
|
|
group->addChild(geode);
|
|
|
|
|
|
|
|
|
|
|
|
geometry = new osg::Geometry;
|
|
|
|
geometry->setSupportsDisplayList(false);
|
|
|
|
|
|
|
|
vertexArray = new osg::Vec3Array;
|
|
|
|
vertexArray->push_back(osg::Vec3(-0.84, -0.84, 0));
|
|
|
|
vertexArray->push_back(osg::Vec3( 0.84, -0.84, 0));
|
|
|
|
vertexArray->push_back(osg::Vec3( 0.84, 0.84, 0));
|
|
|
|
vertexArray->push_back(osg::Vec3(-0.84, 0.84, 0));
|
|
|
|
geometry->setVertexArray(vertexArray);
|
|
|
|
osg::Vec2Array* texCoordArray = new osg::Vec2Array;
|
|
|
|
texCoordArray->push_back(osg::Vec2(0, 0));
|
|
|
|
texCoordArray->push_back(osg::Vec2(1, 0));
|
|
|
|
texCoordArray->push_back(osg::Vec2(1, 1));
|
|
|
|
texCoordArray->push_back(osg::Vec2(0, 1));
|
|
|
|
geometry->setTexCoordArray(0, texCoordArray);
|
|
|
|
colorArray = new osg::Vec4Array;
|
|
|
|
colorArray->push_back(osg::Vec4(1, 1, 1, 1));
|
|
|
|
geometry->setColorArray(colorArray);
|
|
|
|
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
|
|
|
|
geometry->addPrimitiveSet(new osg::DrawArrays(GL_POLYGON, 0, 4));
|
|
|
|
geometry->setUpdateCallback(new FGSplashUpdateCallback(colorArray, 0));
|
|
|
|
stateSet = geometry->getOrCreateStateSet();
|
|
|
|
stateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
|
|
|
|
stateSet->setTextureAttribute(0, splashTexture);
|
|
|
|
geode->addDrawable(geometry);
|
|
|
|
|
|
|
|
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
std::string fn = style->getStringValue("fonts/splash", "");
|
|
|
|
text->setFont(globals->get_fontcache()->getfntpath(fn.c_str()).str());
|
|
|
|
text->setCharacterSize(0.06);
|
|
|
|
text->setColor(osg::Vec4(1, 1, 1, 1));
|
|
|
|
text->setPosition(osg::Vec3(0, -0.92, 0));
|
|
|
|
text->setAlignment(osgText::Text::CENTER_CENTER);
|
|
|
|
SGPropertyNode* prop = fgGetNode("/sim/startup/splash-progress-text", true);
|
|
|
|
text->setUpdateCallback(new FGSplashTextUpdateCallback(prop));
|
|
|
|
geode->addDrawable(text);
|
|
|
|
|
|
|
|
text = new osgText::Text;
|
|
|
|
text->setFont(globals->get_fontcache()->getfntpath(fn.c_str()).str());
|
|
|
|
text->setCharacterSize(0.06);
|
|
|
|
text->setColor(osg::Vec4(1, 1, 1, 1));
|
|
|
|
text->setPosition(osg::Vec3(0, 0.92, 0));
|
|
|
|
text->setAlignment(osgText::Text::CENTER_CENTER);
|
|
|
|
prop = fgGetNode("/sim/startup/splash-title", true);
|
|
|
|
text->setUpdateCallback(new FGSplashTextUpdateCallback(prop));
|
|
|
|
geode->addDrawable(text);
|
|
|
|
|
|
|
|
return camera;
|
1998-07-06 02:42:36 +00:00
|
|
|
}
|
|
|
|
|
2007-05-03 18:12:29 +00:00
|
|
|
// update callback for the switch node guarding that splash
|
|
|
|
class FGSplashGroupUpdateCallback : public osg::NodeCallback {
|
|
|
|
public:
|
|
|
|
FGSplashGroupUpdateCallback() :
|
|
|
|
_splashAlphaNode(fgGetNode("/sim/startup/splash-alpha", true))
|
|
|
|
{ }
|
|
|
|
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
|
|
|
{
|
|
|
|
assert(dynamic_cast<osg::Group*>(node));
|
|
|
|
osg::Group* group = static_cast<osg::Group*>(node);
|
|
|
|
|
|
|
|
double alpha = _splashAlphaNode->getDoubleValue();
|
|
|
|
if (alpha <= 0 || !fgGetBool("/sim/startup/splash-screen"))
|
|
|
|
group->removeChild(0, group->getNumChildren());
|
|
|
|
else if (group->getNumChildren() == 0)
|
|
|
|
group->addChild(fgCreateSplashCamera());
|
|
|
|
|
|
|
|
traverse(node, nv);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SGSharedPtr<const SGPropertyNode> _splashAlphaNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
osg::Node* fgCreateSplashNode() {
|
|
|
|
osg::Group* group = new osg::Group;
|
|
|
|
group->setUpdateCallback(new FGSplashGroupUpdateCallback);
|
|
|
|
return group;
|
2005-05-06 09:08:44 +00:00
|
|
|
}
|
|
|
|
|
2007-05-03 18:12:29 +00:00
|
|
|
// Initialize the splash screen
|
|
|
|
void fgSplashInit () {
|
|
|
|
SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" );
|
|
|
|
globals->get_renderer()->splashinit();
|
|
|
|
fgRequestRedraw();
|
1998-07-06 02:42:36 +00:00
|
|
|
}
|
|
|
|
|
2007-05-03 18:12:29 +00:00
|
|
|
void fgSplashProgress ( const char *text ) {
|
|
|
|
SG_LOG( SG_GENERAL, SG_INFO, "Splash screen progress " << text );
|
|
|
|
fgSetString("/sim/startup/splash-progress-text", text);
|
|
|
|
fgRequestRedraw();
|
|
|
|
}
|