FLTK 1.3.0
Fl_Gl_Choice.H
1 //
2 // "$Id: Fl_Gl_Choice.H 7913 2010-11-29 18:18:27Z greg.ercolano $"
3 //
4 // OpenGL definitions for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
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.
12 //
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.
17 //
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
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 // http://www.fltk.org/str.php
26 //
27 
28 // Internal interface to set up OpenGL.
29 //
30 // A "Fl_Gl_Choice" is created from an OpenGL mode and holds information
31 // necessary to create a window (on X) and to create an OpenGL "context"
32 // (on both X and Win32).
33 //
34 // fl_create_gl_context takes a window (necessary only on Win32) and an
35 // Fl_Gl_Choice and returns a new OpenGL context. All contexts share
36 // display lists with each other.
37 //
38 // On X another fl_create_gl_context is provided to create it for any
39 // X visual.
40 //
41 // fl_set_gl_context makes the given OpenGL context current and makes
42 // it draw into the passed window. It tracks the current one context
43 // to avoid calling the context switching code when the same context
44 // is used, though it is a mystery to me why the GLX/WGL libraries
45 // don't do this themselves...
46 //
47 // fl_no_gl_context clears that cache so the next fl_set_gl_context is
48 // guaranteed to work.
49 //
50 // fl_delete_gl_context destroys the context.
51 //
52 // This code is used by Fl_Gl_Window, gl_start(), and gl_visual()
53 
54 #ifndef Fl_Gl_Choice_H
55 #define Fl_Gl_Choice_H
56 
57 // Warning: whatever GLContext is defined to must take exactly the same
58 // space in a structure as a void*!!!
59 #ifdef WIN32
60 # include <FL/gl.h>
61 # define GLContext HGLRC
62 #elif defined(__APPLE_QUARTZ__)
63 // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
64 # include <OpenGL/gl.h>
65 # include <AGL/agl.h>
66 # define GLContext AGLContext
67 #else
68 # include <GL/glx.h>
69 # define GLContext GLXContext
70 #endif
71 
72 // Describes crap needed to create a GLContext.
73 class Fl_Gl_Choice {
74  int mode;
75  const int *alist;
76  Fl_Gl_Choice *next;
77 public:
78 #ifdef WIN32
79  int pixelformat; // the visual to use
80  PIXELFORMATDESCRIPTOR pfd; // some wgl calls need this thing
81 #elif defined(__APPLE_QUARTZ__)
82  // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
83  AGLPixelFormat pixelformat;
84 #else
85  XVisualInfo *vis; // the visual to use
86  Colormap colormap; // a colormap for that visual
87 #endif
88  // Return one of these structures for a given gl mode.
89  // The second argument is a glX attribute list, and is used if mode is
90  // zero. This is not supported on Win32:
91  static Fl_Gl_Choice *find(int mode, const int *);
92 };
93 
94 class Fl_Window;
95 
96 #ifdef WIN32
97 
98 GLContext fl_create_gl_context(Fl_Window*, const Fl_Gl_Choice*, int layer=0);
99 
100 #elif defined(__APPLE_QUARTZ__)
101 // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
102 
103 GLContext fl_create_gl_context(Fl_Window*, const Fl_Gl_Choice*, int layer=0);
104 
105 #else
106 
107 GLContext fl_create_gl_context(XVisualInfo* vis);
108 
109 static inline
110 GLContext fl_create_gl_context(Fl_Window*, const Fl_Gl_Choice* g) {
111  return fl_create_gl_context(g->vis);
112 }
113 
114 #endif
115 
116 void fl_set_gl_context(Fl_Window*, GLContext);
117 void fl_no_gl_context();
118 void fl_delete_gl_context(GLContext);
119 
120 #endif
121 
122 //
123 // End of "$Id: Fl_Gl_Choice.H 7913 2010-11-29 18:18:27Z greg.ercolano $".
124 //