source: git/src/gla.h @ ac7e4da

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereostereo-2025walls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since ac7e4da was 08253d9, checked in by Olly Betts <olly@…>, 18 years ago

Just set the pan and tilt directly as OpenGL rotations rather than messing
around setting up and then decoding a quaternion. This fixes some glitches
when tilting while looking east, and eliminates 2 source files and 2 headers!

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@3337 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 6.8 KB
RevLine 
[56da40e]1//
2//  gla.h
3//
4//  Header file for the GLA abstraction layer.
5//
6//  Copyright (C) 2002 Mark R. Shinwell.
[08253d9]7//  Copyright (C) 2003,2004,2005,2006,2007 Olly Betts
[56da40e]8//
9//  This program is free software; you can redistribute it and/or modify
10//  it under the terms of the GNU General Public License as published by
11//  the Free Software Foundation; either version 2 of the License, or
12//  (at your option) any later version.
13//
14//  This program is distributed in the hope that it will be useful,
15//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17//  GNU 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22//
23
[1eeb55a]24// Use texture mapped fonts (lots faster, at least with hardware 3d)
25#define USE_FNT
26
[bae6a7c]27#include <vector>
28
29using namespace std;
30
[56da40e]31#include "wx.h"
32#include "aventypes.h"
[08253d9]33#include "vector3.h"
[56da40e]34
[1eeb55a]35#ifdef USE_FNT
36#include "fnt.h"
37#endif
38
[56da40e]39class GfxCore;
40
[cc1a1d9]41wxString GetGLSystemDescription();
42
[d67450e]43// #define GLA_DEBUG
[1897247]44
[56da40e]45typedef Double glaCoord;
46
[aa048c3]47// Colours for drawing.  Don't reorder these!
48enum gla_colour {
49    col_BLACK = 0,
50    col_GREY,
51    col_LIGHT_GREY,
52    col_LIGHT_GREY_2,
53    col_DARK_GREY,
54    col_WHITE,
55    col_TURQUOISE,
56    col_GREEN,
57    col_INDICATOR_1,
58    col_INDICATOR_2,
59    col_YELLOW,
60    col_RED,
[f4c5932]61    col_BLUE,
[aa048c3]62    col_LAST // must be the last entry here
63};
64
[56da40e]65class GLAPen {
[aa048c3]66    friend class GLACanvas; // allow direct access to components
67
68    double components[3]; // red, green, blue
[9cf3688]69
[56da40e]70public:
71    GLAPen();
72    ~GLAPen();
73
74    void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0
[f383708]75    void Interpolate(const GLAPen&, double how_far);
[56da40e]76
[f7ea0e1]77    double GetRed() const;
78    double GetGreen() const;
79    double GetBlue() const;
[56da40e]80};
81
[db59b02]82const unsigned int INVALIDATE_ON_SCALE = 1;
83const unsigned int NEVER_CACHE = 2;
84
85class GLAList {
86    GLuint gl_list;
87    unsigned int flags;
88  public:
89    GLAList() : gl_list(0), flags(0) { }
90    GLAList(GLuint gl_list_, unsigned int flags_)
91        : gl_list(gl_list_), flags(flags_) { }
92    bool test_flag(unsigned int mask) const { return flags & mask; }
93    operator bool() { return gl_list != 0; }
94    void DrawList() const;
95    void InvalidateList();
96};
97
[56da40e]98class GLACanvas : public wxGLCanvas {
[203d2a7]99#ifdef GLA_DEBUG
100    int m_Vertices;
101#endif
102
[dde4fe7]103    GLdouble modelview_matrix[16];
104    GLdouble projection_matrix[16];
105    GLint viewport[4];
106
[c5fc8eb]107    // Viewing volume diameter:
108    glaCoord m_VolumeDiameter;
[56da40e]109
110    // Parameters for plotting data:
[08253d9]111    Double m_Pan, m_Tilt;
[56da40e]112    Double m_Scale;
[d67450e]113    Vector3 m_Translation;
[56da40e]114
[1eeb55a]115#ifdef USE_FNT
116    fntTexFont m_Font;
117#else
[a2036bb]118    static void * const m_Font;
[203d2a7]119    static const int m_FontSize;
[1eeb55a]120#endif
[d9b3270]121
[1b12b82]122    GLUquadric* m_Quadric;
[a517825]123
124    GLuint m_Texture;
[95ce35f]125    GLuint m_CrossTexture;
[a517825]126
[d67450e]127    bool m_SmoothShading;
[a517825]128    bool m_Textured;
[1eeb55a]129    bool m_Perspective;
[c60062d]130    bool m_Fog;
[db452ae]131    bool m_AntiAlias;
[4ba80e0]132    bool glpoint_ok;
[95ce35f]133    bool glpoint_sprite;
[1eeb55a]134
[db59b02]135    vector<GLAList> drawing_lists;
136    mutable unsigned int list_flags;
[bae6a7c]137
[56da40e]138public:
[84f1ed1]139    GLACanvas(wxWindow* parent, int id);
[56da40e]140    ~GLACanvas();
[2c8b64f]141
[1b12b82]142    void FirstShow();
143
[56da40e]144    void Clear();
145    void StartDrawing();
146    void FinishDrawing();
147
[c5fc8eb]148    void SetVolumeDiameter(glaCoord diameter);
[56da40e]149    void SetDataTransform();
150    void SetIndicatorTransform();
[9cf3688]151
[d2fcc9b]152    void DrawList(unsigned int l);
[76dd228]153    void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
[d2fcc9b]154    void InvalidateList(unsigned int l);
155    virtual void GenerateList(unsigned int l) = 0;
[9cf3688]156
[56da40e]157    void SetBackgroundColour(float red, float green, float blue);
[aa048c3]158    void SetColour(const GLAPen& pen, double rgb_scale);
159    void SetColour(const GLAPen& pen);
160    void SetColour(gla_colour colour);
161
[56da40e]162    void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
[1eeb55a]163    void DrawIndicatorText(int x, int y, const wxString& str);
164    void GetTextExtent(const wxString& str, int * x_ext, int * y_ext);
[9cf3688]165
[56da40e]166    void BeginQuadrilaterals();
167    void EndQuadrilaterals();
168    void BeginLines();
169    void EndLines();
[dde4fe7]170    void BeginTriangleStrip();
171    void EndTriangleStrip();
[56da40e]172    void BeginTriangles();
173    void EndTriangles();
174    void BeginPolyline();
175    void EndPolyline();
[45aa1d6]176    void BeginPolygon();
177    void EndPolygon();
[e633bb1]178    void BeginBlobs();
179    void EndBlobs();
[86fe6e4]180    void BeginCrosses();
181    void EndCrosses();
[9cf3688]182
[aa048c3]183    void DrawRectangle(gla_colour edge, gla_colour fill,
[d67450e]184                       glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
[aa048c3]185    void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
186                             glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
187    void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius);
188    void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start);
[d67450e]189    void DrawTriangle(gla_colour edge, gla_colour fill,
190                      const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
[9cf3688]191
[e633bb1]192    void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
[81aea4e]193    void DrawBlob(glaCoord x, glaCoord y);
[86fe6e4]194    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
[e633bb1]195    void DrawRing(glaCoord x, glaCoord y);
[9cf3688]196
[d67450e]197    void PlaceVertex(const Vector3 & v) {
198        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
199    }
[56da40e]200    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
201    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
[203d2a7]202
[d67450e]203    void PlaceNormal(const Vector3 &v);
[9cf3688]204
[56da40e]205    void EnableDashedLines();
206    void DisableDashedLines();
207
[d67450e]208    void EnableSmoothPolygons(bool filled);
[1b12b82]209    void DisableSmoothPolygons();
210
[08253d9]211    void SetRotation(double pan, double tilt) {
212        m_Pan = pan;
213        m_Tilt = tilt;
214    }
[56da40e]215    void SetScale(Double);
[d67450e]216    void SetTranslation(const Vector3 &v) {
217        m_Translation = v;
218    }
219    void AddTranslation(const Vector3 &v) {
220        m_Translation += v;
221    }
222    const Vector3 & GetTranslation() const {
223        return m_Translation;
224    }
[56da40e]225    void AddTranslationScreenCoordinates(int dx, int dy);
226
[d67450e]227    bool Transform(const Vector3 & v, Double* x_out, Double* y_out, Double* z_out) const;
[3c3ca1d]228    void ReverseTransform(Double x, Double y, Double* x_out, Double* y_out, Double* z_out) const;
[56da40e]229
[c09e6c8]230#ifdef USE_FNT
[1eeb55a]231    int GetFontSize() const { return m_Font.getFontSize(); }
[c09e6c8]232#else
233    int GetFontSize() const { return m_FontSize; }
234#endif
[087bc72]235
[d67450e]236    void ToggleSmoothShading();
237    bool GetSmoothShading() const { return m_SmoothShading; }
238
[e7f9e99]239    Double SurveyUnitsAcrossViewport() const;
[6abab84]240
[a517825]241    void ToggleTextured();
242    bool GetTextured() const { return m_Textured; }
243
[6abab84]244    void TogglePerspective() { m_Perspective = !m_Perspective; }
245    bool GetPerspective() const { return m_Perspective; }
[045e2af]246
[c60062d]247    void ToggleFog() { m_Fog = !m_Fog; }
248    bool GetFog() const { return m_Fog; }
249
[db452ae]250    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
251    bool GetAntiAlias() const { return m_AntiAlias; }
252
[045e2af]253    bool SaveScreenshot(const wxString & fnm, int type) const;
[56da40e]254};
Note: See TracBrowser for help on using the repository browser.