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
Line 
1//
2//  gla.h
3//
4//  Header file for the GLA abstraction layer.
5//
6//  Copyright (C) 2002 Mark R. Shinwell.
7//  Copyright (C) 2003,2004,2005,2006,2007 Olly Betts
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
24// Use texture mapped fonts (lots faster, at least with hardware 3d)
25#define USE_FNT
26
27#include <vector>
28
29using namespace std;
30
31#include "wx.h"
32#include "aventypes.h"
33#include "vector3.h"
34
35#ifdef USE_FNT
36#include "fnt.h"
37#endif
38
39class GfxCore;
40
41wxString GetGLSystemDescription();
42
43// #define GLA_DEBUG
44
45typedef Double glaCoord;
46
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,
61    col_BLUE,
62    col_LAST // must be the last entry here
63};
64
65class GLAPen {
66    friend class GLACanvas; // allow direct access to components
67
68    double components[3]; // red, green, blue
69
70public:
71    GLAPen();
72    ~GLAPen();
73
74    void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0
75    void Interpolate(const GLAPen&, double how_far);
76
77    double GetRed() const;
78    double GetGreen() const;
79    double GetBlue() const;
80};
81
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
98class GLACanvas : public wxGLCanvas {
99#ifdef GLA_DEBUG
100    int m_Vertices;
101#endif
102
103    GLdouble modelview_matrix[16];
104    GLdouble projection_matrix[16];
105    GLint viewport[4];
106
107    // Viewing volume diameter:
108    glaCoord m_VolumeDiameter;
109
110    // Parameters for plotting data:
111    Double m_Pan, m_Tilt;
112    Double m_Scale;
113    Vector3 m_Translation;
114
115#ifdef USE_FNT
116    fntTexFont m_Font;
117#else
118    static void * const m_Font;
119    static const int m_FontSize;
120#endif
121
122    GLUquadric* m_Quadric;
123
124    GLuint m_Texture;
125    GLuint m_CrossTexture;
126
127    bool m_SmoothShading;
128    bool m_Textured;
129    bool m_Perspective;
130    bool m_Fog;
131    bool m_AntiAlias;
132    bool glpoint_ok;
133    bool glpoint_sprite;
134
135    vector<GLAList> drawing_lists;
136    mutable unsigned int list_flags;
137
138public:
139    GLACanvas(wxWindow* parent, int id);
140    ~GLACanvas();
141
142    void FirstShow();
143
144    void Clear();
145    void StartDrawing();
146    void FinishDrawing();
147
148    void SetVolumeDiameter(glaCoord diameter);
149    void SetDataTransform();
150    void SetIndicatorTransform();
151
152    void DrawList(unsigned int l);
153    void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
154    void InvalidateList(unsigned int l);
155    virtual void GenerateList(unsigned int l) = 0;
156
157    void SetBackgroundColour(float red, float green, float blue);
158    void SetColour(const GLAPen& pen, double rgb_scale);
159    void SetColour(const GLAPen& pen);
160    void SetColour(gla_colour colour);
161
162    void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
163    void DrawIndicatorText(int x, int y, const wxString& str);
164    void GetTextExtent(const wxString& str, int * x_ext, int * y_ext);
165
166    void BeginQuadrilaterals();
167    void EndQuadrilaterals();
168    void BeginLines();
169    void EndLines();
170    void BeginTriangleStrip();
171    void EndTriangleStrip();
172    void BeginTriangles();
173    void EndTriangles();
174    void BeginPolyline();
175    void EndPolyline();
176    void BeginPolygon();
177    void EndPolygon();
178    void BeginBlobs();
179    void EndBlobs();
180    void BeginCrosses();
181    void EndCrosses();
182
183    void DrawRectangle(gla_colour edge, gla_colour fill,
184                       glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
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);
189    void DrawTriangle(gla_colour edge, gla_colour fill,
190                      const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
191
192    void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
193    void DrawBlob(glaCoord x, glaCoord y);
194    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
195    void DrawRing(glaCoord x, glaCoord y);
196
197    void PlaceVertex(const Vector3 & v) {
198        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
199    }
200    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
201    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
202
203    void PlaceNormal(const Vector3 &v);
204
205    void EnableDashedLines();
206    void DisableDashedLines();
207
208    void EnableSmoothPolygons(bool filled);
209    void DisableSmoothPolygons();
210
211    void SetRotation(double pan, double tilt) {
212        m_Pan = pan;
213        m_Tilt = tilt;
214    }
215    void SetScale(Double);
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    }
225    void AddTranslationScreenCoordinates(int dx, int dy);
226
227    bool Transform(const Vector3 & v, Double* x_out, Double* y_out, Double* z_out) const;
228    void ReverseTransform(Double x, Double y, Double* x_out, Double* y_out, Double* z_out) const;
229
230#ifdef USE_FNT
231    int GetFontSize() const { return m_Font.getFontSize(); }
232#else
233    int GetFontSize() const { return m_FontSize; }
234#endif
235
236    void ToggleSmoothShading();
237    bool GetSmoothShading() const { return m_SmoothShading; }
238
239    Double SurveyUnitsAcrossViewport() const;
240
241    void ToggleTextured();
242    bool GetTextured() const { return m_Textured; }
243
244    void TogglePerspective() { m_Perspective = !m_Perspective; }
245    bool GetPerspective() const { return m_Perspective; }
246
247    void ToggleFog() { m_Fog = !m_Fog; }
248    bool GetFog() const { return m_Fog; }
249
250    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
251    bool GetAntiAlias() const { return m_AntiAlias; }
252
253    bool SaveScreenshot(const wxString & fnm, int type) const;
254};
Note: See TracBrowser for help on using the repository browser.