diff options
author | don bright <hugh.m.bright@gmail.com> | 2013-02-24 01:58:06 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2013-02-24 01:58:06 (GMT) |
commit | 386df69c0f6a893d3f888ae0dd9150fae197514c (patch) | |
tree | 3f51d36d0949a18ec3bd4ff20fd2607afd114c9f | |
parent | f07c6b2cb633bcb22acd8b19315911b373934786 (diff) |
consolidate resizeGL()
-rw-r--r-- | src/GLView.cc | 13 | ||||
-rw-r--r-- | src/GLView.h | 15 | ||||
-rw-r--r-- | src/OffscreenView.cc | 41 | ||||
-rw-r--r-- | src/OffscreenView.h | 11 | ||||
-rw-r--r-- | src/QGLView.h | 10 | ||||
-rw-r--r-- | src/qglview.cc | 40 |
6 files changed, 29 insertions, 101 deletions
diff --git a/src/GLView.cc b/src/GLView.cc index cb1f9c1..c851497 100644 --- a/src/GLView.cc +++ b/src/GLView.cc @@ -15,6 +15,18 @@ void GLView::setRenderer(Renderer* r) this->renderer = r; } +void GLView::resizeGL(int w, int h) +{ +#ifdef ENABLE_OPENCSG + shaderinfo[9] = w; + shaderinfo[10] = h; +#endif + this->width = w; + this->height = h; + glViewport(0, 0, w, h); + w_h_ratio = sqrt((double)w / (double)h); +} + void GLView::setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance) { PRINT("set gimbal camera not implemented"); @@ -68,7 +80,6 @@ void GLView::setupOrtho(bool offset) /* void initializeGL(); // - void resizeGL(int w, int h); // void paintGL(); // diff --git a/src/GLView.h b/src/GLView.h index e98bfe0..aefcfcb 100644 --- a/src/GLView.h +++ b/src/GLView.h @@ -1,6 +1,9 @@ #ifndef GLVIEW_H_ #define GLVIEW_H_ +// A basic OpenGL viewing rectangle. +// Inherited by QGLview (for QT) and OffscreenView (non-QT) + #include <Eigen/Core> #include <Eigen/Geometry> #include <string> @@ -21,9 +24,10 @@ public: Renderer *renderer; /* void initializeGL(); // - void resizeGL(int w, int h); // */ + void resizeGL(int w, int h); + void setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance); void setupGimbalPerspective(); void setupGimbalOrtho(double distance, bool offset=false); @@ -35,6 +39,8 @@ public: virtual bool save(const char *filename) = 0; virtual std::string getRendererInfo() const = 0; + size_t width; + size_t height; double viewer_distance;// double w_h_ratio;// bool orthomode;// @@ -46,12 +52,11 @@ public: Eigen::Vector3d camera_eye; Eigen::Vector3d camera_center; +#ifdef ENABLE_OPENCSG + GLint shaderinfo[11]; +#endif /* void paintGL(); // - bool save(const char *filename); // - //bool save(std::ostream &output); // not implemented in qgl? - - GLint shaderinfo[11]; // */ }; diff --git a/src/OffscreenView.cc b/src/OffscreenView.cc index 837252f..80fa35d 100644 --- a/src/OffscreenView.cc +++ b/src/OffscreenView.cc @@ -17,12 +17,14 @@ OffscreenView::OffscreenView(size_t width, size_t height) camera_eye << 0, 0, 0; camera_center << 0, 0, 0; +#ifdef ENABLE_OPENCSG for (int i = 0; i < 10; i++) this->shaderinfo[i] = 0; +#endif this->ctx = create_offscreen_context(width, height); if ( this->ctx == NULL ) throw -1; initializeGL(); - resizeGL(width, height); + GLView::resizeGL(width, height); } OffscreenView::~OffscreenView() @@ -57,43 +59,6 @@ void OffscreenView::initializeGL() } -void OffscreenView::resizeGL(int w, int h) -{ - this->width = w; - this->height = h; - glViewport(0, 0, w, h); - w_h_ratio = sqrt((double)w / (double)h); -} - -/*void OffscreenView::setupGimbalPerspective() -{ - fprintf(stderr, "gimbal camera not implemented in Offscreen View\n"); -} - -void OffscreenView::setupGimbalOrtho(double distance, bool offset) -{ - fprintf(stderr, "gimbal camera not implemented in Offscreen View\n"); -} - -void OffscreenView::setupPerspective() -{ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - double dist = (this->camera_center - this->camera_eye).norm(); - gluPerspective(45, w_h_ratio, 0.1*dist, 100*dist); -} - -void OffscreenView::setupOrtho(bool offset) -{ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - if (offset) glTranslated(-0.8, -0.8, 0); - double l = (this->camera_center - this->camera_eye).norm() / 10; - glOrtho(-w_h_ratio*l, +w_h_ratio*l, - -(1/w_h_ratio)*l, +(1/w_h_ratio)*l, - -FAR_FAR_AWAY, +FAR_FAR_AWAY); -}*/ - void OffscreenView::paintGL() { glEnable(GL_LIGHTING); diff --git a/src/OffscreenView.h b/src/OffscreenView.h index 5842ba2..091470c 100644 --- a/src/OffscreenView.h +++ b/src/OffscreenView.h @@ -19,18 +19,13 @@ public: ~OffscreenView(); // not void initializeGL(); // - void resizeGL(int w, int h); // - void paintGL(); // - bool save(const char *filename); // - bool save(std::ostream &output); // not implemented in qgl? - std::string getRendererInfo() const; - GLint shaderinfo[11]; // + bool save(const char *filename); + bool save(std::ostream &output); + std::string getRendererInfo() const; OffscreenContext *ctx; // not - size_t width; // not - size_t height; // not }; #endif diff --git a/src/QGLView.h b/src/QGLView.h index e53a411..de53779 100644 --- a/src/QGLView.h +++ b/src/QGLView.h @@ -41,7 +41,6 @@ public: public: QLabel *statusLabel; - GLint shaderinfo[11]; #ifdef ENABLE_OPENCSG bool opencsg_support; @@ -67,15 +66,6 @@ private: void initializeGL(); void resizeGL(int w, int h); -/* void setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance); - void setupGimbalPerspective(); - void setupGimbalOrtho(double distance,bool offset=false); - - void setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d ¢er); - void setupPerspective(); - void setupOrtho(bool offset=false); -*/ - void paintGL(); void normalizeAngle(GLdouble& angle); diff --git a/src/qglview.cc b/src/qglview.cc index f303965..d689a96 100644 --- a/src/qglview.cc +++ b/src/qglview.cc @@ -324,48 +324,10 @@ void QGLView::display_opencsg_warning() void QGLView::resizeGL(int w, int h) { -#ifdef ENABLE_OPENCSG - shaderinfo[9] = w; - shaderinfo[10] = h; -#endif - glViewport(0, 0, w, h); - w_h_ratio = sqrt((double)w / (double)h); - + GLView::resizeGL(w,h); GLView::setupGimbalPerspective(); } -/*void QGLView::setupPerspective() -{ - fprintf(stderr,"non-gimbal camera not implemented for qglview\n"); -} - -void QGLView::setupOrtho(bool offset) -{ - fprintf(stderr,"non-gimbal camera not implemented for qglview\n"); -} - -void QGLView::setupGimbalPerspective() -{ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-w_h_ratio, +w_h_ratio, -(1/w_h_ratio), +(1/w_h_ratio), +10.0, +FAR_FAR_AWAY); - gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); -} - -void QGLView::setupGimbalOrtho(double distance, bool offset) -{ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - if(offset) - glTranslated(-0.8, -0.8, 0); - double l = distance/10; - glOrtho(-w_h_ratio*l, +w_h_ratio*l, - -(1/w_h_ratio)*l, +(1/w_h_ratio)*l, - -FAR_FAR_AWAY, +FAR_FAR_AWAY); - gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); -} -*/ - void QGLView::paintGL() { glEnable(GL_LIGHTING); |