source: git/src/gla.h @ 5627cbb

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since 5627cbb was 5627cbb, checked in by Olly Betts <olly@…>, 14 years ago
  • Fix to build with a "unicode" build of wx.
  • Add "Copy" button to the About dialog to copy the system info to the clipboard.
  • List OpenGL extensions last, since there are usually lots of them with a modern gfx card.
  • When processing survey data, auto-scroll the log window until we've reported a warning or error.
  • Put the survey data log window in a splitter in the standard frame rather than having a separate frame for it.

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@3356 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 <string>
28#include <vector>
29
30using namespace std;
31
32#include "wx.h"
33#include "aventypes.h"
34#include "vector3.h"
35
36#ifdef USE_FNT
37#include "fnt.h"
38#endif
39
40class GfxCore;
41
42string GetGLSystemDescription();
43
44// #define GLA_DEBUG
45
46typedef Double glaCoord;
47
48// Colours for drawing.  Don't reorder these!
49enum gla_colour {
50    col_BLACK = 0,
51    col_GREY,
52    col_LIGHT_GREY,
53    col_LIGHT_GREY_2,
54    col_DARK_GREY,
55    col_WHITE,
56    col_TURQUOISE,
57    col_GREEN,
58    col_INDICATOR_1,
59    col_INDICATOR_2,
60    col_YELLOW,
61    col_RED,
62    col_BLUE,
63    col_LAST // must be the last entry here
64};
65
66class GLAPen {
67    friend class GLACanvas; // allow direct access to components
68
69    double components[3]; // red, green, blue
70
71public:
72    GLAPen();
73    ~GLAPen();
74
75    void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0
76    void Interpolate(const GLAPen&, double how_far);
77
78    double GetRed() const;
79    double GetGreen() const;
80    double GetBlue() const;
81};
82
83const unsigned int INVALIDATE_ON_SCALE = 1;
84const unsigned int NEVER_CACHE = 2;
85
86class GLAList {
87    GLuint gl_list;
88    unsigned int flags;
89  public:
90    GLAList() : gl_list(0), flags(0) { }
91    GLAList(GLuint gl_list_, unsigned int flags_)
92        : gl_list(gl_list_), flags(flags_) { }
93    bool test_flag(unsigned int mask) const { return flags & mask; }
94    operator bool() { return gl_list != 0; }
95    void DrawList() const;
96    void InvalidateList();
97};
98
99class GLACanvas : public wxGLCanvas {
100#ifdef GLA_DEBUG
101    int m_Vertices;
102#endif
103
104    GLdouble modelview_matrix[16];
105    GLdouble projection_matrix[16];
106    GLint viewport[4];
107
108    // Viewing volume diameter:
109    glaCoord m_VolumeDiameter;
110
111    // Parameters for plotting data:
112    Double m_Pan, m_Tilt;
113    Double m_Scale;
114    Vector3 m_Translation;
115
116#ifdef USE_FNT
117    fntTexFont m_Font;
118#else
119    static void * const m_Font;
120    static const int m_FontSize;
121#endif
122
123    GLUquadric* m_Quadric;
124
125    GLuint m_Texture;
126    GLuint m_CrossTexture;
127
128    bool m_SmoothShading;
129    bool m_Textured;
130    bool m_Perspective;
131    bool m_Fog;
132    bool m_AntiAlias;
133    bool glpoint_ok;
134    bool glpoint_sprite;
135
136    vector<GLAList> drawing_lists;
137    mutable unsigned int list_flags;
138
139public:
140    GLACanvas(wxWindow* parent, int id);
141    ~GLACanvas();
142
143    void FirstShow();
144
145    void Clear();
146    void StartDrawing();
147    void FinishDrawing();
148
149    void SetVolumeDiameter(glaCoord diameter);
150    void SetDataTransform();
151    void SetIndicatorTransform();
152
153    void DrawList(unsigned int l);
154    void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation);
155    void InvalidateList(unsigned int l);
156    virtual void GenerateList(unsigned int l) = 0;
157
158    void SetBackgroundColour(float red, float green, float blue);
159    void SetColour(const GLAPen& pen, double rgb_scale);
160    void SetColour(const GLAPen& pen);
161    void SetColour(gla_colour colour);
162
163    void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str);
164    void DrawIndicatorText(int x, int y, const wxString& str);
165    void GetTextExtent(const wxString& str, int * x_ext, int * y_ext);
166
167    void BeginQuadrilaterals();
168    void EndQuadrilaterals();
169    void BeginLines();
170    void EndLines();
171    void BeginTriangleStrip();
172    void EndTriangleStrip();
173    void BeginTriangles();
174    void EndTriangles();
175    void BeginPolyline();
176    void EndPolyline();
177    void BeginPolygon();
178    void EndPolygon();
179    void BeginBlobs();
180    void EndBlobs();
181    void BeginCrosses();
182    void EndCrosses();
183
184    void DrawRectangle(gla_colour edge, gla_colour fill,
185                       glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
186    void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top,
187                             glaCoord x0, glaCoord y0, glaCoord w, glaCoord h);
188    void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius);
189    void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start);
190    void DrawTriangle(gla_colour edge, gla_colour fill,
191                      const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
192
193    void DrawBlob(glaCoord x, glaCoord y, glaCoord z);
194    void DrawBlob(glaCoord x, glaCoord y);
195    void DrawCross(glaCoord x, glaCoord y, glaCoord z);
196    void DrawRing(glaCoord x, glaCoord y);
197
198    void PlaceVertex(const Vector3 & v) {
199        PlaceVertex(v.GetX(), v.GetY(), v.GetZ());
200    }
201    void PlaceVertex(glaCoord x, glaCoord y, glaCoord z);
202    void PlaceIndicatorVertex(glaCoord x, glaCoord y);
203
204    void PlaceNormal(const Vector3 &v);
205
206    void EnableDashedLines();
207    void DisableDashedLines();
208
209    void EnableSmoothPolygons(bool filled);
210    void DisableSmoothPolygons();
211
212    void SetRotation(double pan, double tilt) {
213        m_Pan = pan;
214        m_Tilt = tilt;
215    }
216    void SetScale(Double);
217    void SetTranslation(const Vector3 &v) {
218        m_Translation = v;
219    }
220    void AddTranslation(const Vector3 &v) {
221        m_Translation += v;
222    }
223    const Vector3 & GetTranslation() const {
224        return m_Translation;
225    }
226    void AddTranslationScreenCoordinates(int dx, int dy);
227
228    bool Transform(const Vector3 & v, Double* x_out, Double* y_out, Double* z_out) const;
229    void ReverseTransform(Double x, Double y, Double* x_out, Double* y_out, Double* z_out) const;
230
231#ifdef USE_FNT
232    int GetFontSize() const { return m_Font.getFontSize(); }
233#else
234    int GetFontSize() const { return m_FontSize; }
235#endif
236
237    void ToggleSmoothShading();
238    bool GetSmoothShading() const { return m_SmoothShading; }
239
240    Double SurveyUnitsAcrossViewport() const;
241
242    void ToggleTextured();
243    bool GetTextured() const { return m_Textured; }
244
245    void TogglePerspective() { m_Perspective = !m_Perspective; }
246    bool GetPerspective() const { return m_Perspective; }
247
248    void ToggleFog() { m_Fog = !m_Fog; }
249    bool GetFog() const { return m_Fog; }
250
251    void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; }
252    bool GetAntiAlias() const { return m_AntiAlias; }
253
254    bool SaveScreenshot(const wxString & fnm, int type) const;
255};
Note: See TracBrowser for help on using the repository browser.