2 // "$Id: gl_start.cxx 8368 2011-02-04 23:32:53Z manolo $"
4 // OpenGL context routines for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // You MUST use gl_visual() to select the default visual before doing
29 // show() of any windows. Mesa will crash if you try to use a visual
30 // not returned by glxChooseVisual.
32 // This does not work with Fl_Double_Window's! It will try to draw
33 // into the front buffer. Depending on the system this will either
34 // crash or do nothing (when pixmaps are being used as back buffer
35 // and GL is being done by hardware), work correctly (when GL is done
36 // with software, such as Mesa), or draw into the front buffer and
37 // be erased when the buffers are swapped (when double buffer hardware
44 #include <FL/Fl_Window.H>
46 #include <FL/fl_draw.H>
47 #include "Fl_Gl_Choice.H"
49 static GLContext context
;
50 static int clip_state_number
=-1;
54 static Fl_Gl_Choice
* gl_choice
;
58 static Fl_Gl_Choice
* gl_choice
;
61 Fl_Region
XRectangleRegion(int x
, int y
, int w
, int h
); // in fl_rect.cxx
63 /** Creates an OpenGL context */
67 context
= fl_create_gl_context(fl_visual
);
69 if (!gl_choice
) Fl::gl_visual(0);
70 context
= fl_create_gl_context(Fl_Window::current(), gl_choice
);
71 #elif defined(__APPLE_QUARTZ__)
72 // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
73 context
= fl_create_gl_context(Fl_Window::current(), gl_choice
);
75 # error Unsupported platform
78 fl_set_gl_context(Fl_Window::current(), context
);
79 #if !defined(WIN32) && !defined(__APPLE__)
82 if (pw
!= Fl_Window::current()->w() || ph
!= Fl_Window::current()->h()) {
83 pw
= Fl_Window::current()->w();
84 ph
= Fl_Window::current()->h();
86 glViewport(0, 0, pw
, ph
);
87 glOrtho(0, pw
, 0, ph
, -1, 1);
88 glDrawBuffer(GL_FRONT
);
90 if (clip_state_number
!= fl_graphics_driver
->fl_clip_state_number
) {
91 clip_state_number
= fl_graphics_driver
->fl_clip_state_number
;
93 if (fl_clip_box(0, 0, Fl_Window::current()->w(), Fl_Window::current()->h(),
95 fl_clip_region(XRectangleRegion(x
,y
,w
,h
));
96 glScissor(x
, Fl_Window::current()->h()-(y
+h
), w
, h
);
97 glEnable(GL_SCISSOR_TEST
);
99 glDisable(GL_SCISSOR_TEST
);
104 /** Releases an OpenGL context */
107 #if !defined(WIN32) && !defined(__APPLE__)
112 int Fl::gl_visual(int mode
, int *alist
) {
113 Fl_Gl_Choice
*c
= Fl_Gl_Choice::find(mode
,alist
);
117 fl_colormap
= c
->colormap
;
120 #elif defined(__APPLE_QUARTZ__)
121 // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
124 # error Unsupported platform
131 // End of "$Id: gl_start.cxx 8368 2011-02-04 23:32:53Z manolo $".