2 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
3 * (C) Copyright IBM Corporation 2003
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 /** \file opencloseopen.c
32 * Simple test for Mesa bug #508473. Create a window and rendering context.
33 * Draw a single frame. Close the window, destroy the context, and close
34 * the display. Re-open the display, create a new window and context. This
35 * should work, but, at least as of Mesa 5.1, it segfaults. See the bug
36 * report for more details.
38 * Most of the code here was lifed from various other Mesa xdemos.
44 glViewport(0, 0, 300, 300);
45 glMatrixMode(GL_PROJECTION
);
47 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
48 glMatrixMode(GL_MODELVIEW
);
50 glShadeModel(GL_FLAT
);
51 glClearColor(0.5, 0.5, 0.5, 1.0);
52 glClear(GL_COLOR_BUFFER_BIT
);
56 glColor3f(0.3, 0.3, 1.0);
58 glRotatef(0, 0, 0, 1);
60 glVertex2f(-0.5, -0.25);
61 glVertex2f( 0.5, -0.25);
62 glVertex2f( 0.5, 0.25);
63 glVertex2f(-0.5, 0.25);
69 * Create an RGB, double-buffered window.
70 * Return the window and context handles.
73 make_window( const char * dpyName
, const char *name
,
74 int x
, int y
, int width
, int height
,
75 Display
**dpyRet
, Window
*winRet
, GLXContext
*ctxRet
)
77 int attrib
[] = { GLX_RGBA
,
84 XSetWindowAttributes attr
;
92 dpy
= XOpenDisplay(dpyName
);
94 printf("Error: couldn't open display %s\n", XDisplayName(dpyName
));
99 scrnum
= DefaultScreen( dpy
);
100 root
= RootWindow( dpy
, scrnum
);
102 visinfo
= glXChooseVisual( dpy
, scrnum
, attrib
);
104 printf("Error: couldn't get an RGB, Double-buffered visual\n");
108 /* window attributes */
109 attr
.background_pixel
= 0;
110 attr
.border_pixel
= 0;
111 attr
.colormap
= XCreateColormap( dpy
, root
, visinfo
->visual
, AllocNone
);
112 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
113 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
115 win
= XCreateWindow( dpy
, root
, 0, 0, width
, height
,
116 0, visinfo
->depth
, InputOutput
,
117 visinfo
->visual
, mask
, &attr
);
119 /* set hints and properties */
121 XSizeHints sizehints
;
124 sizehints
.width
= width
;
125 sizehints
.height
= height
;
126 sizehints
.flags
= USSize
| USPosition
;
127 XSetNormalHints(dpy
, win
, &sizehints
);
128 XSetStandardProperties(dpy
, win
, name
, name
,
129 None
, (char **)NULL
, 0, &sizehints
);
132 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, True
);
134 printf("Error: glXCreateContext failed\n");
146 destroy_window( Display
*dpy
, Window win
, GLXContext ctx
)
148 glXMakeCurrent(dpy
, None
, NULL
);
149 glXDestroyContext(dpy
, ctx
);
150 XDestroyWindow(dpy
, win
);
156 main(int argc
, char *argv
[])
161 char *dpyName
= NULL
;
164 for (i
= 1; i
< argc
; i
++) {
165 if (strcmp(argv
[i
], "-display") == 0) {
171 printf("If this program segfaults, then Mesa bug #508473 is probably "
173 make_window(dpyName
, "Open-close-open", 0, 0, 300, 300, &dpy
, &win
, &ctx
);
174 XMapWindow(dpy
, win
);
175 glXMakeCurrent(dpy
, win
, ctx
);
178 glXSwapBuffers(dpy
, win
);
181 destroy_window(dpy
, win
, ctx
);
183 make_window(dpyName
, "Open-close-open", 0, 0, 300, 300, &dpy
, &win
, &ctx
);
184 XMapWindow(dpy
, win
);
185 glXMakeCurrent(dpy
, win
, ctx
);
186 destroy_window(dpy
, win
, ctx
);