source: git/src/gla.h @ f3cfd13

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 f3cfd13 was d67450e, checked in by Olly Betts <olly@…>, 19 years ago

Add Point::Invalidate() and Point::IsValid?() rather than directly setting
the x coordinate to DBL_MAX and testing that.

Add the mechanics to the OpenGL layer to allow a "wireframe" view of the tunnel
walls (not yet hooked up to the UI).

Add the mechanics to allow smooth shading (but we need to set normals before
we can useful turn this on).

Pass/return Vector3 instead of x,y,z triples in many places.

Factor out GfxCore::DrawArrow?() from DrawCompass?()/DrawClino?().

Point class now uses Vector3 as a base class, so the vec() method is no longer
required.

Fix presentation playing to actually work (it wasn't storing the speed so it
never played...)

Inline GLACanvas::SetTranslation?() and AddTranslation?().

Vector3::set() renamed to Vector3::assign() for consistency with C++ STL.

Display altitude to 2 decimal places rather than the nearest metre/foot.

LabelInfo::GetText?() now returns const ref to wxString rather than wxString.

Factor apart WIN32 and non-WIN32 versions of AvenAllowOnTop? class as the
code is much clearer that way.

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

  • Property mode set to 100644
File size: 6.7 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 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 "quaternion.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    Quaternion m_Rotation;
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 DrawCross(glaCoord x, glaCoord y, glaCoord z);
194    void DrawRing(glaCoord x, glaCoord y);
195
196    void PlaceVertex(const Vector3 & v) {
197        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
198    }
199    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
200    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
201
202    void PlaceNormal(const Vector3 &v);
203
204    void EnableDashedLines();
205    void DisableDashedLines();
206
207    void EnableSmoothPolygons(bool filled);
208    void DisableSmoothPolygons();
209
210    void SetRotation(const Quaternion&);
211    void SetScale(Double);
212    void SetTranslation(const Vector3 &v) {
213        m_Translation = v;
214    }
215    void AddTranslation(const Vector3 &v) {
216        m_Translation += v;
217    }
218    const Vector3 & GetTranslation() const {
219        return m_Translation;
220    }
221    void AddTranslationScreenCoordinates(int dx, int dy);
222
223    bool Transform(const Vector3 & v, Double* x_out, Double* y_out, Double* z_out) const;
224    void ReverseTransform(Double x, Double y, Double* x_out, Double* y_out, Double* z_out) const;
225
226#ifdef USE_FNT
227    int GetFontSize() const { return m_Font.getFontSize(); }
228#else
229    int GetFontSize() const { return m_FontSize; }
230#endif
231
232    void ToggleSmoothShading();
233    bool GetSmoothShading() const { return m_SmoothShading; }
234
235    Double SurveyUnitsAcrossViewport() const;
236
237    void ToggleTextured();
238    bool GetTextured() const { return m_Textured; }
239
240    void TogglePerspective() { m_Perspective = !m_Perspective; }
241    bool GetPerspective() const { return m_Perspective; }
242
243    void ToggleFog() { m_Fog = !m_Fog; }
244    bool GetFog() const { return m_Fog; }
245
246    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
247    bool GetAntiAlias() const { return m_AntiAlias; }
248
249    bool SaveScreenshot(const wxString & fnm, int type) const;
250};
Note: See TracBrowser for help on using the repository browser.