fltk/src/gl_start.cxx
Bill Spitzak 97234fb3e2 Replaced remaining _WIN32 symbols with WIN32
Stuff from work:

Removed reference to unused GL/glu.h header file, which is missing on
some Linux systems.

Fl_Gl_Window has a new method to allow you to get and set the context:

  void Fl_Gl_Window::context(void*, int destroy = 0)
  void* Fl_Gl_Window::context() const;

  Return or set a pointer to the GLContext that this window is
  using. This is a system-dependent structure, but it is portable to
  copy the context from one window to another. You can also set it to
  NULL, which will force FLTK to recreate the context the next time
  make_current() is called, this is useful for getting around bugs in
  OpenGL implementations.

  If destroy_flag is true the context will be destroyed by fltk when
  the window is destroyed, or when the mode() is changed, or the next
  time context(x) is called.

Some cleanup of Fl_Gl_Choice to move most of the system dependent
#ifdefs into Fl_Gl_Choice.cxx.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1413 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-03-14 17:20:02 +00:00

118 lines
3.3 KiB
C++

//
// "$Id: gl_start.cxx,v 1.6.2.5 2001/03/14 17:20:02 spitzak Exp $"
//
// OpenGL context routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2001 by Bill Spitzak and others.
//
// 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.
//
// Please report all bugs and problems to "fltk-bugs@easysw.com".
//
// 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>
#include "Fl_Gl_Choice.H"
extern int fl_clip_state_number; // in fl_rect.C
static GLContext context;
static int clip_state_number=-1;
static int pw, ph;
#ifdef WIN32
static Fl_Gl_Choice* gl_choice;
#endif
Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.C
void gl_start() {
if (!context) {
#ifdef WIN32
if (!gl_choice) Fl::gl_visual(0);
context = fl_create_gl_context(Fl_Window::current(), gl_choice);
#else
context = fl_create_gl_context(fl_visual);
#endif
}
fl_set_gl_context(Fl_Window::current(), context);
#ifndef WIN32
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);
}
if (clip_state_number != fl_clip_state_number) {
clip_state_number = fl_clip_state_number;
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);
}
}
}
void gl_finish() {
glFlush();
#ifndef WIN32
glXWaitGL();
#endif
}
int Fl::gl_visual(int mode, int *alist) {
Fl_Gl_Choice *c = Fl_Gl_Choice::find(mode,alist);
if (!c) return 0;
#ifdef WIN32
gl_choice = c;
#else
fl_visual = c->vis;
fl_colormap = c->colormap;
#endif
return 1;
}
#endif
//
// End of "$Id: gl_start.cxx,v 1.6.2.5 2001/03/14 17:20:02 spitzak Exp $".
//