source: git/src/gla.h @ 0e08ec1

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 0e08ec1 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
RevLine 
[56da40e]1//
2//  gla.h
3//
4//  Header file for the GLA abstraction layer.
5//
6//  Copyright (C) 2002 Mark R. Shinwell.
[d67450e]7//  Copyright (C) 2003,2004,2005,2006 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"
33#include "quaternion.h"
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:
111    Quaternion m_Rotation;
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);
[86fe6e4]193    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
[e633bb1]194    void DrawRing(glaCoord x, glaCoord y);
[9cf3688]195
[d67450e]196    void PlaceVertex(const Vector3 & v) {
197        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
198    }
[56da40e]199    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
200    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
[203d2a7]201
[d67450e]202    void PlaceNormal(const Vector3 &v);
[9cf3688]203
[56da40e]204    void EnableDashedLines();
205    void DisableDashedLines();
206
[d67450e]207    void EnableSmoothPolygons(bool filled);
[1b12b82]208    void DisableSmoothPolygons();
209
[69ea543]210    void SetRotation(const Quaternion&);
[56da40e]211    void SetScale(Double);
[d67450e]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    }
[56da40e]221    void AddTranslationScreenCoordinates(int dx, int dy);
222
[d67450e]223    bool Transform(const Vector3 & v, Double* x_out, Double* y_out, Double* z_out) const;
[3c3ca1d]224    void ReverseTransform(Double x, Double y, Double* x_out, Double* y_out, Double* z_out) const;
[56da40e]225
[c09e6c8]226#ifdef USE_FNT
[1eeb55a]227    int GetFontSize() const { return m_Font.getFontSize(); }
[c09e6c8]228#else
229    int GetFontSize() const { return m_FontSize; }
230#endif
[087bc72]231
[d67450e]232    void ToggleSmoothShading();
233    bool GetSmoothShading() const { return m_SmoothShading; }
234
[e7f9e99]235    Double SurveyUnitsAcrossViewport() const;
[6abab84]236
[a517825]237    void ToggleTextured();
238    bool GetTextured() const { return m_Textured; }
239
[6abab84]240    void TogglePerspective() { m_Perspective = !m_Perspective; }
241    bool GetPerspective() const { return m_Perspective; }
[045e2af]242
[c60062d]243    void ToggleFog() { m_Fog = !m_Fog; }
244    bool GetFog() const { return m_Fog; }
245
[db452ae]246    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
247    bool GetAntiAlias() const { return m_AntiAlias; }
248
[045e2af]249    bool SaveScreenshot(const wxString & fnm, int type) const;
[56da40e]250};
Note: See TracBrowser for help on using the repository browser.