1 /* $Id: wincopy.c,v 1.1 1999/11/25 17:41:51 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * This program opens two GLX windows, renders into one and uses
30 * glCopyPixels to copy the image from the first window into the
31 * second by means of the GLX 1.3 function glxMakeContextCurrent().
32 * This function works just like the glXMakeCurrentReadSGI() function
33 * in the GLX_SGI_make_current_read extension.
45 #ifdef GLX_VERSION_1_3
50 static GLXContext Context
;
51 static Window Win
[2]; /* Win[0] = source, Win[1] = dest */
52 static GLint Width
[2], Height
[2];
54 static GLfloat Angle
= 0.0;
59 CreateWindow(Display
*dpy
, int scrnum
, XVisualInfo
*visinfo
,
60 int xpos
, int ypos
, int width
, int height
,
64 XSetWindowAttributes attr
;
68 root
= RootWindow(dpy
, scrnum
);
70 /* window attributes */
71 attr
.background_pixel
= 0;
72 attr
.border_pixel
= 0;
73 attr
.colormap
= XCreateColormap(dpy
, root
, visinfo
->visual
, AllocNone
);
74 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
75 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
77 win
= XCreateWindow(dpy
, root
, xpos
, ypos
, width
, height
,
78 0, visinfo
->depth
, InputOutput
,
79 visinfo
->visual
, mask
, &attr
);
84 sizehints
.width
= width
;
85 sizehints
.height
= height
;
86 sizehints
.flags
= USSize
| USPosition
;
87 XSetNormalHints(dpy
, win
, &sizehints
);
88 XSetStandardProperties(dpy
, win
, name
, name
,
89 None
, (char **)NULL
, 0, &sizehints
);
100 /* make the first window the current one */
101 if (!glXMakeContextCurrent(Dpy
, Win
[0], Win
[0], Context
)) {
102 printf("glXMakeContextCurrent failed in Redraw()\n");
108 glViewport(0, 0, Width
[0], Height
[0]);
109 glMatrixMode(GL_PROJECTION
);
111 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
112 glMatrixMode(GL_MODELVIEW
);
114 glShadeModel(GL_FLAT
);
115 glClearColor(0.5, 0.5, 0.5, 1.0);
116 glClear(GL_COLOR_BUFFER_BIT
);
119 glColor3f(0.3, 0.3, 1.0);
121 glRotatef(Angle
, 0, 0, 1);
123 glVertex2f(-0.5, -0.25);
124 glVertex2f( 0.5, -0.25);
125 glVertex2f( 0.5, 0.25);
126 glVertex2f(-0.5, 0.25);
130 glXSwapBuffers(Dpy
, Win
[0]);
133 /* copy image from window 0 to window 1 */
134 if (!glXMakeContextCurrent(Dpy
, Win
[1], Win
[0], Context
)) {
135 printf("glXMakeContextCurrent failed in Redraw()\n");
139 /* raster pos setup */
140 glViewport(0, 0, Width
[1], Height
[1]);
143 glMatrixMode(GL_PROJECTION
);
146 glOrtho(-1, 1, -1, 1, -1, 1);
147 glRasterPos2f(-1, -1);
149 /* copy the image between windows */
150 glDrawBuffer(GL_FRONT
);
151 glCopyPixels(0, 0, Width
[0], Height
[0], GL_COLOR
);
152 glDrawBuffer(GL_BACK
);
155 glMatrixMode(GL_MODELVIEW
);
162 Resize(Window win
, unsigned int width
, unsigned int height
)
173 if (!glXMakeCurrent(Dpy
, Win
[i
], Context
)) {
174 printf("glXMakeCurrent failed in Resize()\n");
186 if (XPending(Dpy
) > 0) {
187 XNextEvent( Dpy
, &event
);
188 switch (event
.type
) {
192 case ConfigureNotify
:
193 Resize(event
.xany
.window
, event
.xconfigure
.width
, event
.xconfigure
.height
);
212 XVisualInfo
*visinfo
;
213 int attrib
[] = { GLX_RGBA
,
220 Dpy
= XOpenDisplay(NULL
);
222 printf("Couldn't open default display!\n");
226 ScrNum
= DefaultScreen(Dpy
);
228 visinfo
= glXChooseVisual(Dpy
, ScrNum
, attrib
);
230 printf("Unable to find RGB, double-buffered visual\n");
234 Context
= glXCreateContext(Dpy
, visinfo
, NULL
, True
);
236 printf("Couldn't create GLX context\n");
241 Win
[0] = CreateWindow(Dpy
, ScrNum
, visinfo
,
242 0, 0, 300, 300, "source window");
244 Win
[1] = CreateWindow(Dpy
, ScrNum
, visinfo
,
245 350, 0, 300, 300, "dest window");
251 main(int argc
, char *argv
[])
263 main(int argc
, char *argv
[])
265 printf("This program requires GLX 1.3!\n");
270 #endif /* GLX_VERSION_1_3 */