00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourgeforge.net/ 00006 00007 Copyright © 2000-2003 Steven J. Streeting 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/gpl.html. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 00026 #include "OgreGTKGLSupport.h" 00027 #include "OgreLogManager.h" 00028 #include "OgreException.h" 00029 #include "OgreStringConverter.h" 00030 00031 #include "GTKWindow.h" 00032 00033 using namespace Ogre; 00034 00035 GTKGLSupport::GTKGLSupport() : 00036 _kit(0, NULL), _context_ref(0) 00037 { 00038 Gtk::GL::init(0, NULL); 00039 } 00040 00041 void GTKGLSupport::addConfig() 00042 { 00043 ConfigOption optFullScreen; 00044 ConfigOption optVideoMode; 00045 00046 // FS setting possiblities 00047 optFullScreen.name = "Full Screen"; 00048 optFullScreen.possibleValues.push_back("Yes"); 00049 optFullScreen.possibleValues.push_back("No"); 00050 optFullScreen.currentValue = "Yes"; 00051 optFullScreen.immutable = false; 00052 00053 // Video mode possiblities 00054 // XXX Actually do this 00055 optVideoMode.name = "Video Mode"; 00056 optVideoMode.immutable = false; 00057 optVideoMode.possibleValues.push_back("800 x 600"); 00058 optVideoMode.currentValue = "800 x 600"; 00059 00060 mOptions[optFullScreen.name] = optFullScreen; 00061 mOptions[optVideoMode.name] = optVideoMode; 00062 } 00063 00064 String GTKGLSupport::validateConfig() 00065 { 00066 return String(""); 00067 } 00068 00069 RenderWindow* GTKGLSupport::createWindow(bool autoCreateWindow, 00070 GLRenderSystem* renderSystem) 00071 { 00072 if (autoCreateWindow) 00073 { 00074 ConfigOptionMap::iterator opt = mOptions.find("Full Screen"); 00075 if (opt == mOptions.end()) 00076 Except(999, "Can't find full screen options!", "SDLGLSupport::createWindow"); 00077 bool fullscreen = (opt->second.currentValue == "Yes"); 00078 00079 opt = mOptions.find("Video Mode"); 00080 if (opt == mOptions.end()) 00081 Except(999, "Can't find video mode options!", "SDLGLSupport::createWindow"); 00082 String val = opt->second.currentValue; 00083 String::size_type pos = val.find('x'); 00084 if (pos == String::npos) 00085 Except(999, "Invalid Video Mode provided", "SDLGLSupport::createWindow"); 00086 00087 unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos)); 00088 unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1)); 00089 00090 return renderSystem->createRenderWindow("OGRE Render Window", w, h, 32, 00091 fullscreen); 00092 } 00093 else 00094 { 00095 // XXX What is the else? 00096 return NULL; 00097 } 00098 } 00099 00100 RenderWindow* GTKGLSupport::newWindow(const String& name, unsigned int width, 00101 unsigned int height, unsigned int colourDepth, bool fullScreen, int left, int top, 00102 bool depthBuffer, RenderWindow* parentWindowHandle, bool vsync) 00103 { 00104 GTKWindow* window = new GTKWindow(); 00105 window->create(name, width, height, colourDepth, fullScreen, left, top, 00106 depthBuffer, parentWindowHandle); 00107 00108 _ogre_widget = window->get_ogre_widget(); 00109 return window; 00110 } 00111 00112 void GTKGLSupport::start() 00113 { 00114 LogManager::getSingleton().logMessage( 00115 "******************************\n" 00116 "*** Starting GTK Subsystem ***\n" 00117 "******************************"); 00118 } 00119 00120 void GTKGLSupport::stop() 00121 { 00122 LogManager::getSingleton().logMessage( 00123 "******************************\n" 00124 "*** Stopping GTK Subsystem ***\n" 00125 "******************************"); 00126 } 00127 00128 void GTKGLSupport::begin_context() 00129 { 00130 ++_context_ref; 00131 if (_context_ref == 1) 00132 _ogre_widget->get_gl_window()->gl_begin(_ogre_widget->get_gl_context()); 00133 } 00134 00135 void GTKGLSupport::end_context() 00136 { 00137 --_context_ref; 00138 if(_context_ref < 0) 00139 Except(999, "Too many contexts destroyed!", "GTKGLSupport::end_context"); 00140 if (_context_ref == 0) 00141 { 00142 _ogre_widget->get_gl_window()->gl_end(); 00143 } 00144 } 00145 00146 void GTKGLSupport::initialiseExtensions(void) 00147 { 00148 // XXX anythign to actually do here? 00149 } 00150 00151 bool GTKGLSupport::checkMinGLVersion(const String& v) const 00152 { 00153 int major, minor; 00154 Gdk::GL::query_version(major, minor); 00155 00156 std::string::size_type pos = v.find("."); 00157 int cmaj = atoi(v.substr(0, pos).c_str()); 00158 int cmin = atoi(v.substr(pos + 1).c_str()); 00159 00160 return ( (major >= cmaj) && (minor >= cmin) ); 00161 } 00162 00163 bool GTKGLSupport::checkExtension(const String& ext) const 00164 { 00165 return Gdk::GL::query_gl_extension(ext.c_str()); 00166 } 00167 00168 void* GTKGLSupport::getProcAddress(const String& procname) 00169 { 00170 return Gdk::GL::get_proc_address(procname.c_str()); 00171 } 00172
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:12 2004