00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (gl_render_h)
00024 #define gl_render_h 1
00025
00026 #ifdef HAVE_WINDOWS_H
00027 #define WIN32_LEAN_AND_MEAN
00028 #include <windows.h>
00029 #endif
00030
00031 #ifdef HAVE_GL_GL_H
00032 #include <GL/gl.h>
00033 #elif defined HAVE_OPENGL_GL_H || defined HAVE_FRAMEWORK_OPENGL
00034 #include <OpenGL/gl.h>
00035 #endif
00036
00037 #ifdef HAVE_GL_GLU_H
00038 #include <GL/glu.h>
00039 #elif defined HAVE_OPENGL_GLU_H || defined HAVE_FRAMEWORK_OPENGL
00040 #include <OpenGL/glu.h>
00041 #endif
00042
00043 #include "graphics.h"
00044 #include "txt-eng-ft.h"
00045
00046 class
00047 OCTINTERP_API
00048 opengl_renderer
00049 {
00050 public:
00051 opengl_renderer (void)
00052 : toolkit (), xform (), xmin (), xmax (), ymin (), ymax (),
00053 zmin (), zmax (), xZ1 (), xZ2 (), marker_id (), filled_marker_id (),
00054 camera_pos (), camera_dir ()
00055 #if HAVE_FREETYPE
00056 , text_renderer ()
00057 #endif
00058 { }
00059
00060 virtual ~opengl_renderer (void) { }
00061
00062 virtual void draw (const graphics_object& go);
00063
00064 virtual void draw (const Matrix& hlist)
00065 {
00066 int len = hlist.length ();
00067
00068 for (int i = len-1; i >= 0; i--)
00069 {
00070 graphics_object obj = gh_manager::get_object (hlist(i));
00071
00072 if (obj)
00073 draw (obj);
00074 }
00075 }
00076
00077 virtual void set_viewport (int w, int h);
00078 virtual graphics_xform get_transform (void) const { return xform; }
00079
00080 protected:
00081 virtual void draw_figure (const figure::properties& props);
00082 virtual void draw_axes (const axes::properties& props);
00083 virtual void draw_line (const line::properties& props);
00084 virtual void draw_surface (const surface::properties& props);
00085 virtual void draw_patch (const patch::properties& props);
00086 virtual void draw_hggroup (const hggroup::properties& props);
00087 virtual void draw_text (const text::properties& props);
00088 virtual void draw_image (const image::properties& props);
00089
00090 virtual void set_color (const Matrix& c);
00091 virtual void set_polygon_offset (bool on, double offset = 0.0);
00092 virtual void set_linewidth (float w);
00093 virtual void set_linestyle (const std::string& s, bool stipple = false);
00094 virtual void set_clipbox (double x1, double x2, double y1, double y2,
00095 double z1, double z2);
00096 virtual void set_clipping (bool on);
00097 virtual void set_font (const base_properties& props);
00098
00099 virtual void init_marker (const std::string& m, double size, float width);
00100 virtual void end_marker (void);
00101 virtual void draw_marker (double x, double y, double z,
00102 const Matrix& lc, const Matrix& fc);
00103
00104 virtual void text_to_pixels (const std::string& txt,
00105 uint8NDArray& pixels,
00106 Matrix& bbox,
00107 int halign = 0, int valign = 0,
00108 double rotation = 0.0);
00109
00110 virtual Matrix render_text (const std::string& txt,
00111 double x, double y, double z,
00112 int halign, int valign, double rotation = 0.0);
00113
00114 virtual void draw_pixels (GLsizei w, GLsizei h, GLenum format,
00115 GLenum type, const GLvoid *data);
00116
00117 virtual void render_grid (const std::string& gridstyle, const Matrix& ticks,
00118 double lim1, double lim2,
00119 double p1, double p1N, double p2, double p2N,
00120 int xyz, bool is_3D);
00121
00122 virtual void render_tickmarks (const Matrix& ticks, double lim1, double lim2,
00123 double p1, double p1N, double p2, double p2N,
00124 double dx, double dy, double dz,
00125 int xyz, bool doubleside);
00126
00127 virtual void render_ticktexts (const Matrix& ticks,
00128 const string_vector& ticklabels,
00129 double lim1, double lim2,
00130 double p1, double p2,
00131 int xyz, int ha, int va,
00132 int& wmax, int& hmax);
00133
00134 private:
00135 opengl_renderer (const opengl_renderer&)
00136 : toolkit (), xform (), xmin (), xmax (), ymin (), ymax (),
00137 zmin (), zmax (), xZ1 (), xZ2 (), marker_id (), filled_marker_id (),
00138 camera_pos (), camera_dir ()
00139 #if HAVE_FREETYPE
00140 , text_renderer ()
00141 #endif
00142 { }
00143
00144 opengl_renderer& operator = (const opengl_renderer&)
00145 { return *this; }
00146
00147 bool is_nan_or_inf (double x, double y, double z) const
00148 {
00149 return (xisnan (x) || xisnan (y) || xisnan (z)
00150 || xisinf (x) || xisinf (y) || xisinf (z));
00151 }
00152
00153 octave_uint8 clip_code (double x, double y, double z) const
00154 {
00155 return ((x < xmin ? 1 : 0)
00156 | (x > xmax ? 1 : 0) << 1
00157 | (y < ymin ? 1 : 0) << 2
00158 | (y > ymax ? 1 : 0) << 3
00159 | (z < zmin ? 1 : 0) << 4
00160 | (z > zmax ? 1 : 0) << 5
00161 | (is_nan_or_inf (x, y, z) ? 0 : 1) << 6);
00162 }
00163
00164 unsigned int make_marker_list (const std::string& m, double size,
00165 bool filled) const;
00166
00167 void setup_opengl_transformation (const axes::properties& props);
00168
00169 void draw_axes_planes (const axes::properties& props);
00170 void draw_axes_boxes (const axes::properties& props);
00171
00172 void draw_axes_x_grid (const axes::properties& props);
00173 void draw_axes_y_grid (const axes::properties& props);
00174 void draw_axes_z_grid (const axes::properties& props);
00175
00176 void draw_axes_children (const axes::properties& props);
00177
00178 private:
00179
00180 graphics_toolkit toolkit;
00181
00182
00183 graphics_xform xform;
00184
00185
00186 double xmin, xmax;
00187 double ymin, ymax;
00188 double zmin, zmax;
00189
00190
00191 double xZ1, xZ2;
00192
00193
00194 unsigned int marker_id, filled_marker_id;
00195
00196
00197 ColumnVector camera_pos, camera_dir;
00198
00199 #if HAVE_FREETYPE
00200
00201 ft_render text_renderer;
00202 #endif
00203
00204 private:
00205 class patch_tesselator;
00206 };
00207
00208 #endif