summaryrefslogtreecommitdiff
authorOwen W. Taylor <otaylor@fishsoup.net>2011-11-10 22:46:16 (GMT)
committer Owen W. Taylor <otaylor@fishsoup.net>2011-11-10 22:46:56 (GMT)
commit3286a14a4eebdba666d635c2f69154630792fa4b (patch)
tree25a18eddba0c9afd12a2c5b245f008362a8801d7
parente89418a0d2f531df7905fcf366103d232418bbcf (diff)
Create window matching GL fb configmaster
Even when we specify the X visual ID as input to glXChooseFBConfig, we can get a FB config that requires a different visual, so make sure to create the X window matching the selected FB config's visual.
-rw-r--r--main.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/main.c b/main.c
index a66229b..b7714c1 100644
--- a/main.c
+++ b/main.c
@@ -592,14 +592,47 @@ main(int argc, char **argv)
Cursor cursor;
XColor dummy = { 0 };
Atom state;
+ int visual_id;
const char *extensions;
+ XVisualInfo visual_template;
+ XVisualInfo *visual_info;
+ int n_visual_info;
- /* Initialize X and create our window */
+ /* Initialize X */
display = XOpenDisplay(NULL);
screen = DefaultScreen(display);
root_window = DefaultRootWindow(display);
+ /* Initialize GL */
+
+ if (!glXQueryExtension(display, &glx_error_base, &glx_event_base))
+ error("No GLX!");
+
+ i = 0;
+ attributes[i++] = GLX_VISUAL_ID;
+ attributes[i++] = DefaultVisual(display, screen)->visualid;
+ attributes[i++] = GLX_DOUBLEBUFFER;
+ attributes[i++] = True;
+ attributes[i++] = None;
+
+ g_assert(i == G_N_ELEMENTS(attributes));
+
+ config = glXChooseFBConfig(display, screen, attributes, &n_configs);
+ if(!config)
+ error("Couldn't find FBConfig");
+
+ glXGetFBConfigAttrib (display, *config,
+ GLX_VISUAL_ID, &visual_id );
+ visual_template.visualid = visual_id;
+ visual_info = XGetVisualInfo (display, VisualIDMask,
+ &visual_template, &n_visual_info);
+
+ /* Create our window */
+
+ attrs.colormap = XCreateColormap(display, root_window, visual_info[0].visual, AllocNone);
+ attrs_mask |= CWColormap;
+
attrs.event_mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask;
attrs_mask |= CWEventMask;
@@ -620,8 +653,8 @@ main(int argc, char **argv)
(DisplayWidth(display, screen) - WIDTH) / 2,
(DisplayHeight(display, screen) - HEIGHT) / 2,
WIDTH, HEIGHT,
- 0, CopyFromParent,
- InputOutput, CopyFromParent,
+ 0, visual_info[0].depth,
+ InputOutput, visual_info[0].visual,
attrs_mask, &attrs);
window_width = WIDTH;
window_height = HEIGHT;