27 #if defined (HAVE_OPENGL)
38 #define LIGHT_MODE GL_FRONT_AND_BACK
55 : id (),
w (), h (), tw (), th (), tx (), ty (),
56 valid (false), count (1)
59 texture_rep (GLuint id_arg,
int w_arg,
int h_arg,
int tw_arg,
int th_arg)
60 : id (id_arg),
w (w_arg), h (h_arg), tw (tw_arg), th (th_arg),
67 glDeleteTextures (1, &
id);
70 void bind (
int mode)
const
71 {
if (valid) glBindTexture (mode,
id); }
73 void tex_coord (
double q,
double r)
const
74 {
if (valid) glTexCoord2d (q*tx, r*ty); }
87 opengl_texture (texture_rep *_rep) : rep (_rep) { }
90 opengl_texture (
void) : rep (new texture_rep ()) { }
92 opengl_texture (
const opengl_texture& tx)
98 ~opengl_texture (
void)
100 if (--rep->count == 0)
104 opengl_texture& operator = (
const opengl_texture& tx)
106 if (--rep->count == 0)
115 static opengl_texture create (
const octave_value& data);
117 void bind (
int mode = GL_TEXTURE_2D)
const
118 { rep->bind (mode); }
120 void tex_coord (
double q,
double r)
const
121 { rep->tex_coord (q, r); }
123 bool is_valid (
void)
const
124 {
return rep->valid; }
128 next_power_of_2 (
int n)
141 opengl_texture retval;
146 if (dv.length () == 3 && dv(2) == 3)
150 int h = dv(0),
w = dv(1), tw, th;
154 tw = next_power_of_2 (
w);
155 th = next_power_of_2 (
w);
157 glGenTextures (1, &
id);
158 glBindTexture (GL_TEXTURE_2D,
id);
166 for (
int i = 0; i < h; i++)
168 for (
int j = 0, idx = i*tw*3; j <
w; j++, idx += 3)
170 a[idx] = xdata(i,j,0);
171 a[idx+1] = xdata(i,j,1);
172 a[idx+2] = xdata(i,j,2);
176 glTexImage2D (GL_TEXTURE_2D, 0, 3, tw, th, 0, GL_RGB, GL_FLOAT, a);
184 for (
int i = 0; i < h; i++)
186 for (
int j = 0, idx = i*tw*3; j <
w; j++, idx += 3)
188 a[idx] = xdata(i,j,0);
189 a[idx+1] = xdata(i,j,1);
190 a[idx+2] = xdata(i,j,2);
194 glTexImage2D (GL_TEXTURE_2D, 0, 3, tw, th, 0,
195 GL_RGB, GL_UNSIGNED_BYTE, a);
200 warning (
"opengl_texture::create: invalid texture data type (expected double or uint8)");
205 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
206 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
208 if (glGetError () != GL_NO_ERROR)
209 warning (
"opengl_texture::create: OpenGL error while generating texture data");
211 retval = opengl_texture (
new texture_rep (
id,
w, h, tw, th));
215 warning (
"opengl_texture::create: invalid texture data size");
224 #if defined (HAVE_FRAMEWORK_OPENGL) && defined (HAVE_GLUTESSCALLBACK_THREEDOTS)
225 typedef GLvoid (CALLBACK *fcn) (...);
227 typedef void (CALLBACK *fcn) (
void);
232 opengl_tesselator (
void) : glu_tess (0), fill () { init (); }
234 virtual ~opengl_tesselator (
void)
235 {
if (glu_tess) gluDeleteTess (glu_tess); }
237 void begin_polygon (
bool filled =
true)
239 gluTessProperty (glu_tess, GLU_TESS_BOUNDARY_ONLY,
240 (filled ? GL_FALSE : GL_TRUE));
242 gluTessBeginPolygon (glu_tess,
this);
245 void end_polygon (
void)
const
246 { gluTessEndPolygon (glu_tess); }
248 void begin_contour (
void)
const
249 { gluTessBeginContour (glu_tess); }
252 { gluTessEndContour (glu_tess); }
254 void add_vertex (
double *
loc,
void *data)
const
255 { gluTessVertex (glu_tess, loc, data); }
258 virtual void begin (GLenum ) { }
260 virtual void end (
void) { }
262 virtual void vertex (
void * ) { }
264 virtual void combine (GLdouble [3] ,
void * [4] ,
265 GLfloat [4] ,
void ** ) { }
267 virtual void edge_flag (GLboolean ) { }
269 virtual void error (GLenum err)
270 {
::error (
"OpenGL tesselation error (%d)", err); }
272 virtual void init (
void)
274 glu_tess = gluNewTess ();
276 gluTessCallback (glu_tess, GLU_TESS_BEGIN_DATA,
277 reinterpret_cast<fcn> (tess_begin));
278 gluTessCallback (glu_tess, GLU_TESS_END_DATA,
279 reinterpret_cast<fcn> (tess_end));
280 gluTessCallback (glu_tess, GLU_TESS_VERTEX_DATA,
281 reinterpret_cast<fcn> (tess_vertex));
282 gluTessCallback (glu_tess, GLU_TESS_COMBINE_DATA,
283 reinterpret_cast<fcn> (tess_combine));
284 gluTessCallback (glu_tess, GLU_TESS_EDGE_FLAG_DATA,
285 reinterpret_cast<fcn> (tess_edge_flag));
286 gluTessCallback (glu_tess, GLU_TESS_ERROR_DATA,
287 reinterpret_cast<fcn> (tess_error));
290 bool is_filled (
void)
const {
return fill; }
293 static void CALLBACK tess_begin (GLenum
type,
void *t)
294 {
reinterpret_cast<opengl_tesselator *
> (t)->begin (type); }
296 static void CALLBACK tess_end (
void *t)
297 {
reinterpret_cast<opengl_tesselator *
> (t)->end (); }
299 static void CALLBACK tess_vertex (
void *v,
void *t)
300 {
reinterpret_cast<opengl_tesselator *
> (t)->vertex (v); }
302 static void CALLBACK tess_combine (GLdouble c[3],
void *v[4], GLfloat
w[4],
304 {
reinterpret_cast<opengl_tesselator *
> (t)->combine (c, v, w, out); }
306 static void CALLBACK tess_edge_flag (GLboolean flag,
void *t)
307 {
reinterpret_cast<opengl_tesselator *
> (t)->edge_flag (flag); }
309 static void CALLBACK tess_error (GLenum err,
void *t)
310 {
reinterpret_cast<opengl_tesselator *
> (t)->
error (err); }
316 opengl_tesselator (
const opengl_tesselator&);
318 opengl_tesselator operator = (
const opengl_tesselator&);
320 GLUtesselator *glu_tess;
328 class vertex_data_rep
343 vertex_data_rep (
void)
344 : coords (), color (), normal (), alpha (),
345 ambient (), diffuse (), specular (), specular_exp (),count (1) { }
348 double a,
float as,
float ds,
float ss,
float se)
349 : coords (c), color (col), normal (n), alpha (a),
350 ambient (as), diffuse (ds), specular (ss), specular_exp (se),
355 vertex_data_rep *rep;
357 vertex_data_rep *nil_rep (
void)
const
359 static vertex_data_rep *nr =
new vertex_data_rep ();
365 vertex_data (
void) : rep (nil_rep ())
368 vertex_data (
const vertex_data& v) : rep (v.rep)
372 double a,
float as,
float ds,
float ss,
float se)
373 : rep (new vertex_data_rep (c, col, n, a, as, ds, ss, se))
376 vertex_data (vertex_data_rep *new_rep)
381 if (--rep->count == 0)
385 vertex_data& operator = (
const vertex_data& v)
387 if (--rep->count == 0)
396 vertex_data_rep *get_rep (
void)
const {
return rep; }
400 opengl_renderer::patch_tesselator :
public opengl_tesselator
403 patch_tesselator (
opengl_renderer *r,
int cmode,
int lmode,
int idx = 0)
404 : opengl_tesselator (), renderer (r),
405 color_mode (cmode), light_mode (lmode), index (idx),
406 first (true), tmp_vdata ()
410 void begin (GLenum type)
415 if (color_mode == 2 || light_mode == 2)
416 glShadeModel (GL_SMOOTH);
418 glShadeModel (GL_FLAT);
421 renderer->set_polygon_offset (
true, 1+index);
430 renderer->set_polygon_offset (
false);
433 void vertex (
void *data)
435 vertex_data::vertex_data_rep *v
436 =
reinterpret_cast<vertex_data::vertex_data_rep *
> (data);
444 if (color_mode > 0 && (first || color_mode == 2))
448 if (col.
numel () == 3)
450 glColor3dv (col.
data ());
453 float buf[4] = { 0, 0, 0, 1 };
455 for (
int k = 0; k < 3; k++)
456 buf[k] = (v->ambient * col(k));
457 glMaterialfv (LIGHT_MODE, GL_AMBIENT, buf);
459 for (
int k = 0; k < 3; k++)
460 buf[k] = (v->diffuse * col(k));
461 glMaterialfv (LIGHT_MODE, GL_AMBIENT, buf);
466 if (light_mode > 0 && (first || light_mode == 2))
467 glNormal3dv (v->normal.data ());
469 glVertex3dv (v->coords.data ());
474 void combine (GLdouble xyz[3],
void *data[4], GLfloat w[4],
479 vertex_data::vertex_data_rep *v[4];
482 for (
int i = 0; i < 4; i++)
484 v[i] =
reinterpret_cast<vertex_data::vertex_data_rep *
> (data[i]);
486 if (vmax == 4 && ! v[i])
499 if (v[0]->color.numel ())
502 for (
int ic = 0; ic < 3; ic++)
503 for (
int iv = 0; iv < vmax; iv++)
504 cc(ic) += (w[iv] * v[iv]->color (ic));
507 if (v[0]->normal.numel () > 0)
509 for (
int in = 0; in < 3; in++)
510 for (
int iv = 0; iv < vmax; iv++)
511 nn(in) += (w[iv] * v[iv]->normal (in));
514 for (
int iv = 0; iv < vmax; iv++)
515 aa += (w[iv] * v[iv]->alpha);
517 vertex_data new_v (vv, cc,
nn, aa, v[0]->ambient, v[0]->diffuse,
518 v[0]->specular, v[0]->specular_exp);
519 tmp_vdata.push_back (new_v);
521 *out_data = new_v.get_rep ();
528 patch_tesselator (
const patch_tesselator&);
530 patch_tesselator& operator = (
const patch_tesselator&);
537 std::list<vertex_data> tmp_vdata;
551 if (go.
isa (
"figure"))
552 draw_figure (dynamic_cast<const figure::properties&> (props));
553 else if (go.
isa (
"axes"))
554 draw_axes (dynamic_cast<const axes::properties&> (props));
555 else if (go.
isa (
"line"))
556 draw_line (dynamic_cast<const line::properties&> (props));
557 else if (go.
isa (
"surface"))
558 draw_surface (dynamic_cast<const surface::properties&> (props));
559 else if (go.
isa (
"patch"))
560 draw_patch (dynamic_cast<const patch::properties&> (props));
561 else if (go.
isa (
"hggroup"))
562 draw_hggroup (dynamic_cast<const hggroup::properties&> (props));
563 else if (go.
isa (
"text"))
564 draw_text (dynamic_cast<const text::properties&> (props));
565 else if (go.
isa (
"image"))
566 draw_image (dynamic_cast<const image::properties&> (props));
567 else if (go.
isa (
"uimenu") || go.
isa (
"uicontrol")
568 || go.
isa (
"uicontextmenu") || go.
isa (
"uitoolbar")
569 || go.
isa (
"uipushtool") || go.
isa (
"uitoggletool"))
571 else if (go.
isa (
"uipanel"))
574 draw_uipanel (dynamic_cast<const uipanel::properties&> (props), go);
578 warning (
"opengl_renderer: cannot render object of type '%s'",
618 glEnable (GL_DEPTH_TEST);
619 glDepthFunc (GL_LEQUAL);
620 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
621 glAlphaFunc (GL_GREATER, 0.0
f);
622 glEnable (GL_NORMALIZE);
627 glEnable (GL_LINE_SMOOTH);
631 glDisable (GL_BLEND);
632 glDisable (GL_LINE_SMOOTH);
639 glClearColor (c(0), c(1), c(2), 1);
640 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
646 const Matrix& ticks,
double lim1,
double lim2,
647 double p1,
double p1N,
double p2,
double p2N,
652 for (
int i = 0; i < ticks.
numel (); i++)
654 double val = ticks(i);
655 if (lim1 <= val && val <= lim2)
659 glVertex3d (val, p1N, p2);
660 glVertex3d (val, p1, p2);
663 glVertex3d (val, p1, p2N);
664 glVertex3d (val, p1, p2);
669 glVertex3d (p1N, val, p2);
670 glVertex3d (p1, val, p2);
673 glVertex3d (p1, val, p2N);
674 glVertex3d (p1, val, p2);
679 glVertex3d (p1N, p2, val);
680 glVertex3d (p1, p2, val);
681 glVertex3d (p1, p2N, val);
682 glVertex3d (p1, p2, val);
692 double lim1,
double lim2,
693 double p1,
double p1N,
694 double p2,
double p2N,
695 double dx,
double dy,
double dz,
696 int xyz,
bool mirror)
700 for (
int i = 0; i < ticks.
numel (); i++)
702 double val = ticks(i);
704 if (lim1 <= val && val <= lim2)
708 glVertex3d (val, p1, p2);
709 glVertex3d (val, p1+dy, p2+dz);
712 glVertex3d (val, p1N, p2N);
713 glVertex3d (val, p1N-dy, p2N-dz);
718 glVertex3d (p1, val, p2);
719 glVertex3d (p1+dx, val, p2+dz);
722 glVertex3d (p1N, val, p2N);
723 glVertex3d (p1N-dx, val, p2N-dz);
728 glVertex3d (p1, p2, val);
729 glVertex3d (p1+dx, p2+dy, val);
732 glVertex3d (p1N, p2N, val);
733 glVertex3d (p1N-dx, p2N-dy, val);
745 double lim1,
double lim2,
746 double p1,
double p2,
747 int xyz,
int ha,
int va,
748 int& wmax,
int& hmax)
750 int nticks = ticks.
numel ();
751 int nlabels = ticklabels.
numel ();
756 for (
int i = 0; i < nticks; i++)
758 double val = ticks(i);
760 if (lim1 <= val && val <= lim2)
764 std::string label (ticklabels(i % nlabels));
765 label.erase (0, label.find_first_not_of (
" "));
766 label = label.substr (0, label.find_last_not_of (
" ")+1);
783 wmax =
std::max (wmax, static_cast<int> (b(2)));
784 hmax =
std::max (hmax, static_cast<int> (b(3)));
796 xZ1 = x_zlim(0)-(x_zlim(1)-x_zlim(0))/2;
797 xZ2 = x_zlim(1)+(x_zlim(1)-x_zlim(0))/2;
802 #if defined (HAVE_FRAMEWORK_OPENGL)
808 glGetIntegerv (GL_VIEWPORT, vw);
810 glMatrixMode (GL_MODELVIEW);
813 glMultMatrixd (x_mat1.
data ());
814 glMatrixMode (GL_PROJECTION);
816 glOrtho (0, vw[2], vw[3], 0,
xZ1,
xZ2);
817 glMultMatrixd (x_mat2.
data ());
818 glMatrixMode (GL_MODELVIEW);
820 glClear (GL_DEPTH_BUFFER_BIT);
822 glDisable (GL_LINE_SMOOTH);
849 glVertex3d (xPlane, yPlaneN, zPlaneN);
850 glVertex3d (xPlane, yPlane, zPlaneN);
851 glVertex3d (xPlane, yPlane, zPlane);
852 glVertex3d (xPlane, yPlaneN, zPlane);
855 glVertex3d (xPlaneN, yPlane, zPlaneN);
856 glVertex3d (xPlane, yPlane, zPlaneN);
857 glVertex3d (xPlane, yPlane, zPlane);
858 glVertex3d (xPlaneN, yPlane, zPlane);
861 glVertex3d (xPlaneN, yPlaneN, zPlane);
862 glVertex3d (xPlane, yPlaneN, zPlane);
863 glVertex3d (xPlane, yPlane, zPlane);
864 glVertex3d (xPlaneN, yPlane, zPlane);
902 glVertex3d (xPlaneN, ypTick, zpTick);
903 glVertex3d (xPlane, ypTick, zpTick);
907 glVertex3d (xPlaneN, ypTickN, zpTick);
908 glVertex3d (xPlane, ypTickN, zpTick);
909 glVertex3d (xPlaneN, ypTickN, zpTickN);
910 glVertex3d (xPlane, ypTickN, zpTickN);
911 glVertex3d (xPlaneN, ypTick, zpTickN);
912 glVertex3d (xPlane, ypTick, zpTickN);
917 glVertex3d (xpTick, yPlaneN, zpTick);
918 glVertex3d (xpTick, yPlane, zpTick);
920 if (props.
is_box () && ! plotyy)
922 glVertex3d (xpTickN, yPlaneN, zpTick);
923 glVertex3d (xpTickN, yPlane, zpTick);
924 glVertex3d (xpTickN, yPlaneN, zpTickN);
925 glVertex3d (xpTickN, yPlane, zpTickN);
926 glVertex3d (xpTick, yPlaneN, zpTickN);
927 glVertex3d (xpTick, yPlane, zpTickN);
935 glVertex3d (xPlaneN, yPlane, zPlaneN);
936 glVertex3d (xPlaneN, yPlane, zPlane);
940 glVertex3d (xPlane, yPlaneN, zPlaneN);
941 glVertex3d (xPlane, yPlaneN, zPlane);
946 glVertex3d (xPlane, yPlane, zPlaneN);
947 glVertex3d (xPlane, yPlane, zPlane);
951 glVertex3d (xPlane, yPlaneN, zPlaneN);
952 glVertex3d (xPlane, yPlaneN, zPlane);
956 glVertex3d (xPlaneN, yPlane, zPlaneN);
957 glVertex3d (xPlaneN, yPlane, zPlane);
960 glVertex3d (xPlaneN, yPlaneN, zPlaneN);
961 glVertex3d (xPlaneN, yPlaneN, zPlane);
979 double fy = props.
get_fy ();
980 double fz = props.
get_fz ();
998 bool do_xgrid = (props.
is_xgrid () && (gridstyle !=
"none"));
1000 && (minorgridstyle !=
"none"));
1005 int wmax = 0, hmax = 0;
1006 bool tick_along_z = nearhoriz ||
xisinf (fy);
1014 yPlane, yPlaneN, layer2Dtop ? zPlaneN : zPlane,
1021 zpTick, zpTickN, 0., 0.,
1022 signum (zpTick-zpTickN)*fz*xticklen,
1029 signum (ypTick-ypTickN)*fy*xticklen,
1034 if (xticklabels.
numel () > 0)
1036 int halign = (xstate ==
AXE_HORZ_DIR ? 1 : (xyzSym ? 0 : 2));
1037 int valign = (xstate ==
AXE_VERT_DIR ? 1 : (x2Dtop ? 0 : 2));
1041 zpTick+
signum (zpTick-zpTickN)*fz*xtickoffset,
1042 0, halign, valign, wmax, hmax);
1045 ypTick+
signum (ypTick-ypTickN)*fy*xtickoffset,
1046 zpTick, 0, halign, valign, wmax, hmax);
1051 render_grid (minorgridstyle, xmticks, x_min, x_max,
1052 yPlane, yPlaneN, layer2Dtop ? zPlaneN : zPlane,
1060 zpTick, zpTickN, 0., 0.,
1061 signum (zpTick-zpTickN)*fz*xticklen/2,
1066 signum (ypTick-ypTickN)*fy*xticklen/2,
1087 double fx = props.
get_fx ();
1088 double fz = props.
get_fz ();
1106 bool do_ygrid = (props.
is_ygrid () && (gridstyle !=
"none"));
1108 && (minorgridstyle !=
"none"));
1113 int wmax = 0, hmax = 0;
1114 bool tick_along_z = nearhoriz ||
xisinf (fx);
1123 xPlane, xPlaneN, layer2Dtop ? zPlaneN : zPlane,
1129 zpTick, zpTickN, 0., 0.,
1130 signum (zpTick-zpTickN)*fz*yticklen,
1135 signum (xPlaneN-xPlane)*fx*yticklen,
1139 if (yticklabels.
numel () > 0)
1142 ? 1 : (!xyzSym || y2Dright ? 0 : 2));
1147 zpTick+
signum (zpTick-zpTickN)*fz*ytickoffset,
1148 1, halign, valign, wmax, hmax);
1151 xpTick+
signum (xpTick-xpTickN)*fx*ytickoffset,
1152 zpTick, 1, halign, valign, wmax, hmax);
1157 render_grid (minorgridstyle, ymticks, y_min, y_max,
1158 xPlane, xPlaneN, layer2Dtop ? zPlaneN : zPlane,
1166 zpTick, zpTickN, 0., 0.,
1167 signum (zpTick-zpTickN)*fz*yticklen/2,
1172 signum (xpTick-xpTickN)*fx*yticklen/2,
1190 double fx = props.
get_fx ();
1191 double fy = props.
get_fy ();
1205 bool do_zgrid = (props.
is_zgrid () && (gridstyle !=
"none"));
1207 && (minorgridstyle !=
"none"));
1212 int wmax = 0, hmax = 0;
1220 xPlane, xPlaneN, yPlane, yPlaneN, 2,
true);
1228 signum (xPlaneN-xPlane)*fx*zticklen,
1233 signum (yPlane-yPlaneN)*fy*zticklen,
1240 yPlaneN, yPlane, 0.,
1241 signum (yPlaneN-yPlane)*fy*zticklen,
1246 signum (xPlane-xPlaneN)*fx*zticklen,
1251 if (zticklabels.
numel () > 0)
1254 int valign = (zstate ==
AXE_VERT_DIR ? 1 : (zSign ? 3 : 2));
1260 xPlaneN+
signum (xPlaneN-xPlane)*fx*ztickoffset,
1261 yPlane, 2, halign, valign, wmax, hmax);
1264 yPlane+
signum (yPlane-yPlaneN)*fy*ztickoffset,
1265 2, halign, valign, wmax, hmax);
1271 yPlaneN+
signum (yPlaneN-yPlane)*fy*ztickoffset,
1272 2, halign, valign, wmax, hmax);
1275 xPlane+
signum (xPlane-xPlaneN)*fx*ztickoffset,
1276 yPlaneN, 2, halign, valign, wmax, hmax);
1282 render_grid (minorgridstyle, zmticks, z_min, z_max,
1283 xPlane, xPlaneN, yPlane, yPlaneN, 2,
true);
1293 signum (xPlaneN-xPlane)*fx*zticklen/2,
1298 signum (yPlane-yPlaneN)*fy*zticklen/2,
1305 yPlaneN, yPlane, 0.,
1306 signum (yPlaneN-yPlane)*fy*zticklen/2,
1311 signum (xPlane-xPlaneN)*fx*zticklen/2,
1327 GLboolean antialias;
1328 glGetBooleanv (GL_LINE_SMOOTH, &antialias);
1330 if (antialias == GL_TRUE)
1331 glEnable (GL_LINE_SMOOTH);
1334 std::list<graphics_object> obj_list;
1335 std::list<graphics_object>::iterator it;
1348 if (go.
isa (
"light"))
1351 obj_list.push_back (go);
1357 it = obj_list.begin ();
1358 while (it != obj_list.end ())
1369 it = obj_list.erase (it);
1377 glDisable (GL_DEPTH_TEST);
1379 for (it = obj_list.begin (); it != obj_list.end (); it++)
1387 glEnable (GL_DEPTH_TEST);
1407 if (x_max > floatmax || y_max > floatmax || z_max > floatmax
1408 || x_min < -floatmax || y_min < -floatmax || z_min < -floatmax)
1410 warning (
"gl-render: data values greater than float capacity. (1) Scale data, or (2) Use gnuplot");
1429 set_clipbox (x_min, x_max, y_min, y_max, z_min, z_max);
1441 bool has_z = (z.
numel () > 0);
1447 std::vector<octave_uint8> clip (n);
1450 for (
int i = 0; i < n; i++)
1451 clip[i] = (
clip_code (
x(i), y(i), z(i)) & clip_mask);
1456 for (
int i = 0; i < n; i++)
1457 clip[i] = (
clip_code (
x(i), y(i), z_mid) & clip_mask);
1470 for (
int i = 1; i < n; i++)
1472 if ((clip[i-1] & clip[i]) == clip_ok)
1477 glBegin (GL_LINE_STRIP);
1478 glVertex3d (
x(i-1), y(i-1), z(i-1));
1480 glVertex3d (
x(i), y(i), z(i));
1496 for (
int i = 1; i < n; i++)
1498 if ((clip[i-1] & clip[i]) == clip_ok)
1503 glBegin (GL_LINE_STRIP);
1504 glVertex2d (
x(i-1), y(i-1));
1506 glVertex2d (
x(i), y(i));
1544 for (
int i = 0; i < n; i++)
1546 if (clip[i] == clip_ok)
1548 has_z ? z(i) : static_cast<double> (i) / n,
1574 warning (
"opengl_renderer::draw: phong light model not supported");
1593 : props.get_facecolor_rgb ());
1600 float cb[4] = { 0.0, 0.0, 0.0, 1.0 };
1606 bool x_mat = (x.
rows () == z.
rows ());
1609 i1 = i2 = j1 = j2 = 0;
1611 if ((fc_mode > 0 && fc_mode < 3) || ec_mode > 0)
1616 for (
int i = 0; i < zr; i++)
1621 for (
int j = 0; j < zc; j++)
1630 if (fa_mode > 0 || ea_mode > 0)
1636 if (fl_mode > 0 || el_mode > 0)
1638 float buf[4] = { ss, ss, ss, 1 };
1640 glMaterialfv (LIGHT_MODE, GL_SPECULAR, buf);
1641 glMaterialf (LIGHT_MODE, GL_SHININESS, se);
1653 if (fc_mode == 0 || fc_mode == 3)
1655 glColor3dv (fcolor.
data ());
1658 for (
int i = 0; i < 3; i++)
1659 cb[i] = as * fcolor(i);
1660 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
1662 for (
int i = 0; i < 3; i++)
1663 cb[i] = ds * fcolor(i);
1664 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
1669 glEnable (GL_LIGHTING);
1670 glShadeModel ((fc_mode == 2 || fl_mode == 2) ? GL_SMOOTH : GL_FLAT);
1673 glEnable (GL_TEXTURE_2D);
1675 for (
int i = 1; i < zc; i++)
1683 for (
int j = 1; j < zr; j++)
1686 if (clip(j-1, i-1) || clip(j, i-1)
1687 || clip(j-1, i) || clip(j, i))
1696 else if (fc_mode == 2)
1714 tex.tex_coord (
double (i-1) / (zc-1),
1715 double (j-1) / (zr-1));
1716 else if (fc_mode > 0)
1719 for (
int k = 0; k < 3; k++)
1720 cb[k] = c(j-1, i-1, k);
1725 for (
int k = 0; k < 3; k++)
1727 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
1729 for (
int k = 0; k < 3; k++)
1730 cb[k] = ds * c(j-1, i-1, k);
1731 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
1736 d = sqrt (n(j-1,i-1,0) * n(j-1,i-1,0)
1737 + n(j-1,i-1,1) * n(j-1,i-1,1)
1738 + n(j-1,i-1,2) * n(j-1,i-1,2));
1739 glNormal3d (n(j-1,i-1,0)/d,
1743 glVertex3d (
x(j1,i-1), y(j-1,i1), z(j-1,i-1));
1747 tex.tex_coord (
double (i) / (zc-1),
double (j-1) / (zr-1));
1748 else if (fc_mode == 2)
1750 for (
int k = 0; k < 3; k++)
1751 cb[k] = c(j-1, i, k);
1756 for (
int k = 0; k < 3; k++)
1758 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
1760 for (
int k = 0; k < 3; k++)
1761 cb[k] = ds * c(j-1, i, k);
1762 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
1768 d = sqrt (n(j-1,i,0) * n(j-1,i,0)
1769 + n(j-1,i,1) * n(j-1,i,1)
1770 + n(j-1,i,2) * n(j-1,i,2));
1771 glNormal3d (n(j-1,i,0)/d, n(j-1,i,1)/d, n(j-1,i,2)/d);
1774 glVertex3d (
x(j1,i), y(j-1,i2), z(j-1,i));
1778 tex.tex_coord (
double (i) / (zc-1),
double (j) / (zr-1));
1779 else if (fc_mode == 2)
1781 for (
int k = 0; k < 3; k++)
1787 for (
int k = 0; k < 3; k++)
1789 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
1791 for (
int k = 0; k < 3; k++)
1792 cb[k] = ds * c(j, i, k);
1793 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
1798 d = sqrt (n(j,i,0) * n(j,i,0)
1799 + n(j,i,1) * n(j,i,1)
1800 + n(j,i,2) * n(j,i,2));
1801 glNormal3d (n(j,i,0)/d, n(j,i,1)/d, n(j,i,2)/d);
1803 glVertex3d (
x(j2,i), y(j,i2), z(j,i));
1807 tex.tex_coord (
double (i-1) / (zc-1),
double (j) / (zr-1));
1808 else if (fc_mode == 2)
1810 for (
int k = 0; k < 3; k++)
1811 cb[k] = c(j, i-1, k);
1816 for (
int k = 0; k < 3; k++)
1818 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
1820 for (
int k = 0; k < 3; k++)
1821 cb[k] = ds * c(j, i-1, k);
1822 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
1827 d = sqrt (n(j,i-1,0) * n(j,i-1,0)
1828 + n(j,i-1,1) * n(j,i-1,1)
1829 + n(j,i-1,2) * n(j,i-1,2));
1830 glNormal3d (n(j,i-1,0)/d, n(j,i-1,1)/d, n(j,i-1,2)/d);
1832 glVertex3d (
x(j2,i-1), y(j,i1), z(j,i-1));
1840 glDisable (GL_TEXTURE_2D);
1843 glDisable (GL_LIGHTING);
1857 glColor3dv (ecolor.
data ());
1860 for (
int i = 0; i < 3; i++)
1861 cb[i] = as * ecolor(i);
1862 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
1864 for (
int i = 0; i < 3; i++)
1865 cb[i] = ds * ecolor(i);
1866 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
1871 glEnable (GL_LIGHTING);
1872 glShadeModel ((ec_mode == 2 || el_mode == 2) ? GL_SMOOTH : GL_FLAT);
1881 for (
int i = 0; i < zc; i++)
1889 for (
int j = 1; j < zr; j++)
1891 if (clip(j-1,i) || clip(j,i))
1900 else if (ec_mode == 2)
1918 for (
int k = 0; k < 3; k++)
1919 cb[k] = c(j-1, i, k);
1924 for (
int k = 0; k < 3; k++)
1926 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
1928 for (
int k = 0; k < 3; k++)
1929 cb[k] = ds * c(j-1, i, k);
1930 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
1935 d = sqrt (n(j-1,i,0) * n(j-1,i,0)
1936 + n(j-1,i,1) * n(j-1,i,1)
1937 + n(j-1,i,2) * n(j-1,i,2));
1938 glNormal3d (n(j-1,i,0)/d, n(j-1,i,1)/d, n(j-1,i,2)/d);
1940 glVertex3d (
x(j1,i), y(j-1,i2), z(j-1,i));
1945 for (
int k = 0; k < 3; k++)
1951 for (
int k = 0; k < 3; k++)
1953 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
1955 for (
int k = 0; k < 3; k++)
1956 cb[k] = ds * c(j, i, k);
1957 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
1962 d = sqrt (n(j,i,0) * n(j,i,0)
1963 + n(j,i,1) * n(j,i,1)
1964 + n(j,i,2) * n(j,i,2));
1965 glNormal3d (n(j,i,0)/d, n(j,i,1)/d, n(j,i,2)/d);
1967 glVertex3d (
x(j2,i), y(j,i2), z(j,i));
1978 for (
int j = 0; j < zr; j++)
1986 for (
int i = 1; i < zc; i++)
1988 if (clip(j,i-1) || clip(j,i))
1997 else if (ec_mode == 2)
2015 for (
int k = 0; k < 3; k++)
2016 cb[k] = c(j, i-1, k);
2021 for (
int k = 0; k < 3; k++)
2023 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
2025 for (
int k = 0; k < 3; k++)
2026 cb[k] = ds * c(j, i-1, k);
2027 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
2032 d = sqrt (n(j,i-1,0) * n(j,i-1,0)
2033 + n(j,i-1,1) * n(j,i-1,1)
2034 + n(j,i-1,2) * n(j,i-1,2));
2035 glNormal3d (n(j,i-1,0)/d, n(j,i-1,1)/d, n(j,i-1,2)/d);
2037 glVertex3d (
x(j2,i-1), y(j,i1), z(j,i-1));
2042 for (
int k = 0; k < 3; k++)
2048 for (
int k = 0; k < 3; k++)
2050 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
2052 for (
int k = 0; k < 3; k++)
2053 cb[k] = ds * c(j, i, k);
2054 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
2059 d = sqrt (n(j,i,0) * n(j,i,0)
2060 + n(j,i,1) * n(j,i,1)
2061 + n(j,i,2) * n(j,i,2));
2062 glNormal3d (n(j,i,0)/d, n(j,i,1)/d, n(j,i,2)/d);
2064 glVertex3d (
x(j2,i), y(j,i2), z(j,i));
2075 glDisable (GL_LIGHTING);
2110 if ((mecolor.
numel () == 0 || mfcolor.
numel () == 0)
2117 for (
int i = 0; i < zc; i++)
2122 for (
int j = 0; j < zr; j++)
2130 if ((do_edge && mecolor.
numel () == 0)
2131 || (do_face && mfcolor.
numel () == 0))
2136 for (
int k = 0; k < 3; k++)
2140 Matrix lc = (do_edge ? (mecolor.
numel () == 0 ? cc : mecolor)
2142 Matrix fc = (do_face ? (mfcolor.
numel () == 0 ? cc : mfcolor)
2169 bool has_z = (v.
columns () > 2);
2170 bool has_facecolor =
false;
2171 bool has_facealpha =
false;
2199 for (
int i = 0; i < nv; i++)
2202 for (
int i = 0; i < nv; i++)
2208 for (
int i = 0; i < nf; i++)
2213 for (
int j = 0; j < fcmax && !
xisnan (
f(i,j)); j++, count++)
2214 fclip = (fclip || clip(
int (
f(i,j) - 1)));
2220 if (fc_mode > 0 || ec_mode > 0)
2243 has_facecolor = ((c.
numel () > 0) && (c.
rows () == f.
rows ()));
2246 if (fa_mode > 0 || ea_mode > 0)
2250 has_facealpha = ((a.
numel () > 0) && (a.
rows () == f.
rows ()));
2254 std::vector<vertex_data> vdata (f.
numel ());
2256 for (
int i = 0; i < nf; i++)
2257 for (
int j = 0; j < count_f(i); j++)
2259 int idx =
int (
f(i,j) - 1);
2266 vv(0) = v(idx,0); vv(1) = v(idx,1);
2275 cc(0) = c(i,0), cc(1) = c(i,1), cc(2) = c(i,2);
2277 cc(0) = c(idx,0), cc(1) = c(idx,1), cc(2) = c(idx,2);
2288 vertex_data (vv, cc,
nn, aa, as, ds, ss, se);
2291 if (fl_mode > 0 || el_mode > 0)
2293 float buf[4] = { ss, ss, ss, 1 };
2295 glMaterialfv (LIGHT_MODE, GL_SPECULAR, buf);
2296 glMaterialf (LIGHT_MODE, GL_SHININESS, se);
2306 glColor3dv (fcolor.
data ());
2309 float cb[4] = { 0, 0, 0, 1 };
2311 for (
int i = 0; i < 3; i++)
2312 cb[i] = (as * fcolor(i));
2313 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
2315 for (
int i = 0; i < 3; i++)
2316 cb[i] = ds * fcolor(i);
2317 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
2322 glEnable (GL_LIGHTING);
2325 patch_tesselator tess (
this, fc_mode, fl_mode, 0);
2327 for (
int i = 0; i < nf; i++)
2332 tess.begin_polygon (
true);
2333 tess.begin_contour ();
2335 for (
int j = 0; j < count_f(i); j++)
2337 vertex_data::vertex_data_rep *vv = vdata[i+j*fr].get_rep ();
2339 tess.add_vertex (vv->coords.fortran_vec (), vv);
2342 tess.end_contour ();
2343 tess.end_polygon ();
2347 glDisable (GL_LIGHTING);
2362 glColor3dv (ecolor.
data ());
2365 float cb[4] = { 0, 0, 0, 1 };
2367 for (
int i = 0; i < 3; i++)
2368 cb[i] = (as * ecolor(i));
2369 glMaterialfv (LIGHT_MODE, GL_AMBIENT, cb);
2371 for (
int i = 0; i < 3; i++)
2372 cb[i] = ds * ecolor(i);
2373 glMaterialfv (LIGHT_MODE, GL_DIFFUSE, cb);
2378 glEnable (GL_LIGHTING);
2386 patch_tesselator tess (
this, ec_mode, el_mode);
2388 for (
int i = 0; i < nf; i++)
2395 for (
int j = 0; j < count_f(i); j++)
2397 if (! clip(
int (
f(i,j) - 1)))
2399 vertex_data::vertex_data_rep *vv
2400 = vdata[i+j*fr].get_rep ();
2401 const Matrix m = vv->coords;
2405 glBegin (GL_LINE_STRIP);
2407 glVertex3d (m(0), m(1), m(2));
2421 tess.begin_polygon (
false);
2422 tess.begin_contour ();
2424 for (
int j = 0; j < count_f(i); j++)
2426 vertex_data::vertex_data_rep *vv
2427 = vdata[i+j*fr].get_rep ();
2428 tess.add_vertex (vv->coords.fortran_vec (), vv);
2431 tess.end_contour ();
2432 tess.end_polygon ();
2440 glDisable (GL_LIGHTING);
2458 bool has_markerfacecolor =
false;
2465 if (mc.
rows () == 1)
2469 if (mfcolor.
numel () == 0
2473 if (mecolor.
numel () == 0
2479 if (c.
numel () == 0)
2481 has_markerfacecolor = ((c.
numel () > 0)
2490 for (
int i = 0; i < nf; i++)
2491 for (
int j = 0; j < count_f(i); j++)
2493 int idx =
int (
f(i,j) - 1);
2502 if (has_markerfacecolor)
2503 cc(0) = c(i,0), cc(1) = c(i,1), cc(2) = c(i,2);
2505 cc(0) = c(idx,0), cc(1) = c(idx,1), cc(2) = c(idx,2);
2508 Matrix lc = (do_edge ? (mecolor.
numel () == 0 ? cc : mecolor)
2510 Matrix fc = (do_face ? (mfcolor.
numel () == 0 ? cc : mfcolor)
2513 draw_marker (v(idx,0), v(idx,1), (has_z ? v(idx,2) : 0), lc, fc);
2536 bool blend = glIsEnabled (GL_BLEND);
2538 glEnable (GL_BLEND);
2539 glEnable (GL_ALPHA_TEST);
2540 glRasterPos3d (pos(0), pos(1), pos.
numel () > 2 ? pos(2) : 0.0);
2541 glBitmap (0, 0, 0, 0, bbox(0), bbox(1), 0);
2542 glDrawPixels (bbox(2), bbox(3),
2544 glDisable (GL_ALPHA_TEST);
2546 glDisable (GL_BLEND);
2555 int h = dv(0), w = dv(1);
2564 if (w > 1 &&
x(1) ==
x(0))
2565 x(1) =
x(1) + (w-1);
2567 if (h > 1 && y(1) == y(0))
2568 y(1) = y(1) + (h-1);
2575 warning (
"gl-render: image x,y data too large to draw");
2580 float pix_dx, pix_dy;
2582 float nor_dx, nor_dy;
2586 pix_dx = (p1(0) - p0(0))/(w-1);
2587 nor_dx = (
x(1) -
x(0))/(w-1);
2592 pix_dx = p1w(0) - p0(0);
2598 pix_dy = (p1(1) - p0(1))/(h-1);
2599 nor_dy = (y(1) - y(0))/(h-1);
2604 pix_dy = p1h(1) - p0(1);
2616 float im_xmin =
x(0) - nor_dx/2;
2617 float im_xmax =
x(1) + nor_dx/2;
2618 float im_ymin = y(0) - nor_dy/2;
2619 float im_ymax = y(1) + nor_dy/2;
2623 j0 += (
xmin - im_xmin)/nor_dx + 1;
2625 j1 -= (im_xmax -
xmax)/nor_dx ;
2628 i0 += (
ymin - im_ymin)/nor_dy + 1;
2630 i1 -= (im_ymax -
ymax)/nor_dy;
2635 glGetFloatv (GL_VIEWPORT, vp);
2640 if (i0 >= i1 || j0 >= j1)
2643 glPixelZoom (pix_dx, -pix_dy);
2644 glRasterPos3d (im_xmin + nor_dx*j0, im_ymin + nor_dy*i0, 0);
2647 glPixelStorei (GL_UNPACK_ALIGNMENT,1);
2650 if (dv.length () == 3 && dv(2) == 3)
2658 for (
int i = i0; i < i1; i++)
2660 for (
int j = j0, idx = (i-i0)*(j1-j0)*3; j < j1; j++, idx += 3)
2662 a[idx] = xcdata(i,j,0);
2663 a[idx+1] = xcdata(i,j,1);
2664 a[idx+2] = xcdata(i,j,2);
2677 for (
int i = i0; i < i1; i++)
2679 for (
int j = j0, idx = (i-i0)*(j1-j0)*3; j < j1; j++, idx += 3)
2681 a[idx] = xcdata(i,j,0);
2682 a[idx+1] = xcdata(i,j,1);
2683 a[idx+2] = xcdata(i,j,2);
2687 draw_pixels (j1-j0, i1-i0, GL_RGB, GL_UNSIGNED_SHORT, a);
2696 for (
int i = i0; i < i1; i++)
2698 for (
int j = j0, idx = (i-i0)*(j1-j0)*3; j < j1; j++, idx += 3)
2700 a[idx] = xcdata(i,j,0);
2701 a[idx+1] = xcdata(i,j,1);
2702 a[idx+2] = xcdata(i,j,2);
2706 draw_pixels (j1-j0, i1-i0, GL_RGB, GL_UNSIGNED_BYTE, a);
2709 warning (
"opengl_texture::draw: invalid image data type (expected double, uint16, or uint8)");
2712 warning (
"opengl_texture::draw: invalid image size (expected n*m*3 or n*m)");
2720 glViewport (0, 0, w, h);
2725 GLenum type,
const GLvoid *data)
2727 glDrawPixels (width, height, format, type, data);
2733 glColor3dv (c.
data ());
2755 glPolygonOffset (offset, offset);
2756 glEnable (GL_POLYGON_OFFSET_FILL);
2757 glEnable (GL_POLYGON_OFFSET_LINE);
2761 glDisable (GL_POLYGON_OFFSET_FILL);
2762 glDisable (GL_POLYGON_OFFSET_LINE);
2779 glLineStipple (1, static_cast<unsigned short> (0xFFFF));
2783 glLineStipple (1, static_cast<unsigned short> (0x8888));
2785 glLineStipple (1, static_cast<unsigned short> (0x0FFF));
2787 glLineStipple (1, static_cast<unsigned short> (0x020F));
2789 glLineStipple (1, static_cast<unsigned short> (0x0000));
2791 if (solid && ! use_stipple)
2792 glDisable (GL_LINE_STIPPLE);
2794 glEnable (GL_LINE_STIPPLE);
2799 double z1,
double z2)
2801 double dx = (x2-x1);
2802 double dy = (y2-y1);
2803 double dz = (z2-z1);
2805 x1 -= 0.001*dx; x2 += 0.001*dx;
2806 y1 -= 0.001*dy; y2 += 0.001*dy;
2807 z1 -= 0.001*dz; z2 += 0.001*dz;
2811 p(0) = -1; p(3) = x2;
2812 glClipPlane (GL_CLIP_PLANE0, p.data ());
2813 p(0) = 1; p(3) = -x1;
2814 glClipPlane (GL_CLIP_PLANE1, p.data ());
2815 p(0) = 0; p(1) = -1; p(3) = y2;
2816 glClipPlane (GL_CLIP_PLANE2, p.data ());
2817 p(1) = 1; p(3) = -y1;
2818 glClipPlane (GL_CLIP_PLANE3, p.data ());
2819 p(1) = 0; p(2) = -1; p(3) = z2;
2820 glClipPlane (GL_CLIP_PLANE4, p.data ());
2821 p(2) = 1; p(3) = -z1;
2822 glClipPlane (GL_CLIP_PLANE5, p.data ());
2832 bool has_clipping = (glIsEnabled (GL_CLIP_PLANE0) == GL_TRUE);
2834 if (enable != has_clipping)
2837 for (
int i = 0; i < 6; i++)
2838 glEnable (GL_CLIP_PLANE0+i);
2840 for (
int i = 0; i < 6; i++)
2841 glDisable (GL_CLIP_PLANE0+i);
2848 #if defined (HAVE_FRAMEWORK_OPENGL)
2854 glGetIntegerv (GL_VIEWPORT, vw);
2856 glMatrixMode (GL_PROJECTION);
2859 glOrtho (0, vw[2], vw[3], 0,
xZ1,
xZ2);
2860 glMatrixMode (GL_MODELVIEW);
2876 glMatrixMode (GL_MODELVIEW);
2878 glMatrixMode (GL_PROJECTION);
2890 glTranslated (tmp(0), tmp(1), -tmp(2));
2894 glColor3dv (fc.
data ());
2897 if (lc.
numel () > 0)
2899 glColor3dv (lc.
data ());
2900 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
2901 glEdgeFlag (GL_TRUE);
2904 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
2910 glColor3dv (lc.
data ());
2921 if (filled && (c ==
'+' || c ==
'x' || c ==
'*' || c ==
'.'))
2924 unsigned int ID = glGenLists (1);
2928 const double sqrt2d4 = 0.35355339059327;
2929 double tt = sz*sqrt2d4;
2931 glNewList (ID, GL_COMPILE);
2937 glVertex2f (-sz/2, 0);
2938 glVertex2f (sz/2, 0);
2939 glVertex2f (0, -sz/2);
2940 glVertex2f (0, sz/2);
2945 glVertex2f (-sz/2, -sz/2);
2946 glVertex2f (sz/2, sz/2);
2947 glVertex2f (-sz/2, sz/2);
2948 glVertex2f (sz/2, -sz/2);
2953 glVertex2f (-sz/2, 0);
2954 glVertex2f (sz/2, 0);
2955 glVertex2f (0, -sz/2);
2956 glVertex2f (0, sz/2);
2957 glVertex2f (-tt, -tt);
2958 glVertex2f (+tt, +tt);
2959 glVertex2f (-tt, +tt);
2960 glVertex2f (+tt, -tt);
2965 double ang_step = M_PI / 5;
2967 glBegin (GL_POLYGON);
2968 for (
double ang = 0; ang < (2*M_PI); ang += ang_step)
2969 glVertex2d (sz*cos (ang)/3, sz*sin (ang)/3);
2974 glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP));
2975 glVertex2d (-sz/2, -sz/2);
2976 glVertex2d (-sz/2, sz/2);
2977 glVertex2d (sz/2, sz/2);
2978 glVertex2d (sz/2, -sz/2);
2983 double ang_step = M_PI / 5;
2985 glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP));
2986 for (
double ang = 0; ang < (2*M_PI); ang += ang_step)
2987 glVertex2d (sz*cos (ang)/2, sz*sin (ang)/2);
2992 glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP));
2993 glVertex2d (0, -sz/2);
2994 glVertex2d (sz/2, 0);
2995 glVertex2d (0, sz/2);
2996 glVertex2d (-sz/2, 0);
3000 glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP));
3001 glVertex2f (0, sz/2);
3002 glVertex2f (sz/2, -sz/2);
3003 glVertex2f (-sz/2, -sz/2);
3007 glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP));
3008 glVertex2f (0, -sz/2);
3009 glVertex2f (-sz/2, sz/2);
3010 glVertex2f (sz/2, sz/2);
3014 glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP));
3015 glVertex2f (sz/2, 0);
3016 glVertex2f (-sz/2, sz/2);
3017 glVertex2f (-sz/2, -sz/2);
3021 glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP));
3022 glVertex2f (-sz/2, 0);
3023 glVertex2f (sz/2, -sz/2);
3024 glVertex2f (sz/2, sz/2);
3031 double dr = 1.0 - sin (M_PI/10)/sin (3*M_PI/10)*1.02;
3033 glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP));
3034 for (
int i = 0; i < 2*5; i++)
3036 ang = (-0.5 +
double(i+1)/5) * M_PI;
3037 r = 1.0 - (dr * fmod (
double(i+1), 2.0));
3038 glVertex2d (sz*r*cos (ang)/2, sz*r*sin (ang)/2);
3047 double dr = 1.0 - 0.5/sin (M_PI/3)*1.02;
3049 glBegin ((filled ? GL_POLYGON : GL_LINE_LOOP));
3050 for (
int i = 0; i < 2*6; i++)
3052 ang = (0.5 +
double(i+1)/6.0) * M_PI;
3053 r = 1.0 - (dr * fmod (
double(i+1), 2.0));
3054 glVertex2d (sz*r*cos (ang)/2, sz*r*sin (ang)/2);
3060 warning (
"opengl_renderer: unsupported marker '%s'",
3074 int halign,
int valign,
double rotation)
3078 halign, valign, rotation,
"none");
3084 double x,
double y,
double z,
3085 int halign,
int valign,
double rotation)
3089 return Matrix (1, 4, 0.0);
3095 bool blend = glIsEnabled (GL_BLEND);
3097 glEnable (GL_BLEND);
3098 glEnable (GL_ALPHA_TEST);
3099 glRasterPos3d (x, y, z);
3100 glBitmap(0, 0, 0, 0, bbox(0), bbox(1), 0);
3101 glDrawPixels (bbox(2), bbox(3),
3102 GL_RGBA, GL_UNSIGNED_BYTE, pixels.
data ());
3103 glDisable (GL_ALPHA_TEST);
3105 glDisable (GL_BLEND);
3109 ::warning (
"render_text: cannot render text, Freetype library not available");
3110 return Matrix (1, 4, 0.0);