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