http://slackware.bholcomb.com/slackware/slackware-11.0/source/xap/xscreensaver/xscree...
[xscreensaver] / hacks / glx / grab-ximage.h
1 /* grab-ximage.c --- grab the screen to an XImage for use with OpenGL.
2  * xscreensaver, Copyright (c) 2001-2006 Jamie Zawinski <jwz@jwz.org>
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  */
12
13 #ifndef __GRAB_XIMAGE_H__
14 #define __GRAB_XIMAGE_H__
15
16 /* Grabs an image of the desktop (or another random image file) and
17    loads the image into GL's texture memory.  Most of the work is done
18    in the background; when the image has been loaded, a callback is run.
19
20    As a side-effect, that image *may* be painted onto the given Window.
21
22    If mipmap_p is true, then make mipmaps instead of just a single texture.
23
24    If desired_width/height are non-zero, then (if possible) the image
25    will be scaled to fit in that rectangle.  If they are 0, then the size
26    of the window is used.  These parameters are so that you can hint to
27    the image loader that smaller images are acceptable (if you will never
28    be displaying the texture at 100% magnification, you can get away with
29    smaller textures.)
30
31    Returns the sizes of various things:
32
33       texture_width/height: The size of the texture itself, in pixels.
34                             This will often be larger than the grabbed
35                             image, since OpenGL sometimes requires texture
36                             dimensions to be a power of 2.
37
38       image_width/height:   The size of the image: this will usually be the
39                             same as the desired_width/height you passed in
40                             (but may be the size of the Window instead.)
41
42       geometry:             The position in the texture of the image bits.
43                             When image files are loaded, they are scaled up
44                             to the size of the window, but if the image does
45                             not have the same aspect ratio as the window,
46                             there will be black bars on the top/bottom or
47                             left/right.  This geometry specification tells
48                             you where the "real" image bits are.
49
50    So, don't use texture coordinates from 0.0 to 1.0.  Instead use:
51
52       [0.0 - iw/tw]         If you want to display a quad that is the same
53       [0.0 - ih/th]         size as the window; or
54
55       [gx/tw - (gx+gw)/tw]  If you want to display a quad that is the same
56       [gy/th - (gy+gh)/th]  size as the loaded image file.
57
58    When the callback is called, the image data will have been loaded
59    into texture number `texid' (via glBindTexture.)
60
61    If an error occurred, width/height will be 0.
62  */
63 void load_texture_async (Screen *, Window, GLXContext,
64                          int desired_width, int desired_height,
65                          Bool mipmap_p,
66                          GLuint texid,
67                          void (*callback) (const char *filename,
68                                            XRectangle *geometry,
69                                            int image_width,
70                                            int image_height,
71                                            int texture_width,
72                                            int texture_height,
73                                            void *closure),
74                          void *closure);
75
76 #endif /* __GRAB_XIMAGE_H__ */