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>
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
13 #ifndef __GRAB_XIMAGE_H__
14 #define __GRAB_XIMAGE_H__
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.
20 As a side-effect, that image *may* be painted onto the given Window.
22 If mipmap_p is true, then make mipmaps instead of just a single texture.
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
31 Returns the sizes of various things:
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.
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.)
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.
50 So, don't use texture coordinates from 0.0 to 1.0. Instead use:
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
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.
58 When the callback is called, the image data will have been loaded
59 into texture number `texid' (via glBindTexture.)
61 If an error occurred, width/height will be 0.
63 void load_texture_async (Screen *, Window, GLXContext,
64 int desired_width, int desired_height,
67 void (*callback) (const char *filename,
76 #endif /* __GRAB_XIMAGE_H__ */