1 /* File : Fl_Gl_Window.i */
2 //%module Fl_Gl_Window
3 
4 %feature("docstring") ::Fl_Gl_Window
5 """
6 The Fl_Gl_Window widget sets things up so OpenGL works, and also keeps an
7 OpenGL 'context' for that window, so that changes to the lighting and
8 projection may be reused between redraws. Fl_Gl_Window also flushes the
9 OpenGL streams and swaps buffers after draw()  returns.
10 
11 OpenGL hardware typically provides some overlay bit planes, which are very
12 useful for drawing UI controls atop your 3D graphics. If the overlay hardware
13 is not provided, FLTK tries to simulate the overlay, This works pretty well
14 if your graphics are double buffered, but not very well for single-buffered.
15 """ ;
16 
17 %feature("nodirector") Fl_Gl_Window::show;
18 
19 %{
20 #include "FL/Fl_Gl_Window.H"
21 #include "FL/gl.h"
22 #include "string.h"
23 %}
24 
25 %include "macros.i"
26 
27 CHANGE_OWNERSHIP(Fl_Gl_Window)
28 
29 %include "WindowShowTypemap.i"
30 %include typemaps.i
31 
32 // override method show
33 %extend Fl_Gl_Window {
34 	MACRO_WINDOW_SHOW
35 }
36 
37 // typemap to map output of Fl_Gl_Window.valid from char to int
38 %typemap(out) char {
39     $result = PyInt_FromLong( (long)$1);
40 }
41 
42 // ignore original declaration
43 %ignore Fl_Gl_Window::show();
44 %ignore Fl_Gl_Window::show(int argc, char** argv);
45 
46 %include "FL/Fl_Gl_Window.H"
47 %include "FL/gl.h"
48 
49 %feature("docstring") Fl_Gl_Window::drawPixels
50 "Writes a raw RGB string to the canvas.
51 
52 Arguments:
53     - rgb - a string of width * height * 3 bytes, comprising
54       the raw image in RGB format
55 "
56 
57 %extend Fl_Gl_Window {
58 
drawPixels(PyObject * rgb_py)59 void Fl_Gl_Window::drawPixels(PyObject *rgb_py) {
60 
61     char *rgb;
62     size_t len;
63     int i, height=self->h(), halfheight=self->h()/2, rowsize=self->w()*3;
64     char *row0, *row1;
65 
66     char *tmp = new char [rowsize];
67     SWIG_AsCharPtrAndSize(rgb_py, &rgb, &len, 0);
68 
69     row0 = rgb;
70     row1 = rgb + (height-1) * rowsize;
71     for (i=0; i<halfheight; i++) {
72         memcpy(tmp, row0, rowsize);
73         memcpy(row0, row1, rowsize);
74         memcpy(row1, tmp, rowsize);
75         row0 += rowsize;
76         row1 -= rowsize;
77     }
78 
79     glDrawPixels(self->w(), self->h(), GL_RGB, GL_UNSIGNED_BYTE, rgb);
80 
81     delete [] tmp;
82 }
83 
84 };
85 
86 // clear the typemap for char
87 %typemap(out) char;
88