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 // OSG Texture2D sets this, which breaks PLIB fntLoadTXF
83 // force it back to zero so width passed to glTexImage2D is used
84 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
86 FGFontCache *fc = FGFontCache::instance();
87 fc->initializeFonts();
89 = fc->get(globals->get_locale()->getDefaultFont("typewriter.txf"),
91 puSetDefaultFonts(*GuiFont, *GuiFont);
92 guiFnt = puGetDefaultLabelFont();
94 LayoutWidget::setDefaultFont(GuiFont, 15);
96 if (!fgHasNode("/sim/startup/mouse-pointer")) {
97 // no preference specified for mouse pointer
98 } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
101 // force showing pointer
107 // Operation for querying OpenGL parameters. This must be done in a
108 // valid OpenGL context, potentially in another thread.
110 struct GeneralInitOperation : public GraphicsContextOperation
112 GeneralInitOperation()
113 : GraphicsContextOperation(std::string("General init"))
116 void run(osg::GraphicsContext* gc)
118 SGPropertyNode* simRendering = fgGetNode("/sim/rendering");
120 simRendering->setStringValue("gl-vendor", (char*) glGetString(GL_VENDOR));
121 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VENDOR));
123 simRendering->setStringValue("gl-renderer", (char*) glGetString(GL_RENDERER));
124 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_RENDERER));
126 simRendering->setStringValue("gl-version", (char*) glGetString(GL_VERSION));
127 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VERSION));
129 // Old hardware without support for OpenGL 2.0 does not support GLSL and
130 // glGetString returns NULL for GL_SHADING_LANGUAGE_VERSION.
132 // See http://flightgear.org/forums/viewtopic.php?f=17&t=19670&start=15#p181945
133 const char* glsl_version = (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION);
135 glsl_version = "UNSUPPORTED";
136 simRendering->setStringValue("gl-shading-language-version", glsl_version);
137 SG_LOG( SG_GENERAL, SG_INFO, glsl_version);
140 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
141 simRendering->setIntValue("max-texture-size", tmp);
143 glGetIntegerv( GL_DEPTH_BITS, &tmp );
144 simRendering->setIntValue("depth-buffer-bits", tmp);
148 osg::ref_ptr<GUIInitOperation> initOp;
153 * Returns true when done, false when still busy (call again). */
156 static osg::ref_ptr<GeneralInitOperation> genOp;
160 // Pick some window on which to do queries.
161 // XXX Perhaps all this graphics initialization code should be
162 // moved to renderer.cxx?
163 genOp = new GeneralInitOperation;
164 osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
165 WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
166 osg::GraphicsContext* gc = 0;
168 gc = guiCamera->getGraphicsContext();
170 gc->add(genOp.get());
171 initOp = new GUIInitOperation;
172 gc->add(initOp.get());
174 wsa->windows[0]->gc->add(genOp.get());
176 return false; // not ready yet
180 if (!genOp->isFinished())
184 if (!initOp->isFinished())
193 void syncPausePopupState()
195 bool paused = fgGetBool("/sim/freeze/master",true) | fgGetBool("/sim/freeze/clock",true);
196 SGPropertyNode_ptr args(new SGPropertyNode);
197 args->setStringValue("id", "sim-pause");
198 if (paused && fgGetBool("/sim/view-name-popup")) {
199 args->setStringValue("label", "Simulation is paused");
200 globals->get_commands()->execute("show-message", args);
202 globals->get_commands()->execute("clear-message", args);