Starting to cut out individual graphics function, so that multiple drivers can coexist (cfg_gfx). Found the missing pixels in the OpenGL gfx driver.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11012 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher 2016-01-20 00:11:43 +00:00
parent 9872f74053
commit bd78fa1c48
5 changed files with 75 additions and 18 deletions

View File

@ -285,7 +285,7 @@ protected:
/** \brief see fl_color(uchar r, uchar g, uchar b). */
virtual void color(uchar r, uchar g, uchar b) {}
/** \brief see fl_point(int x, int y). */
virtual void point(int x, int y);
virtual void point(int x, int y) = 0;
/** \brief see fl_loop(int x0, int y0, int x1, int y1, int x2, int y2). */
virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2);
/** \brief see fl_loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3). */
@ -474,6 +474,7 @@ public:
static Fl_Offscreen create_offscreen_with_alpha(int w, int h);
#endif
void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
virtual void point(int x, int y);
};
#elif defined(WIN32) || defined(FL_DOXYGEN)
@ -509,6 +510,7 @@ public:
void copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int srcy);
#endif
void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
virtual void point(int x, int y);
};
/**
@ -529,6 +531,8 @@ public:
# pragma message "FL_PORTING: define a native graphics driver Fl_xxx_Graphics_Driver"
class FL_EXPORT Fl_XXX_Graphics_Driver : public Fl_Graphics_Driver {
protected:
virtual void point(int x, int y) { }
};
#else // X11
@ -564,6 +568,7 @@ public:
#if ! defined(FL_DOXYGEN)
void copy_offscreen_with_alpha(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
#endif
virtual void point(int x, int y);
};
#endif

View File

@ -67,10 +67,14 @@ public:
gl_color(c);
}
void rectf(int x, int y, int w, int h) {
if (w<0) { x = x+w; w = -w; }
if (h<0) { y = y+h; h = -h; }
// 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);
glVertex2i(x+w-1, y);
glVertex2i(x+w-1, y+h-1);
glVertex2i(x, y-1);
glVertex2i(x+w, y-1);
glVertex2i(x+w, y+h-1);
glVertex2i(x, y+h-1);
glEnd();
}
@ -79,12 +83,14 @@ public:
glVertex2i(x, y);
glVertex2i(x1, y1);
glEnd();
point(x1, y1);
}
void xyline(int x, int y, int x1) {
glBegin(GL_LINE_STRIP);
glVertex2i(x, y);
glVertex2i(x1, y);
glEnd();
point(x1, y);
}
void xyline(int x, int y, int x1, int y2) {
glBegin(GL_LINE_STRIP);
@ -92,6 +98,7 @@ public:
glVertex2i(x1, y);
glVertex2i(x1, y2);
glEnd();
point(x1, y2);
}
void xyline(int x, int y, int x1, int y2, int x3) {
glBegin(GL_LINE_STRIP);
@ -100,12 +107,14 @@ public:
glVertex2i(x1, y2);
glVertex2i(x3, y2);
glEnd();
point(x3, y2);
}
void yxline(int x, int y, int y1) {
glBegin(GL_LINE_STRIP);
glVertex2i(x, y);
glVertex2i(x, y1);
glEnd();
point(x, y1);
}
void yxline(int x, int y, int y1, int x2) {
glBegin(GL_LINE_STRIP);
@ -113,6 +122,7 @@ public:
glVertex2i(x, y1);
glVertex2i(x2, y1);
glEnd();
point(x2, y1);
}
void yxline(int x, int y, int y1, int x2, int y3) {
glBegin(GL_LINE_STRIP);
@ -121,6 +131,12 @@ public:
glVertex2i(x2, y1);
glVertex2i(x2, y3);
glEnd();
point(x2, y3);
}
virtual void point(int x, int y) {
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd();
}
/*
@ -682,7 +698,7 @@ void Fl_Gl_Window::draw() {
glLoadIdentity();
glOrtho(-0.5, w()-0.5, h()-0.5, -0.5, -1, 1);
// glOrtho(0, w(), h(), 0, -1, 1);
glLineWidth(pixels_per_unit());
glLineWidth(pixels_per_unit()); // should be 1 or 2 (2 if highres OpenGL)
Fl_Window::draw();

View File

@ -27,6 +27,7 @@
// that minimal update works.
#include <config.h>
#include "config_lib.h"
#include <FL/Fl.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Printer.H>
@ -546,20 +547,54 @@ void Fl_Graphics_Driver::polygon(int x, int y, int x1, int y1, int x2, int y2, i
#endif
}
void Fl_Graphics_Driver::point(int x, int y) {
#if defined(USE_X11)
XDrawPoint(fl_display, fl_window, fl_gc, clip_x(x), clip_x(y));
#elif defined(WIN32)
SetPixel(fl_gc, x, y, fl_RGB());
#elif defined(__APPLE_QUARTZ__)
/*
Matt: I wrote individual methods for every class. They are virtual, so the
correct function is called, depending on the active driver.
By having individual methods, multiple drivers can co-exist, for example
Quartz, OpenGL, and a printer driver.
The individual implementations should eventually go into files that are
included into this file, based on the configuration, for example:
src/cfg_gfx/quartz_rect.cxx
src/cfg_gfx/gdi_rect.cxx
src/cfg_gfx/xlib_rect.cxx
Porting the graphics system to a new platform then requires to copy one of
these files and implement the virtual functions. point() is the only function
that *must* be implemented when deriving from 'Fl_Minimal_Graphics_Driver"
(which is still to be written)
*/
#ifdef FL_CFG_GFX_QUARTZ
void Fl_Quartz_Graphics_Driver::point(int x, int y) {
CGContextFillRect(fl_gc, CGRectMake(x - 0.5, y - 0.5, 1, 1) );
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: implement point"
#else
# error unsupported platform
#endif
}
#endif
#ifdef FL_CFG_GFX_GDI
void Fl_GDI_Graphics_Driver::point(int x, int y) {
SetPixel(fl_gc, x, y, fl_RGB());
}
#endif
#ifdef FL_CFG_GFX_XLIB
void Fl_Xlib_Graphics_Driver::point(int x, int y) {
XDrawPoint(fl_display, fl_window, fl_gc, clip_x(x), clip_x(y));
}
#endif
////////////////////////////////////////////////////////////////
#if defined(WIN32)

View File

@ -267,7 +267,8 @@ static void gl_draw_invert(const char* str, int n, int x, int y) {
void gl_draw(
const char* str, // the (multi-line) string
int x, int y, int w, int h, // bounding box
Fl_Align align) {
Fl_Align align)
{
fl_draw(str, x, -y-h, w, h, align, gl_draw_invert, NULL, 0);
}

View File

@ -177,7 +177,7 @@ void print_cb(Fl_Widget *w, void *data)
// end of printing demo
int main(int argc, char **argv) {
Fl::use_high_res_GL(1);
//Fl::use_high_res_GL(1);
makeform(argv[0]);
// added to demo printing
form->begin();