|
KGLLib
|
00001 /* 00002 * Copyright (C) 2008 Rivo Laks <rivolaks@hot.ee> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef KGLLIB_GLWIDGET_H 00019 #define KGLLIB_GLWIDGET_H 00020 00021 00022 #include "kgllib.h" 00023 #include <QtOpenGL/QGLWidget> 00024 #include <QtCore/QList> 00025 00026 #include <Eigen/Core> 00027 00028 class QAction; 00029 00030 00031 namespace KGLLib 00032 { 00033 class Camera; 00034 class FPSCounter; 00035 class TextRenderer; 00036 00048 class KGLLIB_EXPORT GLWidget : public QGLWidget 00049 { 00050 Q_OBJECT 00051 public: 00052 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 00053 00054 explicit GLWidget(QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0); 00055 explicit GLWidget(QGLContext* context, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0); 00056 explicit GLWidget(const QGLFormat& format, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0); 00057 00058 virtual ~GLWidget(); 00059 00064 KGLLib::Camera* camera() const { return mCamera; } 00069 KGLLib::FPSCounter* fpsCounter() const { return mFpsCounter; } 00070 00074 KGLLib::TextRenderer* textRenderer() const; 00075 00079 bool glInitialized() const { return mGLInitialized; } 00080 00081 public Q_SLOTS: 00082 void toggleShowFps(); 00083 void toggleWireframeMode(); 00084 00085 protected: 00097 virtual void initializeGL(); 00101 virtual void initializeGL(Renderer* r); 00107 virtual void resizeGL(int width, int height); 00118 virtual void paintGL(); 00125 virtual void render(); 00126 00132 void setClearColor(const Eigen::Vector4f& c); 00137 void setAutomaticClear(bool clear); 00138 00139 Eigen::Vector4f clearColor() const { return mClearColor; } 00140 bool automaticClear() const { return mAutomaticClear; } 00141 00152 void setErrorText(const QString& text); 00157 QString errorText() const { return mErrorText; } 00158 00163 bool shortcutsEnabled() const { return mShortcutsEnabled; } 00174 virtual void setShortcutsEnabled( bool enabled); 00175 00176 private: 00177 void init(); 00178 00179 private: 00180 KGLLib::Camera* mCamera; 00181 KGLLib::FPSCounter* mFpsCounter; 00182 mutable KGLLib::TextRenderer* mTextRenderer; 00183 00184 bool mAutomaticClear; 00185 Eigen::Vector4f mClearColor; 00186 bool mGLInitialized; 00187 00188 bool mShowFps; 00189 bool mWireframeMode; 00190 QString mErrorText; 00191 // We use our own list of actions here because we want to be able to 00192 // enable/disable only those actions 00193 QList<QAction*> mShortcuts; 00194 bool mShortcutsEnabled; 00195 }; 00196 00197 } 00198 00199 #endif
1.7.4