[56da40e] | 1 | // |
---|
| 2 | // gla.h |
---|
| 3 | // |
---|
| 4 | // Header file for the GLA abstraction layer. |
---|
| 5 | // |
---|
| 6 | // Copyright (C) 2002 Mark R. Shinwell. |
---|
[aea4f8b] | 7 | // Copyright (C) 2003,2004,2005,2006,2007,2011 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 |
---|
[ecbc6c18] | 21 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[56da40e] | 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; |
---|
[807f9dd] | 133 | bool save_hints; |
---|
[fe075d7] | 134 | enum { UNKNOWN = 0, POINT = 'P', LINES = 'L', SPRITE = 'S' }; |
---|
| 135 | int blob_method; |
---|
| 136 | int cross_method; |
---|
[1eeb55a] | 137 | |
---|
[db59b02] | 138 | vector<GLAList> drawing_lists; |
---|
| 139 | mutable unsigned int list_flags; |
---|
[bae6a7c] | 140 | |
---|
[807f9dd] | 141 | wxString vendor, renderer; |
---|
| 142 | |
---|
| 143 | bool CheckVisualFidelity(const unsigned char * target) const; |
---|
| 144 | |
---|
[56da40e] | 145 | public: |
---|
[84f1ed1] | 146 | GLACanvas(wxWindow* parent, int id); |
---|
[56da40e] | 147 | ~GLACanvas(); |
---|
[2c8b64f] | 148 | |
---|
[1b12b82] | 149 | void FirstShow(); |
---|
| 150 | |
---|
[56da40e] | 151 | void Clear(); |
---|
| 152 | void StartDrawing(); |
---|
| 153 | void FinishDrawing(); |
---|
| 154 | |
---|
[c5fc8eb] | 155 | void SetVolumeDiameter(glaCoord diameter); |
---|
[56da40e] | 156 | void SetDataTransform(); |
---|
| 157 | void SetIndicatorTransform(); |
---|
[9cf3688] | 158 | |
---|
[d2fcc9b] | 159 | void DrawList(unsigned int l); |
---|
[76dd228] | 160 | void DrawList2D(unsigned int l, glaCoord x, glaCoord y, Double rotation); |
---|
[d2fcc9b] | 161 | void InvalidateList(unsigned int l); |
---|
| 162 | virtual void GenerateList(unsigned int l) = 0; |
---|
[9cf3688] | 163 | |
---|
[56da40e] | 164 | void SetBackgroundColour(float red, float green, float blue); |
---|
[aa048c3] | 165 | void SetColour(const GLAPen& pen, double rgb_scale); |
---|
| 166 | void SetColour(const GLAPen& pen); |
---|
| 167 | void SetColour(gla_colour colour); |
---|
| 168 | |
---|
[56da40e] | 169 | void DrawText(glaCoord x, glaCoord y, glaCoord z, const wxString& str); |
---|
[1eeb55a] | 170 | void DrawIndicatorText(int x, int y, const wxString& str); |
---|
| 171 | void GetTextExtent(const wxString& str, int * x_ext, int * y_ext); |
---|
[9cf3688] | 172 | |
---|
[56da40e] | 173 | void BeginQuadrilaterals(); |
---|
| 174 | void EndQuadrilaterals(); |
---|
| 175 | void BeginLines(); |
---|
| 176 | void EndLines(); |
---|
[dde4fe7] | 177 | void BeginTriangleStrip(); |
---|
| 178 | void EndTriangleStrip(); |
---|
[56da40e] | 179 | void BeginTriangles(); |
---|
| 180 | void EndTriangles(); |
---|
| 181 | void BeginPolyline(); |
---|
| 182 | void EndPolyline(); |
---|
[45aa1d6] | 183 | void BeginPolygon(); |
---|
| 184 | void EndPolygon(); |
---|
[e633bb1] | 185 | void BeginBlobs(); |
---|
| 186 | void EndBlobs(); |
---|
[86fe6e4] | 187 | void BeginCrosses(); |
---|
| 188 | void EndCrosses(); |
---|
[9cf3688] | 189 | |
---|
[aa048c3] | 190 | void DrawRectangle(gla_colour edge, gla_colour fill, |
---|
[d67450e] | 191 | glaCoord x0, glaCoord y0, glaCoord w, glaCoord h); |
---|
[aa048c3] | 192 | void DrawShadedRectangle(const GLAPen & fill_bot, const GLAPen & fill_top, |
---|
| 193 | glaCoord x0, glaCoord y0, glaCoord w, glaCoord h); |
---|
| 194 | void DrawCircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius); |
---|
| 195 | void DrawSemicircle(gla_colour edge, gla_colour fill, glaCoord cx, glaCoord cy, glaCoord radius, glaCoord start); |
---|
[d67450e] | 196 | void DrawTriangle(gla_colour edge, gla_colour fill, |
---|
| 197 | const Vector3 &p0, const Vector3 &p1, const Vector3 &p2); |
---|
[9cf3688] | 198 | |
---|
[e633bb1] | 199 | void DrawBlob(glaCoord x, glaCoord y, glaCoord z); |
---|
[81aea4e] | 200 | void DrawBlob(glaCoord x, glaCoord y); |
---|
[86fe6e4] | 201 | void DrawCross(glaCoord x, glaCoord y, glaCoord z); |
---|
[e633bb1] | 202 | void DrawRing(glaCoord x, glaCoord y); |
---|
[9cf3688] | 203 | |
---|
[d67450e] | 204 | void PlaceVertex(const Vector3 & v) { |
---|
| 205 | PlaceVertex(v.GetX(), v.GetY(), v.GetZ()); |
---|
| 206 | } |
---|
[56da40e] | 207 | void PlaceVertex(glaCoord x, glaCoord y, glaCoord z); |
---|
| 208 | void PlaceIndicatorVertex(glaCoord x, glaCoord y); |
---|
[203d2a7] | 209 | |
---|
[d67450e] | 210 | void PlaceNormal(const Vector3 &v); |
---|
[9cf3688] | 211 | |
---|
[56da40e] | 212 | void EnableDashedLines(); |
---|
| 213 | void DisableDashedLines(); |
---|
| 214 | |
---|
[d67450e] | 215 | void EnableSmoothPolygons(bool filled); |
---|
[1b12b82] | 216 | void DisableSmoothPolygons(); |
---|
| 217 | |
---|
[08253d9] | 218 | void SetRotation(double pan, double tilt) { |
---|
| 219 | m_Pan = pan; |
---|
| 220 | m_Tilt = tilt; |
---|
| 221 | } |
---|
[56da40e] | 222 | void SetScale(Double); |
---|
[d67450e] | 223 | void SetTranslation(const Vector3 &v) { |
---|
| 224 | m_Translation = v; |
---|
| 225 | } |
---|
| 226 | void AddTranslation(const Vector3 &v) { |
---|
| 227 | m_Translation += v; |
---|
| 228 | } |
---|
| 229 | const Vector3 & GetTranslation() const { |
---|
| 230 | return m_Translation; |
---|
| 231 | } |
---|
[56da40e] | 232 | void AddTranslationScreenCoordinates(int dx, int dy); |
---|
| 233 | |
---|
[f6d8375] | 234 | bool Transform(const Vector3 & v, double* x_out, double* y_out, double* z_out) const; |
---|
| 235 | void ReverseTransform(Double x, Double y, double* x_out, double* y_out, double* z_out) const; |
---|
[56da40e] | 236 | |
---|
[c09e6c8] | 237 | #ifdef USE_FNT |
---|
[1eeb55a] | 238 | int GetFontSize() const { return m_Font.getFontSize(); } |
---|
[c09e6c8] | 239 | #else |
---|
| 240 | int GetFontSize() const { return m_FontSize; } |
---|
| 241 | #endif |
---|
[087bc72] | 242 | |
---|
[d67450e] | 243 | void ToggleSmoothShading(); |
---|
| 244 | bool GetSmoothShading() const { return m_SmoothShading; } |
---|
| 245 | |
---|
[e7f9e99] | 246 | Double SurveyUnitsAcrossViewport() const; |
---|
[6abab84] | 247 | |
---|
[a517825] | 248 | void ToggleTextured(); |
---|
| 249 | bool GetTextured() const { return m_Textured; } |
---|
| 250 | |
---|
[6abab84] | 251 | void TogglePerspective() { m_Perspective = !m_Perspective; } |
---|
| 252 | bool GetPerspective() const { return m_Perspective; } |
---|
[045e2af] | 253 | |
---|
[c60062d] | 254 | void ToggleFog() { m_Fog = !m_Fog; } |
---|
| 255 | bool GetFog() const { return m_Fog; } |
---|
| 256 | |
---|
[db452ae] | 257 | void ToggleAntiAlias() { m_AntiAlias = !m_AntiAlias; } |
---|
| 258 | bool GetAntiAlias() const { return m_AntiAlias; } |
---|
| 259 | |
---|
[045e2af] | 260 | bool SaveScreenshot(const wxString & fnm, int type) const; |
---|
[aea4f8b] | 261 | |
---|
| 262 | void ReadPixels(int width, int height, unsigned char * buf) const; |
---|
[56da40e] | 263 | }; |
---|