FLTK 1.3.4
Fl_Gl_Choice.H
1 //
2 // "$Id: Fl_Gl_Choice.H 10498 2014-12-20 07:19:23Z manolo $"
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 # include <OpenGL/gl.h>
55 #ifdef __OBJC__
56 @class NSOpenGLPixelFormat;
57 @class NSOpenGLContext;
58 #else
59 class NSOpenGLPixelFormat;
60 class NSOpenGLContext;
61 #endif // __OBJC__
62 typedef NSOpenGLContext* FLOpenGLContextPtr;
63 # define GLContext FLOpenGLContextPtr
64 #else
65 # include <GL/glx.h>
66 # define GLContext GLXContext
67 #endif
68 
69 // Describes crap needed to create a GLContext.
70 class Fl_Gl_Choice {
71  int mode;
72  const int *alist;
73  Fl_Gl_Choice *next;
74 public:
75 #ifdef WIN32
76  int pixelformat; // the visual to use
77  PIXELFORMATDESCRIPTOR pfd; // some wgl calls need this thing
78 #elif defined(__APPLE_QUARTZ__)
79  NSOpenGLPixelFormat* pixelformat;
80 #else
81  XVisualInfo *vis; // the visual to use
82  Colormap colormap; // a colormap for that visual
83 #endif
84  // Return one of these structures for a given gl mode.
85  // The second argument is a glX attribute list, and is used if mode is
86  // zero. This is not supported on Win32:
87  static Fl_Gl_Choice *find(int mode, const int *);
88 };
89 
90 class Fl_Window;
91 
92 #ifdef WIN32
93 
94 GLContext fl_create_gl_context(Fl_Window*, const Fl_Gl_Choice*, int layer=0);
95 
96 #elif defined(__APPLE_QUARTZ__)
97 
98 GLContext fl_create_gl_context(Fl_Window*, const Fl_Gl_Choice*, int layer=0);
99 
100 #else
101 
102 GLContext fl_create_gl_context(XVisualInfo* vis);
103 
104 static inline
105 GLContext fl_create_gl_context(Fl_Window*, const Fl_Gl_Choice* g) {
106  return fl_create_gl_context(g->vis);
107 }
108 
109 #endif
110 
111 void fl_set_gl_context(Fl_Window*, GLContext);
112 void fl_no_gl_context();
113 void fl_delete_gl_context(GLContext);
114 
115 #endif
116 
117 //
118 // End of "$Id: Fl_Gl_Choice.H 10498 2014-12-20 07:19:23Z manolo $".
119 //
This widget produces an actual window.
Definition: Fl_Window.H:57
Definition: Fl_Gl_Choice.H:70
This file defines wrapper functions for OpenGL in FLTK.