1 /**************************************************************************
4 * Written 1998 by Durk Talsma, started Juni, 1998. For the flight gear
7 * Additional mouse supported added by David Megginson, 1999.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 **************************************************************************/
31 #include <simgear/compiler.h>
35 #include <simgear/structure/exception.hxx>
36 #include <simgear/structure/commands.hxx>
38 #include <simgear/misc/sg_path.hxx>
39 #include <simgear/props/props.hxx>
40 #include <simgear/props/props_io.hxx>
44 #include <Main/main.hxx>
45 #include <Main/globals.hxx>
46 #include <Main/locale.hxx>
47 #include <Main/fg_props.hxx>
48 #include <Viewer/WindowSystemAdapter.hxx>
49 #include <Viewer/CameraGroup.hxx>
50 #include <GUI/new_gui.hxx>
51 #include <GUI/FGFontCache.hxx>
56 #include <osg/GraphicsContext>
58 using namespace flightgear;
63 /* -------------------------------------------------------------------------
65 _____________________________________________________________________*/
69 class GUIInitOperation : public GraphicsContextOperation
72 GUIInitOperation() : GraphicsContextOperation(std::string("GUI init"))
75 void run(osg::GraphicsContext* gc)
77 WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
79 puSetDefaultStyle ( PUSTYLE_SMALL_SHADED ); //PUSTYLE_DEFAULT
80 puSetDefaultColourScheme (0.8, 0.8, 0.9, 1);
82 FGFontCache *fc = globals->get_fontcache();
83 fc->initializeFonts();
85 = fc->get(globals->get_locale()->getDefaultFont("typewriter.txf"),
87 puSetDefaultFonts(*GuiFont, *GuiFont);
88 guiFnt = puGetDefaultLabelFont();
90 LayoutWidget::setDefaultFont(GuiFont, 15);
92 if (!fgHasNode("/sim/startup/mouse-pointer")) {
93 // no preference specified for mouse pointer
94 } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
97 // force showing pointer
103 // Operation for querying OpenGL parameters. This must be done in a
104 // valid OpenGL context, potentially in another thread.
106 struct GeneralInitOperation : public GraphicsContextOperation
108 GeneralInitOperation()
109 : GraphicsContextOperation(std::string("General init"))
112 void run(osg::GraphicsContext* gc)
114 SGPropertyNode* simRendering = fgGetNode("/sim/rendering");
116 simRendering->setStringValue("gl-vendor", (char*) glGetString(GL_VENDOR));
117 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VENDOR));
119 simRendering->setStringValue("gl-renderer", (char*) glGetString(GL_RENDERER));
120 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_RENDERER));
122 simRendering->setStringValue("gl-version", (char*) glGetString(GL_VERSION));
123 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VERSION));
125 // Old hardware without support for OpenGL 2.0 does not support GLSL and
126 // glGetString returns NULL for GL_SHADING_LANGUAGE_VERSION.
128 // See http://flightgear.org/forums/viewtopic.php?f=17&t=19670&start=15#p181945
129 const char* glsl_version = (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION);
131 glsl_version = "UNSUPPORTED";
132 simRendering->setStringValue("gl-shading-language-version", glsl_version);
133 SG_LOG( SG_GENERAL, SG_INFO, glsl_version);
136 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
137 simRendering->setIntValue("max-texture-size", tmp);
139 glGetIntegerv( GL_DEPTH_BITS, &tmp );
140 simRendering->setIntValue("depth-buffer-bits", tmp);
144 osg::ref_ptr<GUIInitOperation> initOp;
149 * Returns true when done, false when still busy (call again). */
152 static osg::ref_ptr<GeneralInitOperation> genOp;
156 // Pick some window on which to do queries.
157 // XXX Perhaps all this graphics initialization code should be
158 // moved to renderer.cxx?
159 genOp = new GeneralInitOperation;
160 osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
161 WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
162 osg::GraphicsContext* gc = 0;
164 gc = guiCamera->getGraphicsContext();
166 gc->add(genOp.get());
167 initOp = new GUIInitOperation;
168 gc->add(initOp.get());
170 wsa->windows[0]->gc->add(genOp.get());
172 return false; // not ready yet
176 if (!genOp->isFinished())
180 if (!initOp->isFinished())
189 void syncPausePopupState()
191 bool paused = fgGetBool("/sim/freeze/master",true) | fgGetBool("/sim/freeze/clock",true);
192 SGPropertyNode_ptr args(new SGPropertyNode);
193 args->setStringValue("id", "sim-pause");
194 if (paused && fgGetBool("/sim/view-name-popup")) {
195 args->setStringValue("label", "Simulation is paused");
196 globals->get_commands()->execute("show-message", args);
198 globals->get_commands()->execute("clear-message", args);