[56da40e] | 1 | // |
---|
| 2 | // gla.h |
---|
| 3 | // |
---|
| 4 | // Header file for the GLA abstraction layer. |
---|
| 5 | // |
---|
| 6 | // Copyright (C) 2002 Mark R. Shinwell. |
---|
[08253d9] | 7 | // Copyright (C) 2003,2004,2005,2006,2007 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 | |
---|
[5627cbb] | 27 | #include <string> |
---|
[bae6a7c] | 28 | #include <vector> |
---|
| 29 | |
---|
| 30 | using namespace std; |
---|
| 31 | |
---|
[56da40e] | 32 | #include "wx.h" |
---|
| 33 | #include "aventypes.h" |
---|
[08253d9] | 34 | #include "vector3.h" |
---|
[56da40e] | 35 | |
---|
[1eeb55a] | 36 | #ifdef USE_FNT |
---|
| 37 | #include "fnt.h" |
---|
| 38 | #endif |
---|
| 39 | |
---|
[56da40e] | 40 | class GfxCore; |
---|
| 41 | |
---|
[5627cbb] | 42 | string GetGLSystemDescription(); |
---|
[cc1a1d9] | 43 | |
---|
[d67450e] | 44 | // #define GLA_DEBUG |
---|
[1897247] | 45 | |
---|
[56da40e] | 46 | typedef Double glaCoord; |
---|
| 47 | |
---|
[aa048c3] | 48 | // Colours for drawing. Don't reorder these! |
---|
| 49 | enum 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, |
---|
[f4c5932] | 62 | col_BLUE, |
---|
[aa048c3] | 63 | col_LAST // must be the last entry here |
---|
| 64 | }; |
---|
| 65 | |
---|
[56da40e] | 66 | class GLAPen { |
---|
[aa048c3] | 67 | friend class GLACanvas; // allow direct access to components |
---|
| 68 | |
---|
| 69 | double components[3]; // red, green, blue |
---|
[9cf3688] | 70 | |
---|
[56da40e] | 71 | public: |
---|
| 72 | GLAPen(); |
---|
| 73 | ~GLAPen(); |
---|
| 74 | |
---|
| 75 | void SetColour(double red, double green, double blue); // arguments in range 0 to 1.0 |
---|
[f383708] | 76 | void Interpolate(const GLAPen&, double how_far); |
---|
[56da40e] | 77 | |
---|
[f7ea0e1] | 78 | double GetRed() const; |
---|
| 79 | double GetGreen() const; |
---|
| 80 | double GetBlue() const; |
---|
[56da40e] | 81 | }; |
---|
| 82 | |
---|
[db59b02] | 83 | const unsigned int INVALIDATE_ON_SCALE = 1; |
---|
| 84 | const unsigned int NEVER_CACHE = 2; |
---|
| 85 | |
---|
| 86 | class 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 | |
---|
[56da40e] | 99 | class GLACanvas : public wxGLCanvas { |
---|
[203d2a7] | 100 | #ifdef GLA_DEBUG |
---|
| 101 | int m_Vertices; |
---|
| 102 | #endif |
---|
| 103 | |
---|
[dde4fe7] | 104 | GLdouble modelview_matrix[16]; |
---|
| 105 | GLdouble projection_matrix[16]; |
---|
| 106 | GLint viewport[4]; |
---|
| 107 | |
---|
[c5fc8eb] | 108 | // Viewing volume diameter: |
---|
| 109 | glaCoord m_VolumeDiameter; |
---|
[56da40e] | 110 | |
---|
| 111 | // Parameters for plotting data: |
---|
[08253d9] | 112 | Double m_Pan, m_Tilt; |
---|
[56da40e] | 113 | Double m_Scale; |
---|
[d67450e] | 114 | Vector3 m_Translation; |
---|
[56da40e] | 115 | |
---|
[1eeb55a] | 116 | #ifdef USE_FNT |
---|
| 117 | fntTexFont m_Font; |
---|
| 118 | #else |
---|
[a2036bb] | 119 | static void * const m_Font; |
---|
[203d2a7] | 120 | static const int m_FontSize; |
---|
[1eeb55a] | 121 | #endif |
---|
[d9b3270] | 122 | |
---|
[1b12b82] | 123 | GLUquadric* m_Quadric; |
---|
[a517825] | 124 | |
---|
| 125 | GLuint m_Texture; |
---|
[95ce35f] | 126 | GLuint m_CrossTexture; |
---|
[a517825] | 127 | |
---|
[d67450e] | 128 | bool m_SmoothShading; |
---|
[a517825] | 129 | bool m_Textured; |
---|
[1eeb55a] | 130 | bool m_Perspective; |
---|
[c60062d] | 131 | bool m_Fog; |
---|
[db452ae] | 132 | bool m_AntiAlias; |
---|
[4ba80e0] | 133 | bool glpoint_ok; |
---|
[95ce35f] | 134 | bool glpoint_sprite; |
---|
[1eeb55a] | 135 | |
---|
[db59b02] | 136 | vector<GLAList> drawing_lists; |
---|
| 137 | mutable unsigned int list_flags; |
---|
[bae6a7c] | 138 | |
---|
[56da40e] | 139 | public: |
---|
[84f1ed1] | 140 | GLACanvas(wxWindow* parent, int id); |
---|
[56da40e] | 141 | ~GLACanvas(); |
---|
[2c8b64f] | 142 | |
---|
[1b12b82] | 143 | void FirstShow(); |
---|
| 144 | |
---|
[56da40e] | 145 | void Clear(); |
---|
| 146 | void StartDrawing(); |
---|
| 147 | void FinishDrawing(); |
---|
| 148 | |
---|
[c5fc8eb] | 149 | void SetVolumeDiameter(glaCoord diameter); |
---|
[56da40e] | 150 | void SetDataTransform(); |
---|
| 151 | void SetIndicatorTransform(); |
---|
[9cf3688] | 152 | |
---|
[d2fcc9b] | 153 | void DrawList(unsigned int l); |
---|
[76dd228] | 154 | void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation); |
---|
[d2fcc9b] | 155 | void InvalidateList(unsigned int l); |
---|
| 156 | virtual void GenerateList(unsigned int l) = 0; |
---|
[9cf3688] | 157 | |
---|
[56da40e] | 158 | void SetBackgroundColour(float red, float green, float blue); |
---|
[aa048c3] | 159 | void SetColour(const GLAPen& pen, double rgb_scale); |
---|
| 160 | void SetColour(const GLAPen& pen); |
---|
| 161 | void SetColour(gla_colour colour); |
---|
| 162 | |
---|
[56da40e] | 163 | void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str); |
---|
[1eeb55a] | 164 | void DrawIndicatorText(int x, int y, const wxString& str); |
---|
| 165 | void GetTextExtent(const wxString& str, int * x_ext, int * y_ext); |
---|
[9cf3688] | 166 | |
---|
[56da40e] | 167 | void BeginQuadrilaterals(); |
---|
| 168 | void EndQuadrilaterals(); |
---|
| 169 | void BeginLines(); |
---|
| 170 | void EndLines(); |
---|
[dde4fe7] | 171 | void BeginTriangleStrip(); |
---|
| 172 | void EndTriangleStrip(); |
---|
[56da40e] | 173 | void BeginTriangles(); |
---|
| 174 | void EndTriangles(); |
---|
| 175 | void BeginPolyline(); |
---|
| 176 | void EndPolyline(); |
---|
[45aa1d6] | 177 | void BeginPolygon(); |
---|
| 178 | void EndPolygon(); |
---|
[e633bb1] | 179 | void BeginBlobs(); |
---|
| 180 | void EndBlobs(); |
---|
[86fe6e4] | 181 | void BeginCrosses(); |
---|
| 182 | void EndCrosses(); |
---|
[9cf3688] | 183 | |
---|
[aa048c3] | 184 | void DrawRectangle(gla_colour edge, gla_colour fill, |
---|
[d67450e] | 185 | glaCoord x0, glaCoord y0, glaCoord w, glaCoord h); |
---|
[aa048c3] | 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); |
---|
[d67450e] | 190 | void DrawTriangle(gla_colour edge, gla_colour fill, |
---|
| 191 | const Vector3 &p0, const Vector3 &p1, const Vector3 &p2); |
---|
[9cf3688] | 192 | |
---|
[e633bb1] | 193 | void DrawBlob(glaCoord x, glaCoord y, glaCoord z); |
---|
[81aea4e] | 194 | void DrawBlob(glaCoord x, glaCoord y); |
---|
[86fe6e4] | 195 | void DrawCross(glaCoord x, glaCoord y, glaCoord z); |
---|
[e633bb1] | 196 | void DrawRing(glaCoord x, glaCoord y); |
---|
[9cf3688] | 197 | |
---|
[d67450e] | 198 | void PlaceVertex(const Vector3 & v) { |
---|
| 199 | PlaceVertex(v.GetX(), v.GetY(), v.GetZ()); |
---|
| 200 | } |
---|
[56da40e] | 201 | void PlaceVertex(glaCoord x, glaCoord y, glaCoord z); |
---|
| 202 | void PlaceIndicatorVertex(glaCoord x, glaCoord y); |
---|
[203d2a7] | 203 | |
---|
[d67450e] | 204 | void PlaceNormal(const Vector3 &v); |
---|
[9cf3688] | 205 | |
---|
[56da40e] | 206 | void EnableDashedLines(); |
---|
| 207 | void DisableDashedLines(); |
---|
| 208 | |
---|
[d67450e] | 209 | void EnableSmoothPolygons(bool filled); |
---|
[1b12b82] | 210 | void DisableSmoothPolygons(); |
---|
| 211 | |
---|
[08253d9] | 212 | void SetRotation(double pan, double tilt) { |
---|
| 213 | m_Pan = pan; |
---|
| 214 | m_Tilt = tilt; |
---|
| 215 | } |
---|
[56da40e] | 216 | void SetScale(Double); |
---|
[d67450e] | 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 | } |
---|
[56da40e] | 226 | void AddTranslationScreenCoordinates(int dx, int dy); |
---|
| 227 | |
---|
[d67450e] | 228 | bool Transform(const Vector3 & v, Double* x_out, Double* y_out, Double* z_out) const; |
---|
[3c3ca1d] | 229 | void ReverseTransform(Double x, Double y, Double* x_out, Double* y_out, Double* z_out) const; |
---|
[56da40e] | 230 | |
---|
[c09e6c8] | 231 | #ifdef USE_FNT |
---|
[1eeb55a] | 232 | int GetFontSize() const { return m_Font.getFontSize(); } |
---|
[c09e6c8] | 233 | #else |
---|
| 234 | int GetFontSize() const { return m_FontSize; } |
---|
| 235 | #endif |
---|
[087bc72] | 236 | |
---|
[d67450e] | 237 | void ToggleSmoothShading(); |
---|
| 238 | bool GetSmoothShading() const { return m_SmoothShading; } |
---|
| 239 | |
---|
[e7f9e99] | 240 | Double SurveyUnitsAcrossViewport() const; |
---|
[6abab84] | 241 | |
---|
[a517825] | 242 | void ToggleTextured(); |
---|
| 243 | bool GetTextured() const { return m_Textured; } |
---|
| 244 | |
---|
[6abab84] | 245 | void TogglePerspective() { m_Perspective = !m_Perspective; } |
---|
| 246 | bool GetPerspective() const { return m_Perspective; } |
---|
[045e2af] | 247 | |
---|
[c60062d] | 248 | void ToggleFog() { m_Fog = !m_Fog; } |
---|
| 249 | bool GetFog() const { return m_Fog; } |
---|
| 250 | |
---|
[db452ae] | 251 | void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; } |
---|
| 252 | bool GetAntiAlias() const { return m_AntiAlias; } |
---|
| 253 | |
---|
[045e2af] | 254 | bool SaveScreenshot(const wxString & fnm, int type) const; |
---|
[56da40e] | 255 | }; |
---|