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
This commit is contained in:
Matthias Melcher 2016-01-23 20:22:50 +00:00
parent 1bb1e0f42e
commit de12eddb59
7 changed files with 225 additions and 67 deletions

View File

@ -179,12 +179,6 @@ protected:
friend void fl_color(Fl_Color c);
friend void fl_color(uchar r, uchar g, uchar b);
friend void fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
friend void fl_arc(double x, double y, double r, double start, double end);
friend void fl_arc(int x, int y, int w, int h, double a1, double a2);
friend void fl_pie(int x, int y, int w, int h, double a1, double a2);
friend void fl_scale(double x, double y);
friend void fl_scale(double x);
friend void fl_translate(double x, double y);
friend void fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L);
friend void fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L);
@ -219,19 +213,7 @@ protected:
virtual void color(uchar r, uchar g, uchar b) {}
/** \brief see fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3). */
virtual void curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
/** \brief see fl_arc(double x, double y, double r, double start, double end). */
virtual void arc(double x, double y, double r, double start, double end);
/** \brief see fl_arc(int x, int y, int w, int h, double a1, double a2). */
virtual void arc(int x, int y, int w, int h, double a1, double a2);
/** \brief see fl_pie(int x, int y, int w, int h, double a1, double a2). */
virtual void pie(int x, int y, int w, int h, double a1, double a2);
/** \brief see fl_scale(double x, double y). */
inline void scale(double x, double y) { mult_matrix(x,0,0,y,0,0); }
/** \brief see fl_scale(double x). */
inline void scale(double x) { mult_matrix(x,0,0,x,0,0); }
/** \brief see fl_translate(double x, double y). */
inline void translate(double x,double y) { mult_matrix(1,0,0,1,x,y); }
// Images
/** \brief see fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L). */
@ -359,6 +341,12 @@ protected:
virtual void mult_matrix(double a, double b, double c, double d, double x, double y);
friend void fl_rotate(double d);
virtual void rotate(double d);
friend void fl_scale(double x, double y);
virtual void scale(double x, double y);
friend void fl_scale(double x);
virtual void scale(double x);
friend void fl_translate(double x, double y);
virtual void translate(double x,double y);
friend void fl_begin_points();
virtual void begin_points();
friend void fl_begin_line();
@ -395,6 +383,14 @@ protected:
virtual void gap() = 0;
friend void fl_circle(double x, double y, double r);
virtual void circle(double x, double y, double r) = 0;
// --- implementation is in src/fl_arc.cxx which includes src/cfg_gfx/xxx_arc.cxx if needed
friend void fl_arc(double x, double y, double r, double start, double end);
virtual void 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
friend void fl_arc(int x, int y, int w, int h, double a1, double a2);
virtual void arc(int x, int y, int w, int h, double a1, double a2);
friend void fl_pie(int x, int y, int w, int h, double a1, double a2);
virtual void pie(int x, int y, int w, int h, double a1, double a2);
};

View File

@ -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"

View File

@ -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);
};

View File

@ -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$".
//

View File

@ -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$".
//

View File

@ -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) {

View File

@ -147,7 +147,8 @@ void makeform(const char *name) {
cube = new cube_box(23,23,344,344, 0);
if (Fl::cfg_gfx_opengl) { // try to overlay a button onto an OpenGL window
cube->begin();
/*Fl_Button *test =*/ new Fl_Button(35, 105, 100, 30, "Test");
Fl_Button *test = new Fl_Button(35, 105, 100, 30, "Test");
test->box(FL_ROUND_UP_BOX);
cube->end();
}
cube2 = new cube_box(513,23,344,344, 0);