From 2b3567c83ca18b5dad62be7f10cc71446c028164 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Tue, 26 Jan 2016 20:48:21 +0000 Subject: OpenGL new naming scheme. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11055 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Gl_Device_Plugin.cxx | 15 +- src/cfg_gfx/opengl.H | 101 ---------- src/cfg_gfx/opengl_arci.cxx | 70 ------- src/cfg_gfx/opengl_color.cxx | 70 ------- src/cfg_gfx/opengl_font.cxx | 133 ------------- src/cfg_gfx/opengl_line_style.cxx | 70 ------- src/cfg_gfx/opengl_rect.cxx | 209 --------------------- src/cfg_gfx/opengl_vertex.cxx | 142 -------------- src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.h | 101 ++++++++++ .../OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx | 70 +++++++ .../OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx | 70 +++++++ .../OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx | 151 +++++++++++++++ .../Fl_OpenGL_Graphics_Driver_line_style.cxx | 70 +++++++ .../OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx | 209 +++++++++++++++++++++ .../OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx | 142 ++++++++++++++ 15 files changed, 821 insertions(+), 802 deletions(-) delete mode 100644 src/cfg_gfx/opengl.H delete mode 100644 src/cfg_gfx/opengl_arci.cxx delete mode 100644 src/cfg_gfx/opengl_color.cxx delete mode 100644 src/cfg_gfx/opengl_font.cxx delete mode 100644 src/cfg_gfx/opengl_line_style.cxx delete mode 100644 src/cfg_gfx/opengl_rect.cxx delete mode 100644 src/cfg_gfx/opengl_vertex.cxx create mode 100644 src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.h create mode 100644 src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx create mode 100644 src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx create mode 100644 src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx create mode 100644 src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx create mode 100644 src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx create mode 100644 src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx diff --git a/src/Fl_Gl_Device_Plugin.cxx b/src/Fl_Gl_Device_Plugin.cxx index a21aef2b0..9845c9f4f 100644 --- a/src/Fl_Gl_Device_Plugin.cxx +++ b/src/Fl_Gl_Device_Plugin.cxx @@ -36,7 +36,8 @@ #include #include -#include "src/cfg_gfx/opengl.H" + +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver.h" Fl_OpenGL_Display_Device *Fl_OpenGL_Display_Device::display_device() { static Fl_OpenGL_Display_Device *display = new Fl_OpenGL_Display_Device(new Fl_OpenGL_Graphics_Driver()); @@ -53,12 +54,12 @@ const char *Fl_OpenGL_Display_Device::class_id = "Fl_OpenGL_Display_Device"; #endif // ------ end of separate file! ------------------------------------------------ -#include "cfg_gfx/opengl_arci.cxx" -#include "cfg_gfx/opengl_color.cxx" -#include "cfg_gfx/opengl_font.cxx" -#include "cfg_gfx/opengl_line_style.cxx" -#include "cfg_gfx/opengl_rect.cxx" -#include "cfg_gfx/opengl_vertex.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx" #if defined(__APPLE__) diff --git a/src/cfg_gfx/opengl.H b/src/cfg_gfx/opengl.H deleted file mode 100644 index 48944fcb8..000000000 --- a/src/cfg_gfx/opengl.H +++ /dev/null @@ -1,101 +0,0 @@ -// -// "$Id$" -// -// Definition of OpenGL graphics driver -// 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 -// - -/** - \file opengl.H - \brief Definition of OpenGL graphics driver. - */ - -#ifndef FL_CFG_GFX_OPENGL_H -#define FL_CFG_GFX_OPENGL_H - -#include - - -/** - \brief OpenGL specific graphics class. - */ -class FL_EXPORT Fl_OpenGL_Graphics_Driver : public Fl_Graphics_Driver { -public: - static const char *class_id; - const char *class_name() {return class_id;}; - // --- line and polygon drawing with integer coordinates - void point(int x, int y); - void rect(int x, int y, int w, int h); - void rectf(int x, int y, int w, int h); - void line(int x, int y, int x1, int y1); - void line(int x, int y, int x1, int y1, int x2, int y2); - void xyline(int x, int y, int x1); - void xyline(int x, int y, int x1, int y2); - void xyline(int x, int y, int x1, int y2, int x3); - void yxline(int x, int y, int y1); - void yxline(int x, int y, int y1, int x2); - void yxline(int x, int y, int y1, int x2, int y3); - void loop(int x0, int y0, int x1, int y1, int x2, int y2); - void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3); - void polygon(int x0, int y0, int x1, int y1, int x2, int y2); - void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3); - void push_clip(int x, int y, int w, int h); - int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H); - int not_clipped(int x, int y, int w, int h); - void push_no_clip(); - 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 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); - // --- implementation is in src/fl_arc.cxx which includes src/cfg_gfx/xxx_arc.cxx if needed - // using void Fl_Graphics_Driver::arc(double x, double y, double r, double start, double end); - // --- implementation is in src/fl_arci.cxx which includes src/cfg_gfx/xxx_arci.cxx - void arc(int x, int y, int w, int h, double a1, double a2); - void pie(int x, int y, int w, int h, double a1, double a2); - // --- implementation is in src/fl_line_style.cxx which includes src/cfg_gfx/xxx_line_style.cxx - void line_style(int style, int width=0, char* dashes=0); - // --- implementation is in src/fl_color.cxx which includes src/cfg_gfx/xxx_color.cxx - void color(Fl_Color c); - Fl_Color color() { return color_; } - void color(uchar r, uchar g, uchar b); - // --- implementation is in src/fl_font.cxx which includes src/cfg_gfx/xxx_font.cxx - void draw(const char *str, int n, int x, int y); - double width(const char *str, int n); - void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); - int height(); - int descent(); -}; - - -#endif // FL_CFG_GFX_OPENGL_H - -// -// End of "$Id$". -// diff --git a/src/cfg_gfx/opengl_arci.cxx b/src/cfg_gfx/opengl_arci.cxx deleted file mode 100644 index 15ec4cf36..000000000 --- a/src/cfg_gfx/opengl_arci.cxx +++ /dev/null @@ -1,70 +0,0 @@ -// -// "$Id$" -// -// Arc (integer) drawing functions for the Fast Light Tool Kit (FLTK). -// -// Copyright 1998-2010 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_ARCI_CXX -#define FL_CFG_GFX_OPENGL_ARCI_CXX - -/** - \file opengl_arci.cxx - \brief Utility functions for drawing circles using integers -*/ - -#include -#define _USE_MATH_DEFINES -#include - -void Fl_OpenGL_Graphics_Driver::arc(int x,int y,int w,int h,double a1,double a2) { - if (w <= 0 || h <= 0) return; - while (a2 - -// Implementation of fl_color(i), fl_color(r,g,b). - -void Fl_OpenGL_Graphics_Driver::color(Fl_Color i) { - // FIXME: do we need the code below? - /* -#if HAVE_GL_OVERLAY -#if defined(WIN32) - if (fl_overlay && fl_overlay_depth) { - if (fl_overlay_depth < 8) { - // only black & white produce the expected colors. This could - // be improved by fixing the colormap set in Fl_Gl_Overlay.cxx - int size = 1<= size-2) glIndexi(size-1); - else glIndexi(i); - } else { - glIndexi(i ? i : FL_GRAY_RAMP); - } - return; - } -#else - if (fl_overlay) {glIndexi(int(fl_xpixel(i))); return;} -#endif -#endif -*/ - if (i & 0xffffff00) { - unsigned rgb = (unsigned)i; - fl_color((uchar)(rgb >> 24), (uchar)(rgb >> 16), (uchar)(rgb >> 8)); - } else { - Fl_Graphics_Driver::color(i); - uchar red, green, blue; - Fl::get_color(i, red, green, blue); - glColor3ub(red, green, blue); - } -} - -void Fl_OpenGL_Graphics_Driver::color(uchar r,uchar g,uchar b) { - Fl_Graphics_Driver::color( fl_rgb_color(r, g, b) ); - glColor3ub(r,g,b); -} - -// -// End of "$Id$". -// diff --git a/src/cfg_gfx/opengl_font.cxx b/src/cfg_gfx/opengl_font.cxx deleted file mode 100644 index 18c0c2b77..000000000 --- a/src/cfg_gfx/opengl_font.cxx +++ /dev/null @@ -1,133 +0,0 @@ -// -// "$Id$" -// -// Standard X11 font selection code 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 -// - -/* - This module implements a lowest-common-denominator font for OpenGL. - It will always work, even if the main graphics library does not support - rendering text into a texture buffer. - - The font is limited to a single face and ASCII characters. It is drawn using - lines which makes it arbitrarily scalable. I am trying to keep font data really - compact. - */ - - -#include - -/* - |01234567| - -+--------+ - 0| |____ - 1|++++++++|font - 2|++++++++| - 3|++++++++| - 4|++++++++| - 5|++++++++|____ - 6| |descent - 7| | - -+--------+ - */ - - -static const char *font_data[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, /*T*/"\11\71\100\41\45", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, /*e*/"\55\25\14\13\22\52\63\64\14", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, /*s*/"\62\22\13\64\55\15", /*t*/"\41\44\55\65\100\22\62", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - - -#if 0 - -void Fl_OpenGL_Graphics_Driver::draw(const char* str, int n, int x, int y) { - gl_draw(str, n, x, y); -} - -#else - -double Fl_OpenGL_Graphics_Driver::width(const char *str, int n) { - return size_*n*0.5; -} - -int Fl_OpenGL_Graphics_Driver::descent() { - return (int)(size_ - size_*0.8); -} - -int Fl_OpenGL_Graphics_Driver::height() { - return (int)(size_*0.8); -} - -void Fl_OpenGL_Graphics_Driver::text_extents(const char *str, int n, int& dx, int& dy, int& w, int& h) -{ - dx = 0; - dy = descent(); - w = width(str, n); - h = size_; -} - -void Fl_OpenGL_Graphics_Driver::draw(const char *str, int n, int x, int y) -{ - int i; - for (i=0; i63) { - if (cmd=='\100' && rendering) { - glEnd(); - glBegin(GL_POINTS); glVertex2f(px, py); glEnd(); - rendering = 0; - } - } else { - if (!rendering) { glBegin(GL_LINE_STRIP); rendering = 1; } - int vx = (cmd & '\70')>>3; - int vy = (cmd & '\07'); - px = 0.5+x+vx*size_*0.5/8.0; - py = 0.5+y+vy*size_/8.0-0.8*size_; - glVertex2f(px, py); - } - } - } - x += size_*0.5; - } -} - -#endif - - -// -// End of "$Id$". -// diff --git a/src/cfg_gfx/opengl_line_style.cxx b/src/cfg_gfx/opengl_line_style.cxx deleted file mode 100644 index 4bcb2f7fa..000000000 --- a/src/cfg_gfx/opengl_line_style.cxx +++ /dev/null @@ -1,70 +0,0 @@ -// -// "$Id$" -// -// Line style code 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_LINE_STYLE_CXX -#define FL_CFG_GFX_OPENGL_LINE_STYLE_CXX - -/** - \file opengl_line_style.cxx - \brief Line style drawing utility hiding different platforms. -*/ - -#include "opengl.H" -#include - -extern int fl_line_width_; - -// OpenGL implementation does not support custom patterns -// OpenGL implementation does not support cap and join types - -void Fl_OpenGL_Graphics_Driver::line_style(int style, int width, char* dashes) { - - // save line width in global variable for X11 clipping - // FIXME: what does this code do? - if (width == 0) fl_line_width_ = 1; - else fl_line_width_ = width>0 ? width : -width; - - if (width<1) width = 1; - - if (style==FL_SOLID) { - glLineStipple(1, 0xFFFF); - glDisable(GL_LINE_STIPPLE); - } else { - switch (style) { - case FL_DASH: - glLineStipple(width, 0x0F0F); // ....****....**** - break; - case FL_DOT: - glLineStipple(width, 0x5555); // .*.*.*.*.*.*.*.* - break; - case FL_DASHDOT: - glLineStipple(width, 0x2727); // ..*..***..*..*** - break; - case FL_DASHDOTDOT: - glLineStipple(width, 0x5757); // .*.*.***.*.*.*** - break; - } - glEnable(GL_LINE_STIPPLE); - } -} - -#endif // FL_CFG_GFX_OPENGL_LINE_STYLE_CXX - -// -// End of "$Id$". -// diff --git a/src/cfg_gfx/opengl_rect.cxx b/src/cfg_gfx/opengl_rect.cxx deleted file mode 100644 index b1617fcd3..000000000 --- a/src/cfg_gfx/opengl_rect.cxx +++ /dev/null @@ -1,209 +0,0 @@ -// -// "$Id$" -// -// Rectangle 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_RECT_CXX -#define FL_CFG_GFX_OPENGL_RECT_CXX - - -/** - \file quartz_rect.cxx - \brief OpenGL specific line and polygon drawing with integer coordinates. - */ - -#include -#include "opengl.H" - -// --- line and polygon drawing with integer coordinates - -void Fl_OpenGL_Graphics_Driver::point(int x, int y) { - glBegin(GL_POINTS); - glVertex2i(x, y); - glEnd(); -} - -void Fl_OpenGL_Graphics_Driver::rect(int x, int y, int w, int h) { - glBegin(GL_LINE_LOOP); - glVertex2i(x, y); - glVertex2i(x+w, y); - glVertex2i(x+w, y+h); - glVertex2i(x, y+h); - glEnd(); -} - -void Fl_OpenGL_Graphics_Driver::rectf(int x, int y, int w, int h) { - if (w<=0 || h<=0) return; - // OpenGL has the natural origin at the bottom left. Drawing in FLTK - // coordinates requires that we shift the rectangle one pixel up. - glBegin(GL_POLYGON); - glVertex2i(x, y-1); - glVertex2i(x+w, y-1); - glVertex2i(x+w, y+h-1); - glVertex2i(x, y+h-1); - glEnd(); -} - -void Fl_OpenGL_Graphics_Driver::line(int x, int y, int x1, int y1) { - glBegin(GL_LINE_STRIP); - glVertex2i(x, y); - glVertex2i(x1, y1); - glEnd(); - point(x1, y1); -} - -void Fl_OpenGL_Graphics_Driver::line(int x, int y, int x1, int y1, int x2, int y2) { - glBegin(GL_LINE_STRIP); - glVertex2i(x, y); - glVertex2i(x1, y1); - glVertex2i(x2, y2); - glEnd(); - point(x2, y2); -} - -void Fl_OpenGL_Graphics_Driver::xyline(int x, int y, int x1) { - glBegin(GL_LINE_STRIP); - glVertex2i(x, y); - glVertex2i(x1, y); - glEnd(); - point(x1, y); -} - -void Fl_OpenGL_Graphics_Driver::xyline(int x, int y, int x1, int y2) { - glBegin(GL_LINE_STRIP); - glVertex2i(x, y); - glVertex2i(x1, y); - glVertex2i(x1, y2); - glEnd(); - point(x1, y2); -} - -void Fl_OpenGL_Graphics_Driver::xyline(int x, int y, int x1, int y2, int x3) { - glBegin(GL_LINE_STRIP); - glVertex2i(x, y); - glVertex2i(x1, y); - glVertex2i(x1, y2); - glVertex2i(x3, y2); - glEnd(); - point(x3, y2); -} - -void Fl_OpenGL_Graphics_Driver::yxline(int x, int y, int y1) { - glBegin(GL_LINE_STRIP); - glVertex2i(x, y); - glVertex2i(x, y1); - glEnd(); - point(x, y1); -} - -void Fl_OpenGL_Graphics_Driver::yxline(int x, int y, int y1, int x2) { - glBegin(GL_LINE_STRIP); - glVertex2i(x, y); - glVertex2i(x, y1); - glVertex2i(x2, y1); - glEnd(); - point(x2, y1); -} - -void Fl_OpenGL_Graphics_Driver::yxline(int x, int y, int y1, int x2, int y3) { - glBegin(GL_LINE_STRIP); - glVertex2i(x, y); - glVertex2i(x, y1); - glVertex2i(x2, y1); - glVertex2i(x2, y3); - glEnd(); - point(x2, y3); -} - -void Fl_OpenGL_Graphics_Driver::loop(int x0, int y0, int x1, int y1, int x2, int y2) { - glBegin(GL_LINE_LOOP); - glVertex2i(x0, y0); - glVertex2i(x1, y1); - glVertex2i(x2, y2); - glEnd(); -} - -void Fl_OpenGL_Graphics_Driver::loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) { - glBegin(GL_LINE_LOOP); - glVertex2i(x0, y0); - glVertex2i(x1, y1); - glVertex2i(x2, y2); - glVertex2i(x3, y3); - glEnd(); -} - -void Fl_OpenGL_Graphics_Driver::polygon(int x0, int y0, int x1, int y1, int x2, int y2) { - glBegin(GL_POLYGON); - glVertex2i(x0, y0); - glVertex2i(x1, y1); - glVertex2i(x2, y2); - glEnd(); -} - -void Fl_OpenGL_Graphics_Driver::polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) { - glBegin(GL_POLYGON); - glVertex2i(x0, y0); - glVertex2i(x1, y1); - glVertex2i(x2, y2); - glVertex2i(x3, y3); - glEnd(); -} - -void Fl_OpenGL_Graphics_Driver::push_clip(int x, int y, int w, int h) { - // TODO: implement OpenGL clipping - if (rstackptr < region_stack_max) rstack[++rstackptr] = 0L; - else Fl::warning("Fl_OpenGL_Graphics_Driver::push_clip: clip stack overflow!\n"); -} - -int Fl_OpenGL_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H) { - // TODO: implement OpenGL clipping - X = x; Y = y; W = w, H = h; - return 0; -} - -int Fl_OpenGL_Graphics_Driver::not_clipped(int x, int y, int w, int h) { - // TODO: implement OpenGL clipping - return 1; -} - -void Fl_OpenGL_Graphics_Driver::push_no_clip() { - // TODO: implement OpenGL clipping - if (rstackptr < region_stack_max) rstack[++rstackptr] = 0; - else Fl::warning("Fl_OpenGL_Graphics_Driver::push_no_clip: clip stack overflow!\n"); - restore_clip(); -} - -void Fl_OpenGL_Graphics_Driver::pop_clip() { - // TODO: implement OpenGL clipping - if (rstackptr > 0) { - rstackptr--; - } else Fl::warning("Fl_OpenGL_Graphics_Driver::pop_clip: clip stack underflow!\n"); - restore_clip(); -} - -void Fl_OpenGL_Graphics_Driver::restore_clip() { - // TODO: implement OpenGL clipping - fl_clip_state_number++; -} - -const char *Fl_OpenGL_Graphics_Driver::class_id = "Fl_OpenGL_Graphics_Driver"; - - -#endif // FL_CFG_GFX_OPENGL_RECT_CXX - -// -// End of "$Id$". -// diff --git a/src/cfg_gfx/opengl_vertex.cxx b/src/cfg_gfx/opengl_vertex.cxx deleted file mode 100644 index 46bc77fa8..000000000 --- a/src/cfg_gfx/opengl_vertex.cxx +++ /dev/null @@ -1,142 +0,0 @@ -// -// "$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 -#include -#include - - -// 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/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.h b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.h new file mode 100644 index 000000000..48944fcb8 --- /dev/null +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.h @@ -0,0 +1,101 @@ +// +// "$Id$" +// +// Definition of OpenGL graphics driver +// 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 +// + +/** + \file opengl.H + \brief Definition of OpenGL graphics driver. + */ + +#ifndef FL_CFG_GFX_OPENGL_H +#define FL_CFG_GFX_OPENGL_H + +#include + + +/** + \brief OpenGL specific graphics class. + */ +class FL_EXPORT Fl_OpenGL_Graphics_Driver : public Fl_Graphics_Driver { +public: + static const char *class_id; + const char *class_name() {return class_id;}; + // --- line and polygon drawing with integer coordinates + void point(int x, int y); + void rect(int x, int y, int w, int h); + void rectf(int x, int y, int w, int h); + void line(int x, int y, int x1, int y1); + void line(int x, int y, int x1, int y1, int x2, int y2); + void xyline(int x, int y, int x1); + void xyline(int x, int y, int x1, int y2); + void xyline(int x, int y, int x1, int y2, int x3); + void yxline(int x, int y, int y1); + void yxline(int x, int y, int y1, int x2); + void yxline(int x, int y, int y1, int x2, int y3); + void loop(int x0, int y0, int x1, int y1, int x2, int y2); + void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3); + void polygon(int x0, int y0, int x1, int y1, int x2, int y2); + void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3); + void push_clip(int x, int y, int w, int h); + int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H); + int not_clipped(int x, int y, int w, int h); + void push_no_clip(); + 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 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); + // --- implementation is in src/fl_arc.cxx which includes src/cfg_gfx/xxx_arc.cxx if needed + // using void Fl_Graphics_Driver::arc(double x, double y, double r, double start, double end); + // --- implementation is in src/fl_arci.cxx which includes src/cfg_gfx/xxx_arci.cxx + void arc(int x, int y, int w, int h, double a1, double a2); + void pie(int x, int y, int w, int h, double a1, double a2); + // --- implementation is in src/fl_line_style.cxx which includes src/cfg_gfx/xxx_line_style.cxx + void line_style(int style, int width=0, char* dashes=0); + // --- implementation is in src/fl_color.cxx which includes src/cfg_gfx/xxx_color.cxx + void color(Fl_Color c); + Fl_Color color() { return color_; } + void color(uchar r, uchar g, uchar b); + // --- implementation is in src/fl_font.cxx which includes src/cfg_gfx/xxx_font.cxx + void draw(const char *str, int n, int x, int y); + double width(const char *str, int n); + void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); + int height(); + int descent(); +}; + + +#endif // FL_CFG_GFX_OPENGL_H + +// +// End of "$Id$". +// diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx new file mode 100644 index 000000000..15ec4cf36 --- /dev/null +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx @@ -0,0 +1,70 @@ +// +// "$Id$" +// +// Arc (integer) drawing functions for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2010 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_ARCI_CXX +#define FL_CFG_GFX_OPENGL_ARCI_CXX + +/** + \file opengl_arci.cxx + \brief Utility functions for drawing circles using integers +*/ + +#include +#define _USE_MATH_DEFINES +#include + +void Fl_OpenGL_Graphics_Driver::arc(int x,int y,int w,int h,double a1,double a2) { + if (w <= 0 || h <= 0) return; + while (a2 + +// Implementation of fl_color(i), fl_color(r,g,b). + +void Fl_OpenGL_Graphics_Driver::color(Fl_Color i) { + // FIXME: do we need the code below? + /* +#if HAVE_GL_OVERLAY +#if defined(WIN32) + if (fl_overlay && fl_overlay_depth) { + if (fl_overlay_depth < 8) { + // only black & white produce the expected colors. This could + // be improved by fixing the colormap set in Fl_Gl_Overlay.cxx + int size = 1<= size-2) glIndexi(size-1); + else glIndexi(i); + } else { + glIndexi(i ? i : FL_GRAY_RAMP); + } + return; + } +#else + if (fl_overlay) {glIndexi(int(fl_xpixel(i))); return;} +#endif +#endif +*/ + if (i & 0xffffff00) { + unsigned rgb = (unsigned)i; + fl_color((uchar)(rgb >> 24), (uchar)(rgb >> 16), (uchar)(rgb >> 8)); + } else { + Fl_Graphics_Driver::color(i); + uchar red, green, blue; + Fl::get_color(i, red, green, blue); + glColor3ub(red, green, blue); + } +} + +void Fl_OpenGL_Graphics_Driver::color(uchar r,uchar g,uchar b) { + Fl_Graphics_Driver::color( fl_rgb_color(r, g, b) ); + glColor3ub(r,g,b); +} + +// +// End of "$Id$". +// diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx new file mode 100644 index 000000000..24a5fe51b --- /dev/null +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx @@ -0,0 +1,151 @@ +// +// "$Id$" +// +// Standard X11 font selection code 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 +// + +/* + This module implements a lowest-common-denominator font for OpenGL. + It will always work, even if the main graphics library does not support + rendering text into a texture buffer. + + The font is limited to a single face and ASCII characters. It is drawn using + lines which makes it arbitrarily scalable. I am trying to keep font data really + compact. + */ + + +#include + +// FIXME: check out FreeGlut: +// FIXME: implement font-to-RGBA in the main graphics driver + +#if 1 + +/* + |01234567| + -+--------+ + 0| |____ + 1|++++++++|font + 2|++++++++| + 3|++++++++| + 4|++++++++| + 5|++++++++|____ + 6| |descent + 7| | + -+--------+ + */ + + +static const char *font_data[128] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, /*T*/"\11\71\100\41\45", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, /*e*/"\55\25\14\13\22\52\63\64\14", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, /*s*/"\62\22\13\64\55\15", /*t*/"\41\44\55\65\100\22\62", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + + +double Fl_OpenGL_Graphics_Driver::width(const char *str, int n) { + return size_*n*0.5; +} + +int Fl_OpenGL_Graphics_Driver::descent() { + return (int)(size_ - size_*0.8); +} + +int Fl_OpenGL_Graphics_Driver::height() { + return (int)(size_*0.8); +} + +void Fl_OpenGL_Graphics_Driver::text_extents(const char *str, int n, int& dx, int& dy, int& w, int& h) +{ + dx = 0; + dy = descent(); + w = width(str, n); + h = size_; +} + +void Fl_OpenGL_Graphics_Driver::draw(const char *str, int n, int x, int y) +{ + int i; + for (i=0; i63) { + if (cmd=='\100' && rendering) { + glEnd(); + glBegin(GL_POINTS); glVertex2f(px, py); glEnd(); + rendering = 0; + } + } else { + if (!rendering) { glBegin(GL_LINE_STRIP); rendering = 1; } + int vx = (cmd & '\70')>>3; + int vy = (cmd & '\07'); + px = 0.5+x+vx*size_*0.5/8.0; + py = 0.5+y+vy*size_/8.0-0.8*size_; + glVertex2f(px, py); + } + } + } + x += size_*0.5; + } +} + +#elif 0 + +/* +extern FL_EXPORT Fl_Glut_StrokeFont glutStrokeRoman; +extern FL_EXPORT Fl_Glut_StrokeFont glutStrokeMonoRoman; +# define GLUT_STROKE_ROMAN (&glutStrokeRoman) +# define GLUT_STROKE_MONO_ROMAN (&glutStrokeMonoRoman) + +FL_EXPORT void glutStrokeCharacter(void *font, int character); +FL_EXPORT GLfloat glutStrokeHeight(void *font); +FL_EXPORT int glutStrokeLength(void *font, const unsigned char *string); +FL_EXPORT void glutStrokeString(void *font, const unsigned char *string); +FL_EXPORT int glutStrokeWidth(void *font, int character); +*/ + +#else + +void Fl_OpenGL_Graphics_Driver::draw(const char* str, int n, int x, int y) { + gl_draw(str, n, x, y); +} + +#endif + + +// +// End of "$Id$". +// diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx new file mode 100644 index 000000000..c9606f95d --- /dev/null +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx @@ -0,0 +1,70 @@ +// +// "$Id$" +// +// Line style code 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_LINE_STYLE_CXX +#define FL_CFG_GFX_OPENGL_LINE_STYLE_CXX + +/** + \file opengl_line_style.cxx + \brief Line style drawing utility hiding different platforms. +*/ + +#include "Fl_OpenGL_Graphics_Driver.h" +#include + +extern int fl_line_width_; + +// OpenGL implementation does not support custom patterns +// OpenGL implementation does not support cap and join types + +void Fl_OpenGL_Graphics_Driver::line_style(int style, int width, char* dashes) { + + // save line width in global variable for X11 clipping + // FIXME: what does this code do? + if (width == 0) fl_line_width_ = 1; + else fl_line_width_ = width>0 ? width : -width; + + if (width<1) width = 1; + + if (style==FL_SOLID) { + glLineStipple(1, 0xFFFF); + glDisable(GL_LINE_STIPPLE); + } else { + switch (style) { + case FL_DASH: + glLineStipple(width, 0x0F0F); // ....****....**** + break; + case FL_DOT: + glLineStipple(width, 0x5555); // .*.*.*.*.*.*.*.* + break; + case FL_DASHDOT: + glLineStipple(width, 0x2727); // ..*..***..*..*** + break; + case FL_DASHDOTDOT: + glLineStipple(width, 0x5757); // .*.*.***.*.*.*** + break; + } + glEnable(GL_LINE_STIPPLE); + } +} + +#endif // FL_CFG_GFX_OPENGL_LINE_STYLE_CXX + +// +// End of "$Id$". +// diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx new file mode 100644 index 000000000..1ea30a4d7 --- /dev/null +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx @@ -0,0 +1,209 @@ +// +// "$Id$" +// +// Rectangle 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_RECT_CXX +#define FL_CFG_GFX_OPENGL_RECT_CXX + + +/** + \file quartz_rect.cxx + \brief OpenGL specific line and polygon drawing with integer coordinates. + */ + +#include +#include "Fl_OpenGL_Graphics_Driver.h" + +// --- line and polygon drawing with integer coordinates + +void Fl_OpenGL_Graphics_Driver::point(int x, int y) { + glBegin(GL_POINTS); + glVertex2i(x, y); + glEnd(); +} + +void Fl_OpenGL_Graphics_Driver::rect(int x, int y, int w, int h) { + glBegin(GL_LINE_LOOP); + glVertex2i(x, y); + glVertex2i(x+w, y); + glVertex2i(x+w, y+h); + glVertex2i(x, y+h); + glEnd(); +} + +void Fl_OpenGL_Graphics_Driver::rectf(int x, int y, int w, int h) { + if (w<=0 || h<=0) return; + // OpenGL has the natural origin at the bottom left. Drawing in FLTK + // coordinates requires that we shift the rectangle one pixel up. + glBegin(GL_POLYGON); + glVertex2i(x, y-1); + glVertex2i(x+w, y-1); + glVertex2i(x+w, y+h-1); + glVertex2i(x, y+h-1); + glEnd(); +} + +void Fl_OpenGL_Graphics_Driver::line(int x, int y, int x1, int y1) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x1, y1); + glEnd(); + point(x1, y1); +} + +void Fl_OpenGL_Graphics_Driver::line(int x, int y, int x1, int y1, int x2, int y2) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x1, y1); + glVertex2i(x2, y2); + glEnd(); + point(x2, y2); +} + +void Fl_OpenGL_Graphics_Driver::xyline(int x, int y, int x1) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x1, y); + glEnd(); + point(x1, y); +} + +void Fl_OpenGL_Graphics_Driver::xyline(int x, int y, int x1, int y2) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x1, y); + glVertex2i(x1, y2); + glEnd(); + point(x1, y2); +} + +void Fl_OpenGL_Graphics_Driver::xyline(int x, int y, int x1, int y2, int x3) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x1, y); + glVertex2i(x1, y2); + glVertex2i(x3, y2); + glEnd(); + point(x3, y2); +} + +void Fl_OpenGL_Graphics_Driver::yxline(int x, int y, int y1) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x, y1); + glEnd(); + point(x, y1); +} + +void Fl_OpenGL_Graphics_Driver::yxline(int x, int y, int y1, int x2) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x, y1); + glVertex2i(x2, y1); + glEnd(); + point(x2, y1); +} + +void Fl_OpenGL_Graphics_Driver::yxline(int x, int y, int y1, int x2, int y3) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x, y1); + glVertex2i(x2, y1); + glVertex2i(x2, y3); + glEnd(); + point(x2, y3); +} + +void Fl_OpenGL_Graphics_Driver::loop(int x0, int y0, int x1, int y1, int x2, int y2) { + glBegin(GL_LINE_LOOP); + glVertex2i(x0, y0); + glVertex2i(x1, y1); + glVertex2i(x2, y2); + glEnd(); +} + +void Fl_OpenGL_Graphics_Driver::loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) { + glBegin(GL_LINE_LOOP); + glVertex2i(x0, y0); + glVertex2i(x1, y1); + glVertex2i(x2, y2); + glVertex2i(x3, y3); + glEnd(); +} + +void Fl_OpenGL_Graphics_Driver::polygon(int x0, int y0, int x1, int y1, int x2, int y2) { + glBegin(GL_POLYGON); + glVertex2i(x0, y0); + glVertex2i(x1, y1); + glVertex2i(x2, y2); + glEnd(); +} + +void Fl_OpenGL_Graphics_Driver::polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) { + glBegin(GL_POLYGON); + glVertex2i(x0, y0); + glVertex2i(x1, y1); + glVertex2i(x2, y2); + glVertex2i(x3, y3); + glEnd(); +} + +void Fl_OpenGL_Graphics_Driver::push_clip(int x, int y, int w, int h) { + // TODO: implement OpenGL clipping + if (rstackptr < region_stack_max) rstack[++rstackptr] = 0L; + else Fl::warning("Fl_OpenGL_Graphics_Driver::push_clip: clip stack overflow!\n"); +} + +int Fl_OpenGL_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H) { + // TODO: implement OpenGL clipping + X = x; Y = y; W = w, H = h; + return 0; +} + +int Fl_OpenGL_Graphics_Driver::not_clipped(int x, int y, int w, int h) { + // TODO: implement OpenGL clipping + return 1; +} + +void Fl_OpenGL_Graphics_Driver::push_no_clip() { + // TODO: implement OpenGL clipping + if (rstackptr < region_stack_max) rstack[++rstackptr] = 0; + else Fl::warning("Fl_OpenGL_Graphics_Driver::push_no_clip: clip stack overflow!\n"); + restore_clip(); +} + +void Fl_OpenGL_Graphics_Driver::pop_clip() { + // TODO: implement OpenGL clipping + if (rstackptr > 0) { + rstackptr--; + } else Fl::warning("Fl_OpenGL_Graphics_Driver::pop_clip: clip stack underflow!\n"); + restore_clip(); +} + +void Fl_OpenGL_Graphics_Driver::restore_clip() { + // TODO: implement OpenGL clipping + fl_clip_state_number++; +} + +const char *Fl_OpenGL_Graphics_Driver::class_id = "Fl_OpenGL_Graphics_Driver"; + + +#endif // FL_CFG_GFX_OPENGL_RECT_CXX + +// +// End of "$Id$". +// diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx new file mode 100644 index 000000000..1dd091f0d --- /dev/null +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx @@ -0,0 +1,142 @@ +// +// "$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 "Fl_OpenGL_Graphics_Driver.h" + +#include +#include +#include + + +// 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$". +// -- cgit v1.2.3