NOTE: This is a continuation of a thread about problems with the glGenVertexArray() function, but apparently the problem is that my program is not getting a recent OpenGL context since I upgrated my GPU card from GTX285 to GTX680 and my nvidia driver from <who-knows> to <v310.19>. The new thread is because the old title is very misleading.
Yes, I am almost sure the context is the problem. Further down you’ll see that various output my program prints implies the program only has a OpenGL v2.12 context. Probably OpenGL v2.10 didn’t support VAOs yet, hence the behavior.
The program was running with OpenGL v3.30 context before I installed the latest nvidia driver on my 64-bit ubuntu v12.04 computer (nvidia driver 310.19, which is still shown as current as of today). After I installed the new driver, the program stopped working and the first error generated by my program was the VAO issue.
So the question probably is, why is my program not getting an OpenGL v4.30 context?
Since we seem to have narrowed down the problem to OpenGL context and not VAO functions, I create this new, appropriately named threat to continue this conversation.
I have always had problems initializing the combination of xlib, GLX, GLEW, OpenGL. I have never been able to sufficiently grasp everything necessary about xlib, GLX, GLEW and OpenGL to fully understand what is necessary, much less appropriate.
To be clear, I suspect I only need to handle the new OpenGL v4.30 context. I assume OpenGL v3.30 programs will also run on this newer context. If not, please say so.
I guess the best way to attempt to resolve this is to explain exactly what I am doing now. Here goes:
#1: Before anything significant happens in my program, it executes the ig_graphics_initialize() function, which only calls old-style GLX functions and creates, then destroys a window.
#2: Later, after everything is initialized, the application creates a default window with newer GLX functions (and should-be most recent context). It was creating an OpenGL v3.30 context before I updated my nvidia driver to v310.19 (64-bit version).
Next I’ll be more specific and show the code in the ig_graphics_initialize() function, and then the ig_window_create() function. I suspect that something “minor” changed that obsoletes my old approach, and now requires something be done in a different order, or with different functions or arguments. But what do I know? Not much, obviously.
I’ll appreciate any tips or comments anyone might have, especially from xlib, GLX, GLEW, OpenGL initialization gurus.
CORE_PUBLIC_DEFINE_CPU ig_graphics_initialize (cpu mode, cpu options) {
//
// We must initialize GLX, OpenGL and GLEW.
//
// However, apparently we cannot initialize GLEW until we have created GLX and OpenGL contexts,
// which requires we create an XWindows window, and then create a GLX/OpenGL [rendering] context.
// Therefore, during application initialization, we must create an X window (no need to map it),
// then create a GLX/OpenGL [rendering] context, then call glewInit(), then destroy the window
// and the context - then free any resources we created to do all the above.
//
// By calling glewInit() we set up the addresses of all later-version GLX and OpenGL functions,
// so henceforth we can create and manipulate GLX/OpenGL contexts with more advanced functions.
int error = 0;
static int glew_initialized = 0;
Window xwindow = 0;
Display* xdisplay = XOpenDisplay(NULL);
int xscreen = XDefaultScreen (xdisplay);
Window xroot = XRootWindow (xdisplay, xscreen);
Window xwindow_root_default = XDefaultRootWindow (xdisplay);
Screen* xscreen_default_of_display = XDefaultScreenOfDisplay (xdisplay);
Screen* xscreen_of_display = XScreenOfDisplay (xdisplay, xscreen);
GC xgraphics_context = XDefaultGC (xdisplay, xscreen);
Visual* xvisual_default = XDefaultVisual (xdisplay, xscreen);
int xdisplay_width = XDisplayWidth (xdisplay, xscreen);
int xdisplay_height = XDisplayHeight (xdisplay, xscreen);
Colormap xcolormap;
GLXWindow glxwindow;
GLXContext glxcontext;
XVisualInfo* xvisualinfo = 0;
GLXFBConfig* glxfbconfig = 0;
XSetWindowAttributes xsetwindowattributes;
int major = 0;
int minor = 0;
int errorbase = 0;
int eventbase = 0;
//
// not sure what the following line is for, but see comments in various forums
//
glewExperimental = GL_TRUE;
error = glXQueryVersion (xdisplay, &major, &minor);
error = glXQueryExtension (xdisplay, &errorbase, &eventbase);
const char* extensions = glXQueryExtensionsString (xdisplay, xscreen);
const char* clientvendor = glXGetClientString (xdisplay, GLX_VENDOR);
const char* clientversion = glXGetClientString (xdisplay, GLX_VERSION);
const char* clientextensions = glXGetClientString (xdisplay, GLX_EXTENSIONS);
const char* servervendor = glXQueryServerString (xdisplay, xscreen, GLX_VENDOR);
const char* serverversion = glXQueryServerString (xdisplay, xscreen, GLX_VERSION);
const char* serverextensions = glXQueryServerString (xdisplay, xscreen, GLX_EXTENSIONS);
printf ("GLX version ::: major.minor == %d.%d
", major, minor);
printf ("GLX offsets ::: errorbase : eventbase == %d %d
", errorbase, eventbase);
printf ("GLX extensions ::: <%s>
", extensions);
printf ("GLX clientvendor ::: <%s>
", clientvendor);
printf ("GLX clientversion ::: <%s>
", clientversion);
printf ("GLX clientextensions ::: <%s>
", clientextensions);
printf ("GLX servervendor ::: <%s>
", servervendor);
printf ("GLX serverversion ::: <%s>
", serverversion);
printf ("GLX serverextensions ::: <%s>
", serverextensions);
//
// set up xvisualattributes[] array needed in glXChooseVisual() argument list
//
int xvisualattributes[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, 0 };
//
// create xvisualinfo so we can create GLX/OpenGL context so we can call glewInit()
//
xvisualinfo = glXChooseVisual (xdisplay, xscreen, xvisualattributes);
if (xvisualinfo == 0) {
printf ("glXChooseVisual() : error : xvisualinfo == 0 : GLX/OpenGL initialization failed
");
return (CORE_ERROR_INTERNAL);
}
//
// create colormap so we can create GLX/OpenGL context so we can call glewInit()
//
xcolormap = XCreateColormap (xdisplay, xroot, xvisualinfo->visual, AllocNone);
if (xcolormap == 0) {
XFree (xvisualinfo);
printf ("XCreateColormap() : error : xcolormap == 0 : GLX/OpenGL initialization failed
");
return (CORE_ERROR_INTERNAL);
}
//
// ##### establish variables required to create the window #####
//
// to eliminate events of one or more types, comment out the corresponding lines below
//
int xeventmask = 0;
xeventmask = xeventmask | KeyPressMask; // bit 0
xeventmask = xeventmask | KeyReleaseMask; // bit 1
xeventmask = xeventmask | ButtonPressMask; // bit 2
xeventmask = xeventmask | ButtonReleaseMask; // bit 3
xeventmask = xeventmask | EnterWindowMask; // bit 4
xeventmask = xeventmask | LeaveWindowMask; // bit 5
xeventmask = xeventmask | PointerMotionMask; // bit 6
xeventmask = xeventmask | PointerMotionHintMask; // bit 7
xeventmask = xeventmask | Button1MotionMask; // bit 8
xeventmask = xeventmask | Button2MotionMask; // bit 9
xeventmask = xeventmask | Button3MotionMask; // bit 10
xeventmask = xeventmask | Button4MotionMask; // bit 11
xeventmask = xeventmask | Button5MotionMask; // bit 12
xeventmask = xeventmask | ButtonMotionMask; // bit 13
xeventmask = xeventmask | KeymapStateMask; // bit 14
xeventmask = xeventmask | ExposureMask; // bit 15
xeventmask = xeventmask | VisibilityChangeMask; // bit 16
xeventmask = xeventmask | StructureNotifyMask; // bit 17
//xeventmask = xeventmask | ResizeRedirectMask; // bit 18 DANGER --- DO NOT ENABLE
xeventmask = xeventmask | SubstructureNotifyMask; // bit 19
xeventmask = xeventmask | SubstructureRedirectMask; // bit 20
xeventmask = xeventmask | FocusChangeMask; // bit 21
xeventmask = xeventmask | PropertyChangeMask; // bit 22
xeventmask = xeventmask | ColormapChangeMask; // bit 23
xeventmask = xeventmask | OwnerGrabButtonMask; // bit 24
xsetwindowattributes.colormap = xcolormap; // vanilla RGBA
xsetwindowattributes.background_pixel = None; // prevent background clear (let OpenGL glClear())
xsetwindowattributes.background_pixmap = None; // default = None
xsetwindowattributes.border_pixmap = None; // default = CopyFromParent
xsetwindowattributes.border_pixel = None; // default = Undefined
xsetwindowattributes.cursor = None; // default = None
xsetwindowattributes.event_mask = xeventmask; // 0x0001FFFF if events of all types are enabled
xsetwindowattributes.bit_gravity = StaticGravity;
//
// assign values to any arguments to XCreateWindow() that are not already specified
//
int x = 32;
int y = 32;
int width = 640;
int height = 480;
int xselectattributes = (CWBackPixel | CWBorderPixel | CWBitGravity | CWColormap | CWEventMask);
//
// create xwindow so we can create GLX/OpenGL context so we can call glewInit()
//
xwindow = XCreateWindow (xdisplay, xroot, x, y, width, height, 0, xvisualinfo->depth, InputOutput, xvisualinfo->visual, xselectattributes, &xsetwindowattributes);
if (xwindow == 0) {
XFree (xvisualinfo);
printf ("XCreateWindow() : error : xwindow == 0 : GLX/OpenGL initialization failed
");
return (CORE_ERROR_INTERNAL);
}
//
// no need for the next 2 lines
//
// XMapWindow (xdisplay, xwindow);
// XStoreName (xdisplay, xwindow, "GLX/OpenGL initialization");
//
// create GLX / OpenGL context so we can create GLX/OpenGL context so we can call glewInit()
//
glxcontext = glXCreateContext (xdisplay, xvisualinfo, 0, GL_TRUE);
if (glxcontext == 0) {
XFree (xvisualinfo);
printf ("glXCreateContext() : error : glxcontext == 0 : GLX/OpenGL initialization failed
");
return (CORE_ERROR_INTERNAL);
}
//
// make GLX / OpenGL context current == active
//
glXMakeCurrent (xdisplay, xwindow, glxcontext);
//
// call glewInit() to initialize GLX/OpenGL functions (so we can call those functions)
//
error = glewInit();
if (error != GLEW_OK) {
printf("glewInit() : error : %s
", glewGetErrorString(error));
return (CORE_ERROR_INTERNAL);
} else {
glew_initialized = 1;
printf ("status: GLEW initialized %s
", glewGetString(GLEW_VERSION));
}
//
// destroy window, destroy GLX/OpenGL context
//
error = XUnmapWindow (xdisplay, xwindow); // unmap window here if window mapped, else not needed
error = XDestroyWindow (xdisplay, xwindow);
glXDestroyContext (xdisplay, glxcontext); // destroy GLX/OpenGL [rendering] context
XFree (xvisualinfo); // free allocated resource
//
// test some basic OpenGL functions - and make sure OpenGL is initialized
//
const GLubyte* glvendor = glGetString (GL_VENDOR);
const GLubyte* glversion = glGetString (GL_VERSION);
const GLubyte* glrenderer = glGetString (GL_RENDERER);
const GLubyte* glextensions = glGetString (GL_EXTENSIONS);
printf ("OGL vendor ::: %s
", (char*)glvendor);
printf ("OGL version ::: %s
", (char*)glversion);
printf ("OGL renderer ::: %s
", (char*)glrenderer);
printf ("OGL extensions ::: %s
", (char*)glextensions);
return (0);
}
NOTE: You can skip the first ~130 lines below to get to the meat of the function (where real xlib, GLX, GLEW stuff happens)
CORE_PUBLIC_DEFINE_CPU ig_window_create (cpu winid, cpu options, cpu x, cpu y, cpu width, cpu height, cpu dispid) {
int error = 0;
int success = 0;
int fullscreen = 0;
int objects = igstate.object_after;
static cpu glew_initialized = 0;
ig_display* display = 0;
display = (ig_display*)igstate.object[dispid]; // get display structure
error = ig_window_new (winid, 0); // create and initialize new window structure
if (error < 0) { return (error); }
ig_window* window = 0;
window = (ig_window*)igstate.object[winid]; // get address of window structure
//
// establish display characteristics
//
int display_width = display->width;
int display_height = display->height;
Display* xdisplay = display->xdisplay;
Window xwindow = 0;
//
// NOTE: much of the following information was put into the IG display structure when the display was opened with XOpenDisplay() in ig_display_create(). In the long run we must work with the values from our display object so windows can be opened on other displays (on the same computer and across any network).
//
int xscreen = XDefaultScreen (xdisplay);
Window xroot = XRootWindow (xdisplay, xscreen);
Window xwindow_root_default = XDefaultRootWindow (xdisplay);
Screen* xscreen_default_of_display = XDefaultScreenOfDisplay (xdisplay);
Screen* xscreen_of_display = XScreenOfDisplay (xdisplay, xscreen);
GC xgraphics_context = XDefaultGC (xdisplay, xscreen);
Visual* xvisual_default = XDefaultVisual (xdisplay, xscreen);
int xdisplay_width = XDisplayWidth (xdisplay, xscreen);
int xdisplay_height = XDisplayHeight (xdisplay, xscreen);
Colormap xcolormap;
XVisualInfo* xvisualinfo = 0;
XSetWindowAttributes xsetwindowattributes;
GLXWindow glxwindow;
GLXContext glxcontext;
GLXFBConfig* glxfbconfig = 0;
//
// get system metrics --- size-in-pixels of window frame and title-bar
//
int cmo = 1; // number of display-monitors on this/local computer
int xfr = 4; // frame width in pixels = 4 usually (on both left and right edges)
int yfr = 4; // frame height in pixels = 4 usually (on both top and bottom edges)
int yca = 19; // guess this value until we capture information in window message handler
int xsc = display_width; // full screen width - possibly reduced to support start/other bars
int ysc = display_height; // full screen height - possibly reduced to support start/other bars
int xfs = display_width; // full screen width - not reduced by start-bar or other travesties
int yfs = display_height; // full screen height - not reduced by start-bar or other travesties
//
// find functions to return the following values --- generally "window manager hints" in XWindows
//
if (x < 0) { x = 0; } // fix invalid x coordinate
if (y < 0) { y = 0; } // fix invalid y coordinate
if (x > display_width) { x = display_width - 32; } // make window at least partially visible
if (y > display_height) { y = display_height - 32; } // make window at least partially visible
if (width <= 0) { options = options | IG_OPTION_WINDOW_FULLWIDTH; } // width <= 0 is "full-width"
if (height <= 0) { options = options | IG_OPTION_WINDOW_FULLHEIGHT; } // height <= 0 is "full-height"
if (options & IG_OPTION_WINDOW_FULLSCREEN) { fullscreen = IG_OPTION_WINDOW_FULLSCREEN; }
if ((options & IG_OPTION_WINDOW_FULLWIDTH) && (options & IG_OPTION_WINDOW_FULLHEIGHT)) { fullscreen = IG_OPTION_WINDOW_FULLSCREEN; }
//
// later need to support fullscreen window that HAS border, caption and minimize/maximize/close buttons
//
if (fullscreen) { // fullscreen window if window width and height == display width and height
x = 0; // origin is always at top-left corner of display
y = 0; // origin is always at top-left corner of display
xsc = 0; // ditto
ysc = 0; // ditto
xfr = 0; // ditto
yfr = 0; // ditto
yca = 0; // ditto
width = display_width; // width == display_width
height = display_height; // height == display_height
} else {
if (x < xfr) { x = xfr; } // window border at left (4-pixels usually)
if (y < (yfr + yca)) { y = (yfr + yca); } // window border and title-bar at top
if (display_width < (width - (xfr + xfr))) { width = display_width - (xfr + xfr); }
if (display_height < (height - (yca + yfr + yfr))) { height = display_height - (yca + yfr + yfr); }
}
if (width < 16) { width = 16; }
if (height < 16) { height = 16; }
//
// test basic GLX functions and get basic GLX information
//
int major = 0;
int minor = 0;
int errorbase = 0;
int eventbase = 0;
error = glXQueryVersion (xdisplay, &major, &minor);
error = glXQueryExtension (xdisplay, &errorbase, &eventbase);
const char* extensions = glXQueryExtensionsString (xdisplay, xscreen);
const char* clientvendor = glXGetClientString (xdisplay, GLX_VENDOR);
const char* clientversion = glXGetClientString (xdisplay, GLX_VERSION);
const char* clientextensions = glXGetClientString (xdisplay, GLX_EXTENSIONS);
const char* servervendor = glXQueryServerString (xdisplay, xscreen, GLX_VENDOR);
const char* serverversion = glXQueryServerString (xdisplay, xscreen, GLX_VERSION);
const char* serverextensions = glXQueryServerString (xdisplay, xscreen, GLX_EXTENSIONS);
printf ("GLX version ::: major.minor == %d.%d
", major, minor);
printf ("GLX offsets ::: errorbase : eventbase == %d %d
", errorbase, eventbase);
printf ("GLX extensions ::: <%s>
", extensions);
printf ("GLX clientvendor ::: <%s>
", clientvendor);
printf ("GLX clientversion ::: <%s>
", clientversion);
printf ("GLX clientextensions ::: <%s>
", clientextensions);
printf ("GLX servervendor ::: <%s>
", servervendor);
printf ("GLX serverversion ::: <%s>
", serverversion);
printf ("GLX serverextensions ::: <%s>
", serverextensions);
//
// the following is an expanded version of glxfbconfigattributes002 below (for ease of reading)
//
GLint glxfbconfigattributes[] = {
GLX_BUFFER_SIZE, 32,
GLX_DOUBLEBUFFER, 1,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_ALPHA_SIZE, 8,
GLX_DEPTH_SIZE, 24,
GLX_STENCIL_SIZE, 1,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
GLX_CONFIG_CAVEAT, GLX_NONE,
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 2,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0, 0,
0, 0
};
//
// create integer array of GL/GLX framebuffer configuration attributes
//
int glxfbconfigelements = 0;
int glxfbconfigattributes000[] = { GLX_BUFFER_SIZE, 32, GLX_DOUBLEBUFFER, 1, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 1, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_CONFIG_CAVEAT, GLX_NONE, GLX_CONTEXT_MAJOR_VERSION_ARB, 4, GLX_CONTEXT_MINOR_VERSION_ARB, 1, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0, 0, 0, 0 };
int glxfbconfigattributes001[] = { GLX_BUFFER_SIZE, 32, GLX_DOUBLEBUFFER, 1, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 1, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_CONFIG_CAVEAT, GLX_NONE, GLX_CONTEXT_MAJOR_VERSION_ARB, 4, GLX_CONTEXT_MINOR_VERSION_ARB, 0, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0, 0, 0, 0 };
int glxfbconfigattributes002[] = { GLX_BUFFER_SIZE, 32, GLX_DOUBLEBUFFER, 1, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 1, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_CONFIG_CAVEAT, GLX_NONE, GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 3, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0, 0, 0, 0 };
int glxfbconfigattributes003[] = { GLX_BUFFER_SIZE, 32, GLX_DOUBLEBUFFER, 1, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 1, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_CONFIG_CAVEAT, GLX_NONE, GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 2, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0, 0, 0, 0 };
int glxfbconfigattributes004[] = { GLX_BUFFER_SIZE, 32, GLX_DOUBLEBUFFER, 1, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 1, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_CONFIG_CAVEAT, GLX_NONE, GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 2, 0, 0, 0, 0 };
int glxfbconfigattributes005[] = { GLX_BUFFER_SIZE, 32, GLX_DOUBLEBUFFER, 1, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 1, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_CONFIG_CAVEAT, GLX_NONE, 0, 0, 0, 0 };
int glxfbconfigattributes006[] = { GLX_BUFFER_SIZE, 32, GLX_DOUBLEBUFFER, 1, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 1, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 0, 0, 0, 0 };
int glxfbconfigattributes007[] = { GLX_BUFFER_SIZE, 32, GLX_DOUBLEBUFFER, 1, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 32, GLX_STENCIL_SIZE, 1, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 0, 0, 0, 0 };
int glxfbconfigattributes008[] = { 0, 0, 0, 0 };
//
// choose framebuffer configuration closest to desired (in order specified above)
//
// glxfbconfig = glXChooseFBConfig (xdisplay, xscreen, 0, &glxfbconfigelements);
glxfbconfig = glXChooseFBConfig (xdisplay, xscreen, (int*)glxfbconfigattributes000, &glxfbconfigelements);
if ((glxfbconfig == 0) || (glxfbconfigelements < 1)) {
printf ("glXChooseFBConfig() : error : glxfbconfigattributes000 failed - trying less restrictive...
");
glxfbconfig = glXChooseFBConfig (xdisplay, xscreen, (int*)glxfbconfigattributes001, &glxfbconfigelements);
if ((glxfbconfig == 0) || (glxfbconfigelements < 1)) {
printf ("glXChooseFBConfig() : error : glxfbconfigattributes001 failed - trying less restrictive...
");
glxfbconfig = glXChooseFBConfig (xdisplay, xscreen, (int*)glxfbconfigattributes002, &glxfbconfigelements);
if ((glxfbconfig == 0) || (glxfbconfigelements < 1)) {
printf ("glXChooseFBConfig() : error : glxfbconfigattributes002 failed - trying less restrictive...
");
glxfbconfig = glXChooseFBConfig (xdisplay, xscreen, (int*)glxfbconfigattributes003, &glxfbconfigelements);
if ((glxfbconfig == 0) || (glxfbconfigelements < 1)) {
printf ("glXChooseFBConfig() : error : glxfbconfigattributes003 failed - trying less restrictive...
");
glxfbconfig = glXChooseFBConfig (xdisplay, xscreen, (int*)glxfbconfigattributes004, &glxfbconfigelements);
if ((glxfbconfig == 0) || (glxfbconfigelements < 1)) {
printf ("glXChooseFBConfig() : error : glxfbconfigattributes004 failed - trying less restrictive...
");
glxfbconfig = glXChooseFBConfig (xdisplay, xscreen, (int*)glxfbconfigattributes005, &glxfbconfigelements);
if ((glxfbconfig == 0) || (glxfbconfigelements < 1)) {
printf ("glXChooseFBConfig() : error : glxfbconfigattributes005 failed - nothing less restrictive - permanent failure - terminate process
");
return (CORE_ERROR_INTERNAL);
}
}
}
}
}
}
xvisualinfo = glXGetVisualFromFBConfig (xdisplay, glxfbconfig[0]);
if (xvisualinfo == 0) { printf ("glXGetVisualFromFBConfig() : error : xvisualinfo == 0 : terminate process
"); return (CORE_ERROR_INTERNAL); }
glxcontext = glXCreateNewContext (xdisplay, glxfbconfig[0], GLX_RGBA_TYPE, 0, GL_TRUE);
if (glxcontext == 0) { printf ("glXCreateNewContext() : error : glxcontext == 0 : terminate process
"); return (CORE_ERROR_INTERNAL); }
xcolormap = XCreateColormap (xdisplay, xroot, xvisualinfo->visual, AllocNone);
if (xcolormap == 0) { printf ("XCreateColormap() : error : xcolormap == 0 : terminate process
"); return (CORE_ERROR_INTERNAL); }
//
// define XCreateWindow() arguments
//
int xeventmask = 0;
xeventmask = xeventmask | KeyPressMask; // bit 0
xeventmask = xeventmask | KeyReleaseMask; // bit 1
xeventmask = xeventmask | ButtonPressMask; // bit 2
xeventmask = xeventmask | ButtonReleaseMask; // bit 3
xeventmask = xeventmask | EnterWindowMask; // bit 4
xeventmask = xeventmask | LeaveWindowMask; // bit 5
xeventmask = xeventmask | PointerMotionMask; // bit 6
xeventmask = xeventmask | PointerMotionHintMask; // bit 7
xeventmask = xeventmask | Button1MotionMask; // bit 8
xeventmask = xeventmask | Button2MotionMask; // bit 9
xeventmask = xeventmask | Button3MotionMask; // bit 10
xeventmask = xeventmask | Button4MotionMask; // bit 11
xeventmask = xeventmask | Button5MotionMask; // bit 12
xeventmask = xeventmask | ButtonMotionMask; // bit 13
xeventmask = xeventmask | KeymapStateMask; // bit 14
xeventmask = xeventmask | ExposureMask; // bit 15
xeventmask = xeventmask | VisibilityChangeMask; // bit 16
xeventmask = xeventmask | StructureNotifyMask; // bit 17
//xeventmask = xeventmask | ResizeRedirectMask; // bit 18 DANGER ::: DO NOT ENABLE
xeventmask = xeventmask | SubstructureNotifyMask; // bit 19
xeventmask = xeventmask | SubstructureRedirectMask; // bit 20
xeventmask = xeventmask | FocusChangeMask; // bit 21
xeventmask = xeventmask | PropertyChangeMask; // bit 22
xeventmask = xeventmask | ColormapChangeMask; // bit 23
xeventmask = xeventmask | OwnerGrabButtonMask; // bit 24
xsetwindowattributes.colormap = xcolormap; // vanilla RGBA
xsetwindowattributes.background_pixel = None; // prevent background clear (let OpenGL glClear())
xsetwindowattributes.background_pixmap = None; // default = None
xsetwindowattributes.border_pixmap = None; // default = CopyFromParent
xsetwindowattributes.border_pixel = None; // default = Undefined
xsetwindowattributes.cursor = None; // default = None
xsetwindowattributes.event_mask = xeventmask; // 0x0001FFFF if events of all types are enabled
xsetwindowattributes.bit_gravity = StaticGravity;
int xselectattributes = (CWBackPixel | CWBorderPixel | CWBitGravity | CWColormap | CWEventMask);
xwindow = XCreateWindow (xdisplay, xroot, x, y, width, height, 0, xvisualinfo->depth, InputOutput, xvisualinfo->visual, xselectattributes, &xsetwindowattributes);
if (xwindow == 0) { printf ("error ::: XCreateWindow()
"); return (-1); }
error = XSetStandardProperties (xdisplay, xwindow, "IG", "window.bmp", 0, 0, 0, 0);
if (error == 0) { printf ("error ::: XSetStandardProperties()
"); }
char* STRING_WM_DELETE_WINDOW = (char*) "WM_DELETE_WINDOW";
Atom XA_WM_DELETE_WINDOW = XInternAtom (xdisplay, STRING_WM_DELETE_WINDOW, 0);
error = XSetWMProtocols (xdisplay, xwindow, &XA_WM_DELETE_WINDOW, 1);
igstate.message_close_window = XA_WM_DELETE_WINDOW;
//
// ####################### in theory the glXMakeContextCurrent() should not be here, but........
// ##### IMPORTANT ##### simple tests indicate this glXMakeContextCurrent() must be here
// ####################### because putting this in CreateNotify causes segment violation
//
glxwindow = glXCreateWindow (xdisplay, glxfbconfig[0], xwindow, 0);
error = glXMakeContextCurrent (xdisplay, glxwindow, glxwindow, glxcontext);
//
// do not automatically map/show/display windows --- we have a function for that == ig_window_display()
//
// error = XMapWindow (xdisplay, xwindow);
//
// populate window structure
//
window->displayid = dispid;
window->xdisplay = xdisplay;
window->xwindow = xwindow;
window->glxwindow = glxwindow;
window->glxcontext = glxcontext;
window->glxfbconfig = glxfbconfig[0];
window->style = 0;
window->type = options;
if (fullscreen) {
window->x = 0;
window->y = 0;
window->xdisp = x;
window->ydisp = y;
window->width = width;
window->height = height;
window->xframe = x;
window->yframe = y;
window->wframe = width;
window->hframe = height;
window->lborder = 0;
window->tborder = 0;
window->rborder = 0;
window->bborder = 0;
window->cborder = 0;
window->resized = 1;
} else {
window->x = 0;
window->y = 0;
window->xdisp = x;
window->ydisp = y;
window->width = width;
window->height = height;
window->xframe = x - xfr;
window->yframe = y - yfr - yca;
window->wframe = width + xfr + xfr;
window->hframe = height + yfr + yfr + yca;
window->lborder = xfr;
window->tborder = yfr;
window->rborder = xfr;
window->bborder = yfr;
window->cborder = yca;
window->resized = 1;
}
//
//
// ###############################################################################
// ##### XWindows does NOT generate an event when a new window is created! #####
// ##### But work must be done when windows are created, so generate event #####
// ###############################################################################
//
XCreateWindowEvent xmessage;
xmessage.type = CreateNotify;
xmessage.display = xdisplay;
xmessage.window = xwindow;
xmessage.parent = xroot;
xmessage.send_event = 0;
xmessage.serial = 0;
xmessage.x = x;
xmessage.y = y;
xmessage.width = width;
xmessage.height = height;
xmessage.border_width = xfr;
xmessage.override_redirect = 0;
error = XSendEvent (xdisplay, xwindow, 0, StructureNotifyMask, (XEvent*)&xmessage);
//
// free all resources we're supposed to free according to xlib and GLX function documentation
//
XFree (glxfbconfig);
XFree (xvisualinfo);
return (winid); // return window id #
}