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