1998-10-20 00:46:58 +04:00
|
|
|
//
|
2001-03-14 20:20:02 +03:00
|
|
|
// "$Id: gl_draw.cxx,v 1.7.2.5 2001/03/14 17:20:02 spitzak Exp $"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// OpenGL drawing support routines for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2001-01-22 18:13:41 +03:00
|
|
|
// Copyright 1998-2001 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2000-06-06 01:21:24 +04:00
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// Functions from <FL/gl.h>
|
|
|
|
// See also Fl_Gl_Window and gl_start.C
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#if HAVE_GL
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/gl.h>
|
|
|
|
#include <FL/x.H>
|
1998-12-02 18:51:38 +03:00
|
|
|
#include <FL/fl_draw.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include "Fl_Gl_Choice.H"
|
|
|
|
#include "Fl_Font.H"
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
int gl_height() {return fl_height();}
|
|
|
|
int gl_descent() {return fl_descent();}
|
|
|
|
double gl_width(const char* s) {return fl_width(s);}
|
|
|
|
double gl_width(const char* s, int n) {return fl_width(s,n);}
|
|
|
|
double gl_width(uchar c) {return fl_width(c);}
|
|
|
|
|
2001-03-14 20:20:02 +03:00
|
|
|
void gl_font(int fontid, int size) {
|
|
|
|
fl_font(fontid, size);
|
1998-12-02 18:51:38 +03:00
|
|
|
if (!fl_fontsize->listbase) {
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifdef WIN32
|
1998-12-02 18:51:38 +03:00
|
|
|
int base = fl_fontsize->metr.tmFirstChar;
|
|
|
|
int size = fl_fontsize->metr.tmLastChar-base+1;
|
|
|
|
HFONT oldFid = (HFONT)SelectObject(fl_gc, fl_fontsize->fid);
|
1998-12-03 00:15:19 +03:00
|
|
|
fl_fontsize->listbase = glGenLists(256);
|
1998-12-02 18:51:38 +03:00
|
|
|
wglUseFontBitmaps(fl_gc, base, size, fl_fontsize->listbase+base);
|
1998-10-06 22:21:25 +04:00
|
|
|
SelectObject(fl_gc, oldFid);
|
|
|
|
#else
|
1998-12-02 18:51:38 +03:00
|
|
|
int base = fl_xfont->min_char_or_byte2;
|
|
|
|
int size = fl_xfont->max_char_or_byte2-base+1;
|
1998-12-03 00:15:19 +03:00
|
|
|
fl_fontsize->listbase = glGenLists(256);
|
1998-12-02 18:51:38 +03:00
|
|
|
glXUseXFont(fl_xfont->fid, base, size, fl_fontsize->listbase+base);
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
1998-12-02 18:51:38 +03:00
|
|
|
}
|
2001-03-14 20:20:02 +03:00
|
|
|
glListBase(fl_fontsize->listbase);
|
|
|
|
}
|
1998-12-03 00:15:19 +03:00
|
|
|
|
2001-03-14 20:20:02 +03:00
|
|
|
void gl_draw(const char* str, int n) {
|
|
|
|
glCallLists(n, GL_UNSIGNED_BYTE, str);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void gl_draw(const char* str, int n, int x, int y) {
|
|
|
|
glRasterPos2i(x, y);
|
|
|
|
gl_draw(str, n);
|
|
|
|
}
|
|
|
|
|
1998-11-24 16:18:34 +03:00
|
|
|
void gl_draw(const char* str, int n, float x, float y) {
|
|
|
|
glRasterPos2f(x, y);
|
|
|
|
gl_draw(str, n);
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
void gl_draw(const char* str) {
|
|
|
|
gl_draw(str, strlen(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_draw(const char* str, int x, int y) {
|
|
|
|
gl_draw(str, strlen(str), x, y);
|
|
|
|
}
|
|
|
|
|
1998-11-24 16:18:34 +03:00
|
|
|
void gl_draw(const char* str, float x, float y) {
|
|
|
|
gl_draw(str, strlen(str), x, y);
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
static void gl_draw_invert(const char* str, int n, int x, int y) {
|
|
|
|
glRasterPos2i(x, -y);
|
|
|
|
gl_draw(str, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_draw(
|
|
|
|
const char* str, // the (multi-line) string
|
|
|
|
int x, int y, int w, int h, // bounding box
|
|
|
|
Fl_Align align) {
|
|
|
|
fl_draw(str, x, -y-h, w, h, align, gl_draw_invert);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_measure(const char* str, int& x, int& y) {fl_measure(str,x,y);}
|
|
|
|
|
|
|
|
void gl_rect(int x, int y, int w, int h) {
|
|
|
|
if (w < 0) {w = -w; x = x-w;}
|
|
|
|
if (h < 0) {h = -h; y = y-h;}
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glVertex2i(x+w-1, y+h-1);
|
|
|
|
glVertex2i(x+w-1, y);
|
|
|
|
glVertex2i(x, y);
|
|
|
|
glVertex2i(x, y+h-1);
|
|
|
|
glVertex2i(x+w, y+h-1);
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_GL_OVERLAY
|
|
|
|
extern uchar fl_overlay;
|
2000-03-24 11:42:03 +03:00
|
|
|
extern int fl_overlay_depth;
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void gl_color(Fl_Color i) {
|
|
|
|
#if HAVE_GL_OVERLAY
|
|
|
|
#ifdef WIN32
|
2000-03-24 11:42:03 +03:00
|
|
|
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<<fl_overlay_depth;
|
|
|
|
if (!i) glIndexi(size-2);
|
|
|
|
else if (i >= size-2) glIndexi(size-1);
|
|
|
|
else glIndexi(i);
|
|
|
|
} else {
|
|
|
|
glIndexi(i ? i : FL_GRAY_RAMP);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
#else
|
|
|
|
if (fl_overlay) {glIndexi(int(fl_xpixel(i))); return;}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
uchar red, green, blue;
|
|
|
|
Fl::get_color(i, red, green, blue);
|
|
|
|
glColor3ub(red, green, blue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_draw_image(const uchar* b, int x, int y, int w, int h, int d, int ld) {
|
|
|
|
if (!ld) ld = w*d;
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, ld/d);
|
|
|
|
glRasterPos2i(x,y);
|
|
|
|
glDrawPixels(w,h,d<4?GL_RGB:GL_RGBA,GL_UNSIGNED_BYTE,(const ulong*)b);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2001-03-14 20:20:02 +03:00
|
|
|
// End of "$Id: gl_draw.cxx,v 1.7.2.5 2001/03/14 17:20:02 spitzak Exp $".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|