source: git/src/gla.h @ bae6a7c

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

Generate opengl lists lazily to try to reduce start up times.

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

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