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