source: git/src/gla.h @ 5b7164d

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 5b7164d was 76dd228, checked in by Olly Betts <olly@…>, 20 years ago

Added mechanism for drawing "2D lists", for use with indicators.

Fix depth bar to appear back in top right when window resizes (broken
in 1.1.5).

Fix compass and clino outer edges to "light up" when dragging with mouse
pointer outside (like they do in 1.0).

Reworked indicator drawing code in preparation for using lists more.

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