summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2016-01-23 20:22:50 +0000
committerMatthias Melcher <fltk@matthiasm.com>2016-01-23 20:22:50 +0000
commitde12eddb59bea9ba529230d14cccf3dbef5518e4 (patch)
tree6c19dcb3d9c5ff7a8ad3cfb2db4ff31f87217e0e /src
parent1bb1e0f42e7bbcdaa7a4560940c2cd590fc954cf (diff)
Added OpenGL implementation of fl_vertex calls. Compiling and linking, but functionality untested.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11035 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Gl_Device_Plugin.cxx1
-rw-r--r--src/cfg_gfx/opengl.H58
-rw-r--r--src/cfg_gfx/opengl_vertex.cxx143
-rw-r--r--src/fl_arc.cxx6
-rw-r--r--src/fl_vertex.cxx49
5 files changed, 209 insertions, 48 deletions
diff --git a/src/Fl_Gl_Device_Plugin.cxx b/src/Fl_Gl_Device_Plugin.cxx
index 3ad9263ab..3e6144a35 100644
--- a/src/Fl_Gl_Device_Plugin.cxx
+++ b/src/Fl_Gl_Device_Plugin.cxx
@@ -54,6 +54,7 @@ const char *Fl_OpenGL_Display_Device::class_id = "Fl_OpenGL_Display_Device";
// ------ end of separate file! ------------------------------------------------
#include "cfg_gfx/opengl_rect.cxx"
+#include "cfg_gfx/opengl_vertex.cxx"
diff --git a/src/cfg_gfx/opengl.H b/src/cfg_gfx/opengl.H
index 86abea41a..dae36eb20 100644
--- a/src/cfg_gfx/opengl.H
+++ b/src/cfg_gfx/opengl.H
@@ -62,40 +62,30 @@ public:
void pop_clip();
void restore_clip();
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
-// void transformed_vertex0(COORD_T x, COORD_T y);
-// void fixloop();
-// void push_matrix();
-// void pop_matrix();
-// void mult_matrix(double a, double b, double c, double d, double x, double y);
-// void rotate(double d);
-// void begin_points();
-// void begin_line();
-// void begin_loop();
-// void begin_polygon();
-// void begin_complex_polygon();
-// double transform_x(double x, double y);
-// double transform_y(double x, double y);
-// double transform_dx(double x, double y);
-// double transform_dy(double x, double y);
-// void transformed_vertex(double xf, double yf);
-// void vertex(double x, double y);
-// void end_points();
-// void end_line();
-// void end_loop();
-// void end_polygon();
-// void end_complex_polygon();
-// void gap();
-// void circle(double x, double y, double r);
- void begin_complex_polygon() { }
- void transformed_vertex(double xf, double yf) { }
- void vertex(double x, double y) { }
- void end_points() { }
- void end_line() { }
- void end_loop() { }
- void end_polygon() { }
- void end_complex_polygon() { }
- void gap() { }
- void circle(double x, double y, double r) { }
+ // void push_matrix();
+ // void pop_matrix();
+ // void mult_matrix(double a, double b, double c, double d, double x, double y);
+ // void rotate(double d);
+ // double transform_x(double x, double y);
+ // double transform_y(double x, double y);
+ // double transform_dx(double x, double y);
+ // double transform_dy(double x, double y);
+ void transformed_vertex0(COORD_T x, COORD_T y);
+ void transformed_vertex(double xf, double yf);
+ void vertex(double x, double y);
+ void begin_points();
+ void end_points();
+ void begin_line();
+ void end_line();
+ void begin_loop();
+ void end_loop();
+ void begin_polygon();
+ void end_polygon();
+ void begin_complex_polygon();
+ void gap();
+ void end_complex_polygon();
+ void fixloop();
+ void circle(double x, double y, double r);
};
diff --git a/src/cfg_gfx/opengl_vertex.cxx b/src/cfg_gfx/opengl_vertex.cxx
new file mode 100644
index 000000000..cfc5df15b
--- /dev/null
+++ b/src/cfg_gfx/opengl_vertex.cxx
@@ -0,0 +1,143 @@
+//
+// "$Id$"
+//
+// Portable drawing routines for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2016 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file. If this
+// file is missing or damaged, see the license at:
+//
+// http://www.fltk.org/COPYING.php
+//
+// Please report all bugs and problems on the following page:
+//
+// http://www.fltk.org/str.php
+//
+
+#ifndef FL_CFG_GFX_OPENGL_VERTEX_CXX
+#define FL_CFG_GFX_OPENGL_VERTEX_CXX
+
+/**
+ \file opengl_vertex.cxx
+ \brief Portable drawing code for drawing arbitrary shapes with
+ simple 2D transformations, implemented for OpenGL.
+*/
+
+#include "opengl.H"
+
+#include <FL/fl_draw.H>
+#include <FL/x.h>
+#include <FL/gl.h>
+#include <FL/math.h>
+
+
+// Event though there are faster versions of the functions in OpenGL,
+// we use the default FLTK implementation for compatibility in the
+// following functions.
+
+// void Fl_OpenGL_Graphics_Driver::push_matrix()
+// void Fl_OpenGL_Graphics_Driver::pop_matrix()
+// void Fl_OpenGL_Graphics_Driver::mult_matrix(double a, double b, double c, double d, double x, double y)
+// void Fl_OpenGL_Graphics_Driver::rotate(double d)
+// double Fl_OpenGL_Graphics_Driver::transform_x(double x, double y)
+// double Fl_OpenGL_Graphics_Driver::transform_y(double x, double y)
+// double Fl_OpenGL_Graphics_Driver::transform_dx(double x, double y)
+// double Fl_OpenGL_Graphics_Driver::transform_dy(double x, double y)
+
+void Fl_OpenGL_Graphics_Driver::begin_points() {
+ glBegin(GL_POINTS);
+}
+
+void Fl_OpenGL_Graphics_Driver::end_points() {
+ glEnd();
+}
+
+void Fl_OpenGL_Graphics_Driver::begin_line() {
+ glBegin(GL_LINE_STRIP);
+}
+
+void Fl_OpenGL_Graphics_Driver::end_line() {
+ glEnd();
+}
+
+void Fl_OpenGL_Graphics_Driver::begin_loop() {
+ glBegin(GL_LINE_LOOP);
+}
+
+void Fl_OpenGL_Graphics_Driver::end_loop() {
+ glEnd();
+}
+
+void Fl_OpenGL_Graphics_Driver::begin_polygon() {
+ glBegin(GL_POLYGON);
+}
+
+void Fl_OpenGL_Graphics_Driver::end_polygon() {
+ glEnd();
+}
+
+void Fl_OpenGL_Graphics_Driver::begin_complex_polygon() {
+ glBegin(GL_POLYGON);
+}
+
+void Fl_OpenGL_Graphics_Driver::gap() {
+ glEnd();
+ glBegin(GL_POLYGON);
+}
+
+// FXIME: non-convex polygons are not supported yet
+// use gluTess* functions to do this; search for gluBeginPolygon
+void Fl_OpenGL_Graphics_Driver::end_complex_polygon() {
+ glEnd();
+}
+
+// remove equal points from closed path
+void Fl_OpenGL_Graphics_Driver::fixloop() { }
+
+void Fl_OpenGL_Graphics_Driver::transformed_vertex(double xf, double yf) {
+ glVertex2d(xf, yf);
+}
+
+void Fl_OpenGL_Graphics_Driver::transformed_vertex0(COORD_T x, COORD_T y) {
+ glVertex2d(x, y);
+}
+
+void Fl_OpenGL_Graphics_Driver::vertex(double x,double y) {
+ transformed_vertex0(x*m.a + y*m.c + m.x, x*m.b + y*m.d + m.y);
+}
+
+void Fl_OpenGL_Graphics_Driver::circle(double cx, double cy, double r) {
+ double rx = r * (m.c ? sqrt(m.a*m.a+m.c*m.c) : fabs(m.a));
+ double ry = r * (m.b ? sqrt(m.b*m.b+m.d*m.d) : fabs(m.d));
+ double rMax;
+ if (ry>rx) rMax = ry; else rMax = rx;
+
+ // from http://slabode.exofire.net/circle_draw.shtml and many other places
+ int num_segments = (int)(10 * sqrt(rMax))+1;
+ double theta = 2 * M_PI / float(num_segments);
+ double tangetial_factor = tan(theta);
+ double radial_factor = cosf(theta);//calculate the radial factor
+ double x = r; //we start at angle = 0
+ double y = 0;
+
+ glBegin(GL_LINE_LOOP);
+ for(int ii = 0; ii < num_segments; ii++) {
+ vertex(x + cx, y + cy); // output vertex
+ double tx = -y;
+ double ty = x;
+ x += tx * tangetial_factor;
+ y += ty * tangetial_factor;
+ x *= radial_factor;
+ y *= radial_factor;
+ }
+ glEnd();
+
+}
+
+#endif // FL_CFG_GFX_OPENGL_VERTEX_CXX
+
+//
+// End of "$Id$".
+//
diff --git a/src/fl_arc.cxx b/src/fl_arc.cxx
index 3895ca50a..a37e24ff8 100644
--- a/src/fl_arc.cxx
+++ b/src/fl_arc.cxx
@@ -71,12 +71,6 @@ void Fl_Graphics_Driver::arc(double x, double y, double r, double start, double
}
}
-#if 0 // portable version. X-specific one in fl_vertex.cxx
-void fl_circle(double x,double y,double r) {
- _fl_arc(x, y, r, r, 0, 360);
-}
-#endif
-
//
// End of "$Id$".
//
diff --git a/src/fl_vertex.cxx b/src/fl_vertex.cxx
index ae65fa5d4..16f0a501f 100644
--- a/src/fl_vertex.cxx
+++ b/src/fl_vertex.cxx
@@ -42,6 +42,7 @@
#include <FL/math.h>
#include <stdlib.h>
+
void Fl_Graphics_Driver::push_matrix() {
if (sptr==matrix_stack_size)
Fl::error("fl_push_matrix(): matrix stack overflow.");
@@ -79,21 +80,53 @@ void Fl_Graphics_Driver::rotate(double d) {
}
}
-void Fl_Graphics_Driver::begin_points() {n = 0; what = POINT_;}
+void Fl_Graphics_Driver::scale(double x, double y) {
+ mult_matrix(x,0,0,y,0,0);
+}
-void Fl_Graphics_Driver::begin_line() {n = 0; what = LINE;}
+void Fl_Graphics_Driver::scale(double x) {
+ mult_matrix(x,0,0,x,0,0);
+}
-void Fl_Graphics_Driver::begin_loop() {n = 0; what = LOOP;}
+void Fl_Graphics_Driver::translate(double x,double y) {
+ mult_matrix(1,0,0,1,x,y);
+}
-void Fl_Graphics_Driver::begin_polygon() {n = 0; what = POLYGON;}
+void Fl_Graphics_Driver::begin_points() {
+ n = 0;
+ what = POINT_;
+}
-double Fl_Graphics_Driver::transform_x(double x, double y) {return x*m.a + y*m.c + m.x;}
+void Fl_Graphics_Driver::begin_line() {
+ n = 0;
+ what = LINE;
+}
-double Fl_Graphics_Driver::transform_y(double x, double y) {return x*m.b + y*m.d + m.y;}
+void Fl_Graphics_Driver::begin_loop() {
+ n = 0;
+ what = LOOP;
+}
-double Fl_Graphics_Driver::transform_dx(double x, double y) {return x*m.a + y*m.c;}
+void Fl_Graphics_Driver::begin_polygon() {
+ n = 0;
+ what = POLYGON;
+}
-double Fl_Graphics_Driver::transform_dy(double x, double y) {return x*m.b + y*m.d;}
+double Fl_Graphics_Driver::transform_x(double x, double y) {
+ return x*m.a + y*m.c + m.x;
+}
+
+double Fl_Graphics_Driver::transform_y(double x, double y) {
+ return x*m.b + y*m.d + m.y;
+}
+
+double Fl_Graphics_Driver::transform_dx(double x, double y) {
+ return x*m.a + y*m.c;
+}
+
+double Fl_Graphics_Driver::transform_dy(double x, double y) {
+ return x*m.b + y*m.d;
+}
void Fl_Graphics_Driver::transformed_vertex0(COORD_T x, COORD_T y) {
if (!n || x != p[n-1].x || y != p[n-1].y) {