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/misc/sg_path.hxx>
37 #include <simgear/props/props.hxx>
38 #include <simgear/props/props_io.hxx>
42 #include <Main/main.hxx>
43 #include <Main/globals.hxx>
44 #include <Main/locale.hxx>
45 #include <Main/fg_props.hxx>
46 #include <Viewer/WindowSystemAdapter.hxx>
47 #include <Viewer/CameraGroup.hxx>
48 #include <GUI/new_gui.hxx>
49 #include <GUI/FGFontCache.hxx>
54 #include <osg/GraphicsContext>
56 using namespace flightgear;
61 /* -------------------------------------------------------------------------
63 _____________________________________________________________________*/
67 class GUIInitOperation : public GraphicsContextOperation
70 GUIInitOperation() : GraphicsContextOperation(std::string("GUI init"))
73 void run(osg::GraphicsContext* gc)
75 WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
77 puSetDefaultStyle ( PUSTYLE_SMALL_SHADED ); //PUSTYLE_DEFAULT
78 puSetDefaultColourScheme (0.8, 0.8, 0.9, 1);
80 FGFontCache *fc = globals->get_fontcache();
81 fc->initializeFonts();
83 = fc->get(globals->get_locale()->getDefaultFont("typewriter.txf"),
85 puSetDefaultFonts(*GuiFont, *GuiFont);
86 guiFnt = puGetDefaultLabelFont();
88 LayoutWidget::setDefaultFont(GuiFont, 15);
90 if (!fgHasNode("/sim/startup/mouse-pointer")) {
91 // no preference specified for mouse pointer
92 } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
95 // force showing pointer
101 // Operation for querying OpenGL parameters. This must be done in a
102 // valid OpenGL context, potentially in another thread.
104 struct GeneralInitOperation : public GraphicsContextOperation
106 GeneralInitOperation()
107 : GraphicsContextOperation(std::string("General init"))
110 void run(osg::GraphicsContext* gc)
112 SGPropertyNode* simRendering = fgGetNode("/sim/rendering");
114 simRendering->setStringValue("gl-vendor", (char*) glGetString(GL_VENDOR));
115 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VENDOR));
117 simRendering->setStringValue("gl-renderer", (char*) glGetString(GL_RENDERER));
118 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_RENDERER));
120 simRendering->setStringValue("gl-version", (char*) glGetString(GL_VERSION));
121 SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VERSION));
123 // Old hardware without support for OpenGL 2.0 does not support GLSL and
124 // glGetString returns NULL for GL_SHADING_LANGUAGE_VERSION.
126 // See http://flightgear.org/forums/viewtopic.php?f=17&t=19670&start=15#p181945
127 const char* glsl_version = (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION);
129 glsl_version = "UNSUPPORTED";
130 simRendering->setStringValue("gl-shading-language-version", glsl_version);
131 SG_LOG( SG_GENERAL, SG_INFO, glsl_version);
134 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
135 simRendering->setIntValue("max-texture-size", tmp);
137 glGetIntegerv( GL_DEPTH_BITS, &tmp );
138 simRendering->setIntValue("depth-buffer-bits", tmp);
142 osg::ref_ptr<GUIInitOperation> initOp;
147 * Returns true when done, false when still busy (call again). */
150 static osg::ref_ptr<GeneralInitOperation> genOp;
154 // Pick some window on which to do queries.
155 // XXX Perhaps all this graphics initialization code should be
156 // moved to renderer.cxx?
157 genOp = new GeneralInitOperation;
158 osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
159 WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
160 osg::GraphicsContext* gc = 0;
162 gc = guiCamera->getGraphicsContext();
164 gc->add(genOp.get());
165 initOp = new GUIInitOperation;
166 gc->add(initOp.get());
168 wsa->windows[0]->gc->add(genOp.get());
170 return false; // not ready yet
174 if (!genOp->isFinished())
178 if (!initOp->isFinished())