]> git.mxchange.org Git - flightgear.git/blob - src/GUI/gui.cxx
Support for multiple data dirs.
[flightgear.git] / src / GUI / gui.cxx
1 /**************************************************************************
2  * gui.cxx
3  *
4  * Written 1998 by Durk Talsma, started Juni, 1998.  For the flight gear
5  * project.
6  *
7  * Additional mouse supported added by David Megginson, 1999.
8  *
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.
13  *
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.
18  *
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.
22  *
23  * $Id$
24  **************************************************************************/
25
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #include <simgear/compiler.h>
32
33 #include <string>
34
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>
39
40 #include <plib/pu.h>
41
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>
50
51 #include "gui.h"
52 #include "layout.hxx"
53
54 #include <osg/GraphicsContext>
55
56 using namespace flightgear;
57
58 puFont guiFnt = 0;
59
60
61 /* -------------------------------------------------------------------------
62 init the gui
63 _____________________________________________________________________*/
64
65 namespace
66 {
67 class GUIInitOperation : public GraphicsContextOperation
68 {
69 public:
70     GUIInitOperation() : GraphicsContextOperation(std::string("GUI init"))
71     {
72     }
73     void run(osg::GraphicsContext* gc)
74     {
75         WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
76         wsa->puInitialize();
77         puSetDefaultStyle         ( PUSTYLE_SMALL_SHADED ); //PUSTYLE_DEFAULT
78         puSetDefaultColourScheme  (0.8, 0.8, 0.9, 1);
79
80         FGFontCache *fc = globals->get_fontcache();
81         fc->initializeFonts();
82         puFont *GuiFont
83             = fc->get(globals->get_locale()->getDefaultFont("typewriter.txf"),
84                       15);
85         puSetDefaultFonts(*GuiFont, *GuiFont);
86         guiFnt = puGetDefaultLabelFont();
87
88         LayoutWidget::setDefaultFont(GuiFont, 15);
89   
90         if (!fgHasNode("/sim/startup/mouse-pointer")) {
91             // no preference specified for mouse pointer
92         } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
93             // don't show pointer
94         } else {
95             // force showing pointer
96             puShowCursor();
97         }
98     }
99 };
100
101 // Operation for querying OpenGL parameters. This must be done in a
102 // valid OpenGL context, potentially in another thread.
103
104 struct GeneralInitOperation : public GraphicsContextOperation
105 {
106     GeneralInitOperation()
107         : GraphicsContextOperation(std::string("General init"))
108     {
109     }
110     void run(osg::GraphicsContext* gc)
111     {
112         SGPropertyNode* simRendering = fgGetNode("/sim/rendering");
113
114         simRendering->setStringValue("gl-vendor", (char*) glGetString(GL_VENDOR));
115         SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VENDOR));
116
117         simRendering->setStringValue("gl-renderer", (char*) glGetString(GL_RENDERER));
118         SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_RENDERER));
119
120         simRendering->setStringValue("gl-version", (char*) glGetString(GL_VERSION));
121         SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VERSION));
122
123         // Old hardware without support for OpenGL 2.0 does not support GLSL and
124         // glGetString returns NULL for GL_SHADING_LANGUAGE_VERSION.
125         //
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);
128         if( !glsl_version )
129           glsl_version = "UNSUPPORTED";
130         simRendering->setStringValue("gl-shading-language-version", glsl_version);
131         SG_LOG( SG_GENERAL, SG_INFO, glsl_version);
132
133         GLint tmp;
134         glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
135         simRendering->setIntValue("max-texture-size", tmp);
136
137         glGetIntegerv( GL_DEPTH_BITS, &tmp );
138         simRendering->setIntValue("depth-buffer-bits", tmp);
139     }
140 };
141
142 osg::ref_ptr<GUIInitOperation> initOp;
143
144 }
145
146 /** Initializes GUI.
147  * Returns true when done, false when still busy (call again). */
148 bool guiInit()
149 {
150     static osg::ref_ptr<GeneralInitOperation> genOp;
151
152     if (!genOp.valid())
153     {
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;
161         if (guiCamera)
162             gc = guiCamera->getGraphicsContext();
163         if (gc) {
164             gc->add(genOp.get());
165             initOp = new GUIInitOperation;
166             gc->add(initOp.get());
167         } else {
168             wsa->windows[0]->gc->add(genOp.get());
169         }
170         return false; // not ready yet
171     }
172     else
173     {
174         if (!genOp->isFinished())
175             return false;
176         if (!initOp.valid())
177             return true;
178         if (!initOp->isFinished())
179             return false;
180         genOp = 0;
181         initOp = 0;
182         // we're done
183         return true;
184     }
185 }