3 * Mesa 3-D graphics library
6 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * This program opens two GLX windows, renders into one and uses
29 * glCopyPixels to copy the image from the first window into the
30 * second by means of the GLX 1.3 function glxMakeContextCurrent().
31 * This function works just like the glXMakeCurrentReadSGI() function
32 * in the GLX_SGI_make_current_read extension.
44 #ifdef GLX_VERSION_1_3
49 static GLXContext Context
;
50 static Window Win
[2]; /* Win[0] = source, Win[1] = dest */
51 static GLint Width
[2], Height
[2];
53 static GLfloat Angle
= 0.0;
58 CreateWindow(Display
*dpy
, int scrnum
, XVisualInfo
*visinfo
,
59 int xpos
, int ypos
, int width
, int height
,
63 XSetWindowAttributes attr
;
67 root
= RootWindow(dpy
, scrnum
);
69 /* window attributes */
70 attr
.background_pixel
= 0;
71 attr
.border_pixel
= 0;
72 attr
.colormap
= XCreateColormap(dpy
, root
, visinfo
->visual
, AllocNone
);
73 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
74 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
76 win
= XCreateWindow(dpy
, root
, xpos
, ypos
, width
, height
,
77 0, visinfo
->depth
, InputOutput
,
78 visinfo
->visual
, mask
, &attr
);
83 sizehints
.width
= width
;
84 sizehints
.height
= height
;
85 sizehints
.flags
= USSize
| USPosition
;
86 XSetNormalHints(dpy
, win
, &sizehints
);
87 XSetStandardProperties(dpy
, win
, name
, name
,
88 None
, (char **)NULL
, 0, &sizehints
);
99 /* make the first window the current one */
100 if (!glXMakeContextCurrent(Dpy
, Win
[0], Win
[0], Context
)) {
101 printf("glXMakeContextCurrent failed in Redraw()\n");
107 glViewport(0, 0, Width
[0], Height
[0]);
108 glMatrixMode(GL_PROJECTION
);
110 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
111 glMatrixMode(GL_MODELVIEW
);
113 glShadeModel(GL_FLAT
);
114 glClearColor(0.5, 0.5, 0.5, 1.0);
115 glClear(GL_COLOR_BUFFER_BIT
);
118 glColor3f(0.3, 0.3, 1.0);
120 glRotatef(Angle
, 0, 0, 1);
122 glVertex2f(-0.5, -0.25);
123 glVertex2f( 0.5, -0.25);
124 glVertex2f( 0.5, 0.25);
125 glVertex2f(-0.5, 0.25);
129 glXSwapBuffers(Dpy
, Win
[0]);
132 /* copy image from window 0 to window 1 */
133 if (!glXMakeContextCurrent(Dpy
, Win
[1], Win
[0], Context
)) {
134 printf("glXMakeContextCurrent failed in Redraw()\n");
138 /* raster pos setup */
139 glViewport(0, 0, Width
[1], Height
[1]);
142 glMatrixMode(GL_PROJECTION
);
145 glOrtho(-1, 1, -1, 1, -1, 1);
146 glRasterPos2f(-1, -1);
148 /* copy the image between windows */
149 glDrawBuffer(GL_FRONT
);
150 glCopyPixels(0, 0, Width
[0], Height
[0], GL_COLOR
);
151 glDrawBuffer(GL_BACK
);
154 glMatrixMode(GL_MODELVIEW
);
161 Resize(Window win
, unsigned int width
, unsigned int height
)
172 if (!glXMakeCurrent(Dpy
, Win
[i
], Context
)) {
173 printf("glXMakeCurrent failed in Resize()\n");
185 if (XPending(Dpy
) > 0) {
186 XNextEvent( Dpy
, &event
);
187 switch (event
.type
) {
191 case ConfigureNotify
:
192 Resize(event
.xany
.window
, event
.xconfigure
.width
, event
.xconfigure
.height
);
211 XVisualInfo
*visinfo
;
212 int attrib
[] = { GLX_RGBA
,
219 Dpy
= XOpenDisplay(NULL
);
221 printf("Couldn't open default display!\n");
225 ScrNum
= DefaultScreen(Dpy
);
227 visinfo
= glXChooseVisual(Dpy
, ScrNum
, attrib
);
229 printf("Unable to find RGB, double-buffered visual\n");
233 Context
= glXCreateContext(Dpy
, visinfo
, NULL
, True
);
235 printf("Couldn't create GLX context\n");
240 Win
[0] = CreateWindow(Dpy
, ScrNum
, visinfo
,
241 0, 0, 300, 300, "source window");
243 Win
[1] = CreateWindow(Dpy
, ScrNum
, visinfo
,
244 350, 0, 300, 300, "dest window");
250 main(int argc
, char *argv
[])
262 main(int argc
, char *argv
[])
264 printf("This program requires GLX 1.3!\n");
269 #endif /* GLX_VERSION_1_3 */