1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// OpenGL context routines for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2010-11-29 21:18:27 +03:00
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// 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
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 23:14:55 +04:00
|
|
|
|
|
|
|
// You MUST use gl_visual() to select the default visual before doing
|
|
|
|
// show() of any windows. Mesa will crash if you try to use a visual
|
|
|
|
// not returned by glxChooseVisual.
|
|
|
|
|
|
|
|
// This does not work with Fl_Double_Window's! It will try to draw
|
|
|
|
// into the front buffer. Depending on the system this will either
|
|
|
|
// crash or do nothing (when pixmaps are being used as back buffer
|
|
|
|
// and GL is being done by hardware), work correctly (when GL is done
|
|
|
|
// with software, such as Mesa), or draw into the front buffer and
|
|
|
|
// be erased when the buffers are swapped (when double buffer hardware
|
|
|
|
// is being used)
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#if HAVE_GL
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/x.H>
|
|
|
|
#include <FL/fl_draw.H>
|
2014-10-30 12:18:45 +03:00
|
|
|
#include <FL/gl.h>
|
1998-10-06 23:14:55 +04:00
|
|
|
#include "Fl_Gl_Choice.H"
|
|
|
|
|
2001-03-14 20:20:02 +03:00
|
|
|
static GLContext context;
|
1998-10-06 23:14:55 +04:00
|
|
|
static int clip_state_number=-1;
|
|
|
|
static int pw, ph;
|
|
|
|
|
|
|
|
#ifdef WIN32
|
2001-03-14 20:20:02 +03:00
|
|
|
static Fl_Gl_Choice* gl_choice;
|
1998-10-06 23:14:55 +04:00
|
|
|
#endif
|
|
|
|
|
2001-12-18 14:00:09 +03:00
|
|
|
#ifdef __APPLE__
|
|
|
|
static Fl_Gl_Choice* gl_choice;
|
|
|
|
#endif
|
|
|
|
|
2001-11-28 23:43:44 +03:00
|
|
|
Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
|
1998-10-06 23:14:55 +04:00
|
|
|
|
2009-04-10 00:44:31 +04:00
|
|
|
/** Creates an OpenGL context */
|
1998-10-06 23:14:55 +04:00
|
|
|
void gl_start() {
|
|
|
|
if (!context) {
|
2008-10-14 03:10:43 +04:00
|
|
|
#if defined(USE_X11)
|
|
|
|
context = fl_create_gl_context(fl_visual);
|
|
|
|
#elif defined(WIN32)
|
2001-03-14 20:20:02 +03:00
|
|
|
if (!gl_choice) Fl::gl_visual(0);
|
|
|
|
context = fl_create_gl_context(Fl_Window::current(), gl_choice);
|
2004-08-25 04:20:27 +04:00
|
|
|
#elif defined(__APPLE_QUARTZ__)
|
2004-09-10 01:34:48 +04:00
|
|
|
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
|
2004-08-25 04:20:27 +04:00
|
|
|
context = fl_create_gl_context(Fl_Window::current(), gl_choice);
|
1998-10-06 23:14:55 +04:00
|
|
|
#else
|
2008-10-14 03:10:43 +04:00
|
|
|
# error Unsupported platform
|
1999-09-16 09:34:27 +04:00
|
|
|
#endif
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
1999-09-16 09:34:27 +04:00
|
|
|
fl_set_gl_context(Fl_Window::current(), context);
|
2001-11-27 20:44:08 +03:00
|
|
|
#if !defined(WIN32) && !defined(__APPLE__)
|
1998-10-06 23:14:55 +04:00
|
|
|
glXWaitX();
|
|
|
|
#endif
|
|
|
|
if (pw != Fl_Window::current()->w() || ph != Fl_Window::current()->h()) {
|
|
|
|
pw = Fl_Window::current()->w();
|
|
|
|
ph = Fl_Window::current()->h();
|
|
|
|
glLoadIdentity();
|
|
|
|
glViewport(0, 0, pw, ph);
|
|
|
|
glOrtho(0, pw, 0, ph, -1, 1);
|
|
|
|
glDrawBuffer(GL_FRONT);
|
|
|
|
}
|
2011-02-05 02:32:53 +03:00
|
|
|
if (clip_state_number != fl_graphics_driver->fl_clip_state_number) {
|
|
|
|
clip_state_number = fl_graphics_driver->fl_clip_state_number;
|
1998-10-06 23:14:55 +04:00
|
|
|
int x, y, w, h;
|
|
|
|
if (fl_clip_box(0, 0, Fl_Window::current()->w(), Fl_Window::current()->h(),
|
|
|
|
x, y, w, h)) {
|
|
|
|
fl_clip_region(XRectangleRegion(x,y,w,h));
|
|
|
|
glScissor(x, Fl_Window::current()->h()-(y+h), w, h);
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
} else {
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-10 00:44:31 +04:00
|
|
|
/** Releases an OpenGL context */
|
1998-10-06 23:14:55 +04:00
|
|
|
void gl_finish() {
|
|
|
|
glFlush();
|
2001-11-27 20:44:08 +03:00
|
|
|
#if !defined(WIN32) && !defined(__APPLE__)
|
1998-10-06 23:14:55 +04:00
|
|
|
glXWaitGL();
|
|
|
|
#endif
|
|
|
|
}
|
2008-10-14 03:10:43 +04:00
|
|
|
|
1998-10-06 23:14:55 +04:00
|
|
|
int Fl::gl_visual(int mode, int *alist) {
|
|
|
|
Fl_Gl_Choice *c = Fl_Gl_Choice::find(mode,alist);
|
|
|
|
if (!c) return 0;
|
2008-10-14 03:10:43 +04:00
|
|
|
#if defined(USE_X11)
|
|
|
|
fl_visual = c->vis;
|
|
|
|
fl_colormap = c->colormap;
|
|
|
|
#elif defined(WIN32)
|
2004-08-25 04:20:27 +04:00
|
|
|
gl_choice = c;
|
|
|
|
#elif defined(__APPLE_QUARTZ__)
|
2004-09-10 01:34:48 +04:00
|
|
|
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
|
2001-12-18 14:00:09 +03:00
|
|
|
gl_choice = c;
|
2001-03-14 20:20:02 +03:00
|
|
|
#else
|
2008-10-14 03:10:43 +04:00
|
|
|
# error Unsupported platform
|
1998-10-06 23:14:55 +04:00
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
1998-10-20 00:46:58 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|