add option for newer Linux demos to dynamically load X11, glX and OpenGL 1 functions

(and avoid having to link against X, glx and GL)
-DGLEW_INIT_OPENGL11_FUNCTIONS
-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
-DDYNAMIC_LOAD_X11_FUNCTIONS
and link against libdl (for example usingi -ldl)
This commit is contained in:
Erwin Coumans (Google)
2014-07-11 14:25:32 -07:00
parent 72ae3b6afb
commit 433d349369
6 changed files with 537 additions and 155 deletions

View File

@@ -31,6 +31,7 @@
#define GLEW_NO_GLU #define GLEW_NO_GLU
//#define GLEW_INIT_OPENGL11_FUNCTIONS 1 //#define GLEW_INIT_OPENGL11_FUNCTIONS 1
//#define GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS 1
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
@@ -19061,6 +19062,10 @@ GLEWAPI const GLubyte * GLEWAPIENTRY glewGetString (GLenum name);
GLEWAPI GLboolean GLEWAPIENTRY glewOpenGL11Init(void); GLEWAPI GLboolean GLEWAPIENTRY glewOpenGL11Init(void);
#endif //GLEW_INIT_OPENGL11_FUNCTIONS #endif //GLEW_INIT_OPENGL11_FUNCTIONS
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
GLEWAPI GLboolean GLEWAPIENTRY glewXInit(void);
#endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -97,7 +97,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xmd.h> #include <X11/Xmd.h>
#include <GL/glew.h> #include "glew.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -143,6 +143,48 @@ typedef struct __GLXcontextRec *GLXContext;
typedef unsigned int GLXVideoDeviceNV; typedef unsigned int GLXVideoDeviceNV;
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
typedef Bool (* PFNGLXQUERYEXTENSION) (Display *dpy, int *errorBase, int *eventBase);
#define glXQueryExtension GLXEW_GET_FUN(__glewXQueryExtension)
typedef Bool (* PFNGLXQUERYVERSION) (Display *dpy, int *major, int *minor);
#define glXQueryVersion GLXEW_GET_FUN(__glewXQueryVersion)
typedef int (* PFNGLXGETCONFIG) (Display *dpy, XVisualInfo *vis, int attrib, int *value);
#define glXGetConfig GLXEW_GET_FUN(__glewXGetConfig)
typedef XVisualInfo* (* PFNGLXCHOOSEVISUAL) (Display *dpy, int screen, int *attribList);
#define glXChooseVisual GLXEW_GET_FUN(__glewXChooseVisual)
//extern GLXPixmap glXCreateGLXPixmap (Display *dpy, XVisualInfo *vis, Pixmap pixmap);
//extern void glXDestroyGLXPixmap (Display *dpy, GLXPixmap pix);
typedef GLXContext (* PFNGLXCREATECONTEXT) (Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct);
#define glXCreateContext GLXEW_GET_FUN(__glewXCreateContext)
typedef void (*PFNGLXDESTROYCONTEXT) (Display *dpy, GLXContext ctx);
#define glXDestroyContext GLXEW_GET_FUN(__glewXDestroyContext)
typedef Bool (* PFNGLXISDIRECT) (Display *dpy, GLXContext ctx);
#define glXIsDirect GLXEW_GET_FUN(__glewXIsDirect)
//extern void glXCopyContext (Display *dpy, GLXContext src, GLXContext dst, GLulong mask);
typedef Bool (*PFNGLXMAKECURRENT) (Display *dpy, GLXDrawable drawable, GLXContext ctx);
#define glXMakeCurrent GLXEW_GET_FUN(__glewXMakeCurrent)
//extern GLXContext glXGetCurrentContext (void);
//extern GLXDrawable glXGetCurrentDrawable (void);
//extern void glXWaitGL (void);
//extern void glXWaitX (void);
typedef void (*PFNGLXSWAPBUFFERS) (Display *dpy, GLXDrawable drawable);
#define glXSwapBuffers GLXEW_GET_FUN(__glewXSwapBuffers)
//extern void glXUseXFont (Font font, int first, int count, int listBase);
#else//GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
extern Bool glXQueryExtension (Display *dpy, int *errorBase, int *eventBase); extern Bool glXQueryExtension (Display *dpy, int *errorBase, int *eventBase);
extern Bool glXQueryVersion (Display *dpy, int *major, int *minor); extern Bool glXQueryVersion (Display *dpy, int *major, int *minor);
extern int glXGetConfig (Display *dpy, XVisualInfo *vis, int attrib, int *value); extern int glXGetConfig (Display *dpy, XVisualInfo *vis, int attrib, int *value);
@@ -160,6 +202,7 @@ extern void glXWaitGL (void);
extern void glXWaitX (void); extern void glXWaitX (void);
extern void glXSwapBuffers (Display *dpy, GLXDrawable drawable); extern void glXSwapBuffers (Display *dpy, GLXDrawable drawable);
extern void glXUseXFont (Font font, int first, int count, int listBase); extern void glXUseXFont (Font font, int first, int count, int listBase);
#endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#define GLXEW_VERSION_1_0 GLXEW_GET_VAR(__GLXEW_VERSION_1_0) #define GLXEW_VERSION_1_0 GLXEW_GET_VAR(__GLXEW_VERSION_1_0)
@@ -174,9 +217,22 @@ extern void glXUseXFont (Font font, int first, int count, int listBase);
#define GLX_VERSION 0x2 #define GLX_VERSION 0x2
#define GLX_EXTENSIONS 0x3 #define GLX_EXTENSIONS 0x3
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
typedef const char* (*PFNGLXQUERYEXTENSIONSSTRING) (Display *dpy, int screen);
#define glXQueryExtensionsString GLXEW_GET_FUN(__glewXQueryExtensionsString)
typedef const char* (*PFNGLXGETCLIENTSTRING) (Display *dpy, int name);
#define glXGetClientString GLXEW_GET_FUN(__glewXGetClientString)
typedef const char* (*PFNGLXQUERYSERVERSTRING) (Display *dpy, int screen, int name);
#define glXQueryServerString GLXEW_GET_FUN(__glewXQueryServerString)
#else//GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
extern const char* glXQueryExtensionsString (Display *dpy, int screen); extern const char* glXQueryExtensionsString (Display *dpy, int screen);
extern const char* glXGetClientString (Display *dpy, int name); extern const char* glXGetClientString (Display *dpy, int name);
extern const char* glXQueryServerString (Display *dpy, int screen, int name); extern const char* glXQueryServerString (Display *dpy, int screen, int name);
#endif//GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#define GLXEW_VERSION_1_1 GLXEW_GET_VAR(__GLXEW_VERSION_1_1) #define GLXEW_VERSION_1_1 GLXEW_GET_VAR(__GLXEW_VERSION_1_1)
@@ -460,7 +516,13 @@ typedef GLXContext ( * PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display* dpy, GLXFBCo
#ifndef GLX_ARB_get_proc_address #ifndef GLX_ARB_get_proc_address
#define GLX_ARB_get_proc_address 1 #define GLX_ARB_get_proc_address 1
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
typedef void* ( * PFNGLXGETPROCADDRESSARBPROC) (const GLubyte *procName);
#define glXGetProcAddressARB GLXEW_GET_FUN(__glewXGetProcAddressARB)
#else//GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
extern void ( * glXGetProcAddressARB (const GLubyte *procName)) (void); extern void ( * glXGetProcAddressARB (const GLubyte *procName)) (void);
#endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#define GLXEW_ARB_get_proc_address GLXEW_GET_VAR(__GLXEW_ARB_get_proc_address) #define GLXEW_ARB_get_proc_address GLXEW_GET_VAR(__GLXEW_ARB_get_proc_address)
@@ -1421,6 +1483,24 @@ typedef int ( * PFNGLXVIDEORESIZESUNPROC) (Display* display, GLXDrawable window,
#define GLXEW_VAR_EXPORT GLEW_VAR_EXPORT #define GLXEW_VAR_EXPORT GLEW_VAR_EXPORT
#endif /* GLEW_MX */ #endif /* GLEW_MX */
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
GLXEW_FUN_EXPORT PFNGLXGETPROCADDRESSARBPROC __glewXGetProcAddressARB;
GLXEW_FUN_EXPORT PFNGLXQUERYEXTENSION __glewXQueryExtension;
GLXEW_FUN_EXPORT PFNGLXQUERYVERSION __glewXQueryVersion;
GLXEW_FUN_EXPORT PFNGLXGETCONFIG __glewXGetConfig;
GLXEW_FUN_EXPORT PFNGLXCHOOSEVISUAL __glewXChooseVisual;
GLXEW_FUN_EXPORT PFNGLXCREATECONTEXT __glewXCreateContext;
GLXEW_FUN_EXPORT PFNGLXDESTROYCONTEXT __glewXDestroyContext;
GLXEW_FUN_EXPORT PFNGLXISDIRECT __glewXIsDirect;
GLXEW_FUN_EXPORT PFNGLXMAKECURRENT __glewXMakeCurrent;
GLXEW_FUN_EXPORT PFNGLXQUERYEXTENSIONSSTRING __glewXQueryExtensionsString;
GLXEW_FUN_EXPORT PFNGLXGETCLIENTSTRING __glewXGetClientString;
GLXEW_FUN_EXPORT PFNGLXQUERYSERVERSTRING __glewXQueryServerString;
GLXEW_FUN_EXPORT PFNGLXSWAPBUFFERS __glewXSwapBuffers;
#endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
GLXEW_FUN_EXPORT PFNGLXGETCURRENTDISPLAYPROC __glewXGetCurrentDisplay; GLXEW_FUN_EXPORT PFNGLXGETCURRENTDISPLAYPROC __glewXGetCurrentDisplay;
GLXEW_FUN_EXPORT PFNGLXCHOOSEFBCONFIGPROC __glewXChooseFBConfig; GLXEW_FUN_EXPORT PFNGLXCHOOSEFBCONFIGPROC __glewXChooseFBConfig;
@@ -1453,6 +1533,7 @@ GLXEW_FUN_EXPORT PFNGLXMAKEASSOCIATEDCONTEXTCURRENTAMDPROC __glewXMakeAssociated
GLXEW_FUN_EXPORT PFNGLXCREATECONTEXTATTRIBSARBPROC __glewXCreateContextAttribsARB; GLXEW_FUN_EXPORT PFNGLXCREATECONTEXTATTRIBSARBPROC __glewXCreateContextAttribsARB;
GLXEW_FUN_EXPORT PFNGLXBINDTEXIMAGEATIPROC __glewXBindTexImageATI; GLXEW_FUN_EXPORT PFNGLXBINDTEXIMAGEATIPROC __glewXBindTexImageATI;
GLXEW_FUN_EXPORT PFNGLXDRAWABLEATTRIBATIPROC __glewXDrawableAttribATI; GLXEW_FUN_EXPORT PFNGLXDRAWABLEATTRIBATIPROC __glewXDrawableAttribATI;
GLXEW_FUN_EXPORT PFNGLXRELEASETEXIMAGEATIPROC __glewXReleaseTexImageATI; GLXEW_FUN_EXPORT PFNGLXRELEASETEXIMAGEATIPROC __glewXReleaseTexImageATI;

View File

@@ -34,7 +34,38 @@
#if defined(_WIN32) #if defined(_WIN32)
# include <GL/wglew.h> # include <GL/wglew.h>
#elif !defined(__ANDROID__) && !defined(__native_client__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX)) #elif !defined(__ANDROID__) && !defined(__native_client__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))
# include <GL/glxew.h> # include "GL/glxew.h"
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
void* dlglXGetProcAddressARB(const GLubyte* name)
{
static void* h = NULL;
static void* gpa;
if (h == NULL)
{
if ((h = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL)) == NULL)
{
return NULL;
}
gpa = dlsym(h, "glXGetProcAddressARB");
}
if (gpa != NULL)
return ((void*(*)(const GLubyte*))gpa)(name);
else
return dlsym(h, (const char*)name);
}
#endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#endif #endif
/* /*
@@ -169,7 +200,11 @@ void* NSGLGetProcAddress (const GLubyte *name)
#elif defined(__native_client__) #elif defined(__native_client__)
# define glewGetProcAddress(name) NULL /* TODO */ # define glewGetProcAddress(name) NULL /* TODO */
#else /* __linux */ #else /* __linux */
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
# define glewGetProcAddress(name) dlglXGetProcAddressARB(name)
#else//GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
# define glewGetProcAddress(name) (*glXGetProcAddressARB)(name) # define glewGetProcAddress(name) (*glXGetProcAddressARB)(name)
#endif//GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#endif #endif
/* /*
@@ -12326,6 +12361,24 @@ GLenum GLEWAPIENTRY wglewContextInit (WGLEW_CONTEXT_ARG_DEF_LIST)
#elif !defined(__ANDROID__) && !defined(__native_client__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX)) #elif !defined(__ANDROID__) && !defined(__native_client__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
PFNGLXGETPROCADDRESSARBPROC __glewXGetProcAddressARB = NULL;
PFNGLXQUERYEXTENSION __glewXQueryExtension=NULL;
PFNGLXQUERYVERSION __glewXQueryVersion=NULL;
PFNGLXGETCONFIG __glewXGetConfig=NULL;
PFNGLXCHOOSEVISUAL __glewXChooseVisual=NULL;
PFNGLXCREATECONTEXT __glewXCreateContext=NULL;
PFNGLXDESTROYCONTEXT __glewXDestroyContext=NULL;
PFNGLXISDIRECT __glewXIsDirect=NULL;
PFNGLXMAKECURRENT __glewXMakeCurrent=NULL;
PFNGLXQUERYEXTENSIONSSTRING __glewXQueryExtensionsString=NULL;
PFNGLXGETCLIENTSTRING __glewXGetClientString=NULL;
PFNGLXQUERYSERVERSTRING __glewXQueryServerString=NULL;
PFNGLXSWAPBUFFERS __glewXSwapBuffers=NULL;
#endif//GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
PFNGLXGETCURRENTDISPLAYPROC __glewXGetCurrentDisplay = NULL; PFNGLXGETCURRENTDISPLAYPROC __glewXGetCurrentDisplay = NULL;
PFNGLXCHOOSEFBCONFIGPROC __glewXChooseFBConfig = NULL; PFNGLXCHOOSEFBCONFIGPROC __glewXChooseFBConfig = NULL;
@@ -13476,6 +13529,34 @@ extern GLenum GLEWAPIENTRY wglewContextInit (void);
extern GLenum GLEWAPIENTRY glxewContextInit (void); extern GLenum GLEWAPIENTRY glxewContextInit (void);
#endif /* _WIN32 */ #endif /* _WIN32 */
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
GLboolean GLEWAPIENTRY glewXInit(void)
{
GLboolean r = GL_FALSE;
r = ((glXGetProcAddressARB = (PFNGLXGETPROCADDRESSARBPROC)dlglXGetProcAddressARB((const GLubyte*)"glXGetProcAddressARB")) == NULL) || r;
r = ((glXQueryExtension = (PFNGLXQUERYEXTENSION)dlglXGetProcAddressARB((const GLubyte*)"glXQueryExtension")) == NULL) || r;
r = ((glXQueryVersion = (PFNGLXQUERYVERSION)dlglXGetProcAddressARB((const GLubyte*)"glXQueryVersion")) == NULL) || r;
r = ((glXGetConfig = (PFNGLXGETCONFIG)dlglXGetProcAddressARB((const GLubyte*)"glXGetConfig")) == NULL) || r;
r = ((glXChooseVisual = (PFNGLXCHOOSEVISUAL)dlglXGetProcAddressARB((const GLubyte*)"glXChooseVisual")) == NULL) || r;
r = ((glXCreateContext = (PFNGLXCREATECONTEXT)dlglXGetProcAddressARB((const GLubyte*)"glXCreateContext")) == NULL) || r;
r = ((glXDestroyContext = (PFNGLXDESTROYCONTEXT)dlglXGetProcAddressARB((const GLubyte*)"glXDestroyContext")) == NULL) || r;
r = ((glXDestroyContext = (PFNGLXDESTROYCONTEXT)dlglXGetProcAddressARB((const GLubyte*)"glXDestroyContext")) == NULL) || r;
r = ((glXIsDirect = (PFNGLXISDIRECT)dlglXGetProcAddressARB((const GLubyte*)"glXIsDirect")) == NULL) || r;
r = ((glXMakeCurrent = (PFNGLXMAKECURRENT)dlglXGetProcAddressARB((const GLubyte*)"glXMakeCurrent")) == NULL) || r;
r = ((glXQueryExtensionsString = (PFNGLXQUERYEXTENSIONSSTRING)dlglXGetProcAddressARB((const GLubyte*)"glXQueryExtensionsString")) == NULL) || r;
r = ((glXGetClientString = (PFNGLXGETCLIENTSTRING)dlglXGetProcAddressARB((const GLubyte*)"glXGetClientString")) == NULL) || r;
r = ((glXQueryServerString = (PFNGLXQUERYSERVERSTRING)dlglXGetProcAddressARB((const GLubyte*)"glXQueryServerString")) == NULL) || r;
r = ((glXSwapBuffers = (PFNGLXSWAPBUFFERS)dlglXGetProcAddressARB((const GLubyte*)"glXSwapBuffers")) == NULL) || r;
//glxewContextInit();
_glewInit_GLX_VERSION_1_3();
if (r==0)
{
printf("glewXInit dynamically loaded using dlopen/dlsym OK\n");
}
return r;
}
#endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#ifdef GLEW_INIT_OPENGL11_FUNCTIONS #ifdef GLEW_INIT_OPENGL11_FUNCTIONS
@@ -14160,6 +14241,10 @@ GLboolean GLEWAPIENTRY glewOpenGL11Init(void)
r = ((glVertexPointer = (PFNGLVERTEXPOINTERPROC)glewGetProcAddress(fqn_from_convention(glew_convention, "glVertexPointer"))) == NULL) || r; r = ((glVertexPointer = (PFNGLVERTEXPOINTERPROC)glewGetProcAddress(fqn_from_convention(glew_convention, "glVertexPointer"))) == NULL) || r;
r = ((glViewport = (PFNGLVIEWPORTPROC)glewGetProcAddress(fqn_from_convention(glew_convention, "glViewport"))) == NULL) || r; r = ((glViewport = (PFNGLVIEWPORTPROC)glewGetProcAddress(fqn_from_convention(glew_convention, "glViewport"))) == NULL) || r;
if (r==0)
{
printf("glewOpenGL11Init dynamically loaded using dlopen/dlsym OK\n");
}
return r; return r;
} }
#endif //GLEW_INIT_OPENGL11_FUNCTIONS #endif //GLEW_INIT_OPENGL11_FUNCTIONS

View File

@@ -27,14 +27,14 @@ subject to the following restrictions:
#include <OpenGL/gl3.h> #include <OpenGL/gl3.h>
#else #else
#include <GL/glew.h> #include "GlewWindows/GL/glew.h"
#ifdef _WINDOWS #ifdef _WINDOWS
#include <windows.h> #include <windows.h>
#include <GL/gl.h> //#include <GL/gl.h>
#include <GL/glu.h> //#include <GL/glu.h>
#else #else
#include <GL/gl.h> //#include <GL/gl.h>
//#include <GL/glu.h> //#include <GL/glu.h>
#endif //_WINDOWS #endif //_WINDOWS
#endif //APPLE #endif //APPLE

View File

@@ -3,12 +3,25 @@
#include<stdio.h> #include<stdio.h>
#include<stdlib.h> #include<stdlib.h>
#include<X11/X.h> #include "GlewWindows/GL/glew.h"
#include<X11/Xlib.h> #ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#include<GL/gl.h> #include "GlewWindows/GL/glxew.h"
#else
#include<GL/glx.h> #include<GL/glx.h>
//#include<GL/glu.h> #endif // GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#include <assert.h>
//#define DYNAMIC_LOAD_X11_FUNCTIONS
#ifdef DYNAMIC_LOAD_X11_FUNCTIONS
#include <dlfcn.h>
#endif //DYNAMIC_LOAD_X11_FUNCTIONS
//#include<X11/X.h>
//#include<X11/Xlib.h>
//#include<GL/gl.h>
//defined in GL/glxew.h
//#include<GL/glu.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -19,6 +32,84 @@
GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
static bool forceOpenGL3 = true; static bool forceOpenGL3 = true;
#ifdef DYNAMIC_LOAD_X11_FUNCTIONS
///our X11 function typedefs
typedef int (*PFNXFREE)(void*);
typedef XErrorHandler (* PFNXSETERRORHANDLER) (XErrorHandler);
typedef int (* PFNXSYNC) (Display* a,Bool b);
typedef Display* (* PFNXOPENDISPLAY) (_Xconst char* a);
typedef Colormap (*PFNXCREATECOLORMAP) (Display* a,Window b,Visual* c,int d);
typedef Window (*PFNXCREATEWINDOW) (Display* a,Window b,int c,int d,unsigned int e,unsigned int f,unsigned int g,int h,unsigned int i,Visual* j,unsigned long k,XSetWindowAttributes* l);
typedef int (*PFNXMAPWINDOW) (Display*, Window);
typedef int (*PFNXSTORENAME) (Display* a,Window b,_Xconst char* c);
typedef int (*PFNXCLOSEDISPLAY) (Display* a);
typedef int (*PFNXDESTROYWINDOW) (Display* a,Window b);
#if NeedWidePrototypes
typedef KeySym (*PFNXKEYCODETOKEYSYM) (Display* a,unsigned int b,int c);
#else
typedef KeySym (*PFNXKEYCODETOKEYSYM) (Display* a,KeyCode b,int c);
#endif
typedef void (*PFNXCONVERTCASE) (KeySym /* sym */,KeySym * /* lower */,KeySym * /* upper */);
typedef int (*PFNXPENDING) (Display* a);
typedef int (*PFNXNEXTEVENT) (Display* a,XEvent* b);
typedef int (*PFNXEVENTSQUEUED) (Display* a,int b);
typedef int (*PFNXPEEKEVENT) (Display* a,XEvent* b);
typedef KeySym (*PFNXLOOKUPKEYSYM) (XKeyEvent* a,int b);
typedef Status (*PFNXGETWINDOWATTRIBUTES) (Display* a,Window b,XWindowAttributes* c);
#define X11_LIBRARY "libX11.so.6"
#define MyXSync m_data->m_x11_XSync
#define MyXSetErrorHandler m_data->m_x11_XSetErrorHandler
#define MyXOpenDisplay m_data->m_x11_XOpenDisplay
#define MyXCreateColormap m_data->m_x11_XCreateColormap
#define MyXCreateWindow m_data->m_x11_XCreateWindow
#define MyXMapWindow m_data->m_x11_XMapWindow
#define MyXStoreName m_data->m_x11_XStoreName
#define MyXDestroyWindow m_data->m_x11_XDestroyWindow
#define MyXCloseDisplay m_data->m_x11_XCloseDisplay
#define MyXKeycodeToKeysym m_data->m_x11_XKeycodeToKeysym
#define MyXConvertCase m_data->m_x11_XConvertCase
#define MyXPending m_data->m_x11_XPending
#define MyXNextEvent m_data->m_x11_XNextEvent
#define MyXEventsQueued m_data->m_x11_XEventsQueued
#define MyXPeekEvent m_data->m_x11_XPeekEvent
#define MyXNextEvent m_data->m_x11_XNextEvent
#define MyXGetWindowAttributes m_data->m_x11_XGetWindowAttributes
#define MyXStoreName m_data->m_x11_XStoreName
#define MyXFree m_data->m_x11_XFree
#define MyXMapWindow m_data->m_x11_XMapWindow
#define MyXStoreName m_data->m_x11_XStoreName
#define MyXLookupKeysym m_data->m_x11_XLookupKeysym
#else
#define MyXSync XSync
#define MyXSetErrorHandler XSetErrorHandler
#define MyXOpenDisplay XOpenDisplay
#define MyXCreateColormap XCreateColormap
#define MyXCreateWindow XCreateWindow
#define MyXMapWindow XMapWindow
#define MyXStoreName XStoreName
#define MyXDestroyWindow XDestroyWindow
#define MyXCloseDisplay XCloseDisplay
#define MyXKeycodeToKeysym XKeycodeToKeysym
#define MyXConvertCase XConvertCase
#define MyXPending XPending
#define MyXNextEvent XNextEvent
#define MyXEventsQueued XEventsQueued
#define MyXPeekEvent XPeekEvent
#define MyXNextEvent XNextEvent
#define MyXGetWindowAttributes XGetWindowAttributes
#define MyXStoreName XStoreName
#define MyXFree XFree
#define MyXMapWindow XMapWindow
#define MyXStoreName XStoreName
#define MyXLookupKeysym XLookupKeysym
#endif//DYNAMIC_LOAD_X11_FUNCTIONS
struct InternalData2 struct InternalData2
{ {
Display* m_dpy; Display* m_dpy;
@@ -32,6 +123,29 @@ struct InternalData2
XEvent m_xev; XEvent m_xev;
GLXFBConfig m_bestFbc; GLXFBConfig m_bestFbc;
#ifdef DYNAMIC_LOAD_X11_FUNCTIONS
//dynamically load stuff
void* m_x11_library;
PFNXFREE m_x11_XFree;
PFNXSETERRORHANDLER m_x11_XSetErrorHandler;
PFNXSYNC m_x11_XSync;
PFNXOPENDISPLAY m_x11_XOpenDisplay;
PFNXCREATECOLORMAP m_x11_XCreateColormap;
PFNXCREATEWINDOW m_x11_XCreateWindow;
PFNXMAPWINDOW m_x11_XMapWindow;
PFNXSTORENAME m_x11_XStoreName;
PFNXCLOSEDISPLAY m_x11_XCloseDisplay;
PFNXDESTROYWINDOW m_x11_XDestroyWindow;
PFNXKEYCODETOKEYSYM m_x11_XKeycodeToKeysym;
PFNXCONVERTCASE m_x11_XConvertCase;
PFNXPENDING m_x11_XPending;
PFNXNEXTEVENT m_x11_XNextEvent;
PFNXEVENTSQUEUED m_x11_XEventsQueued;
PFNXPEEKEVENT m_x11_XPeekEvent;
PFNXLOOKUPKEYSYM m_x11_XLookupKeysym;
PFNXGETWINDOWATTRIBUTES m_x11_XGetWindowAttributes;
#endif //DYNAMIC_LOAD_X11_FUNCTIONS
b3WheelCallback m_wheelCallback; b3WheelCallback m_wheelCallback;
b3MouseMoveCallback m_mouseMoveCallback; b3MouseMoveCallback m_mouseMoveCallback;
b3MouseButtonCallback m_mouseButtonCallback; b3MouseButtonCallback m_mouseButtonCallback;
@@ -47,7 +161,68 @@ struct InternalData2
m_resizeCallback(0), m_resizeCallback(0),
m_keyboardCallback(0) m_keyboardCallback(0)
{ {
#ifdef DYNAMIC_LOAD_X11_FUNCTIONS
m_x11_library = dlopen(X11_LIBRARY, RTLD_LOCAL | RTLD_NOW);
if (!m_x11_library)
{
printf("Error opening X11 library %s\n", X11_LIBRARY);
exit(0);
}
bool missingFunc = false;
missingFunc = ((m_x11_XFree = (PFNXFREE) dlsym(m_x11_library, "XFree"))==NULL) | missingFunc;
assert(!missingFunc);
if (missingFunc) { printf("Error: missing func XFree in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XSetErrorHandler = (PFNXSETERRORHANDLER) dlsym(m_x11_library,"XSetErrorHandler"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XSetErrorHandler in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XSetErrorHandler = (PFNXSETERRORHANDLER) dlsym(m_x11_library,"XSetErrorHandler"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XSetErrorHandler in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XSync = (PFNXSYNC) dlsym(m_x11_library,"XSync"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XSync in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XOpenDisplay = (PFNXOPENDISPLAY) dlsym(m_x11_library,"XOpenDisplay"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XOpenDisplay in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XCreateColormap = (PFNXCREATECOLORMAP) dlsym(m_x11_library,"XCreateColormap"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XCreateColormap in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XCreateWindow = (PFNXCREATEWINDOW) dlsym(m_x11_library,"XCreateWindow"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XCreateWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XMapWindow = (PFNXMAPWINDOW) dlsym(m_x11_library,"XMapWindow"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XMapWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XStoreName = (PFNXSTORENAME) dlsym(m_x11_library,"XStoreName"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XStoreName in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XCloseDisplay = (PFNXCLOSEDISPLAY) dlsym(m_x11_library,"XCloseDisplay"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XCloseDisplay in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XDestroyWindow = (PFNXDESTROYWINDOW) dlsym(m_x11_library,"XDestroyWindow"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XMapWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XKeycodeToKeysym = (PFNXKEYCODETOKEYSYM) dlsym(m_x11_library,"XKeycodeToKeysym"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XKeycodeToKeysym in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XConvertCase = (PFNXCONVERTCASE) dlsym(m_x11_library,"XConvertCase"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XConvertCase in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XPending = (PFNXPENDING) dlsym(m_x11_library,"XPending"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XPending in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XNextEvent = (PFNXNEXTEVENT) dlsym(m_x11_library,"XNextEvent"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XNextEvent in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XEventsQueued = (PFNXEVENTSQUEUED) dlsym(m_x11_library,"XEventsQueued"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XEventsQueued in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XPeekEvent = (PFNXPEEKEVENT) dlsym(m_x11_library,"XPeekEvent"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XPeekEvent in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XLookupKeysym = (PFNXLOOKUPKEYSYM) dlsym(m_x11_library,"XLookupKeysym"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XLookupKeysym in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XGetWindowAttributes = (PFNXGETWINDOWATTRIBUTES) dlsym(m_x11_library,"XGetWindowAttributes"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XGetWindowAttributes in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc)
{
printf("Error: a missing func in %s, exiting!\n", X11_LIBRARY);
exit(0);
} else
{
printf("X11 functions dynamically loaded using dlopen/dlsym OK!\n");
}
#endif //DYNAMIC_LOAD_X11_FUNCTIONS
} }
}; };
@@ -120,6 +295,7 @@ X11OpenGLWindow::~X11OpenGLWindow()
void X11OpenGLWindow::enableOpenGL() void X11OpenGLWindow::enableOpenGL()
{ {
if (forceOpenGL3) if (forceOpenGL3)
{ {
// Get the default screen's GLX extension list // Get the default screen's GLX extension list
@@ -127,7 +303,8 @@ void X11OpenGLWindow::enableOpenGL()
DefaultScreen( m_data->m_dpy ) ); DefaultScreen( m_data->m_dpy ) );
// NOTE: It is not necessary to create or make current to a context before // NOTE: It is not necessary to create or make current to a context before
// calling glXGetProcAddressARB // calling glXGetProcAddressARB, unless we dynamically load OpenGL/GLX/X11
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" ); glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
@@ -142,7 +319,7 @@ void X11OpenGLWindow::enableOpenGL()
// threads issuing X commands while this code is running. // threads issuing X commands while this code is running.
ctxErrorOccurred = false; ctxErrorOccurred = false;
int (*oldHandler)(Display*, XErrorEvent*) = int (*oldHandler)(Display*, XErrorEvent*) =
XSetErrorHandler(&ctxErrorHandler); MyXSetErrorHandler(&ctxErrorHandler);
// Check for the GLX_ARB_create_context extension string and the function. // Check for the GLX_ARB_create_context extension string and the function.
// If either is not present, use GLX 1.3 context creation method. // If either is not present, use GLX 1.3 context creation method.
@@ -178,7 +355,7 @@ void X11OpenGLWindow::enableOpenGL()
True, context_attribs ); True, context_attribs );
// Sync to ensure any errors generated are processed. // Sync to ensure any errors generated are processed.
XSync( m_data->m_dpy, False ); MyXSync( m_data->m_dpy, False );
if ( !ctxErrorOccurred && ctx ) if ( !ctxErrorOccurred && ctx )
printf( "Created GL 3.0 context\n" ); printf( "Created GL 3.0 context\n" );
else else
@@ -202,10 +379,10 @@ void X11OpenGLWindow::enableOpenGL()
} }
// Sync to ensure any errors generated are processed. // Sync to ensure any errors generated are processed.
XSync( m_data->m_dpy, False ); MyXSync( m_data->m_dpy, False );
// Restore the original error handler // Restore the original error handler
XSetErrorHandler( oldHandler ); MyXSetErrorHandler( oldHandler );
if ( ctxErrorOccurred || !ctx ) if ( ctxErrorOccurred || !ctx )
{ {
@@ -231,6 +408,22 @@ void X11OpenGLWindow::enableOpenGL()
m_data->m_glc = glXCreateContext(m_data->m_dpy, m_data->m_vi, NULL, GL_TRUE); m_data->m_glc = glXCreateContext(m_data->m_dpy, m_data->m_vi, NULL, GL_TRUE);
glXMakeCurrent(m_data->m_dpy, m_data->m_win, m_data->m_glc); glXMakeCurrent(m_data->m_dpy, m_data->m_win, m_data->m_glc);
} }
#ifdef GLEW_INIT_OPENGL11_FUNCTIONS
{
GLboolean res = glewOpenGL11Init();
if (res==0)
{
printf("glewOpenGL11Init OK!\n");
} else
{
printf("ERROR: glewOpenGL11Init failed, exiting!\n");
exit(0);
}
}
#endif //GLEW_INIT_OPENGL11_FUNCTIONS
const GLubyte* ven = glGetString(GL_VENDOR); const GLubyte* ven = glGetString(GL_VENDOR);
printf("GL_VENDOR=%s\n", ven); printf("GL_VENDOR=%s\n", ven);
@@ -260,8 +453,8 @@ void X11OpenGLWindow::disableOpenGL()
void X11OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) void X11OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
{ {
printf("createWindow\n");
m_data->m_dpy = XOpenDisplay(NULL); m_data->m_dpy = MyXOpenDisplay(NULL);
if(m_data->m_dpy == NULL) { if(m_data->m_dpy == NULL) {
printf("\n\tcannot connect to X server\n\n"); printf("\n\tcannot connect to X server\n\n");
@@ -270,6 +463,20 @@ printf("createWindow\n");
m_data->m_root = DefaultRootWindow(m_data->m_dpy); m_data->m_root = DefaultRootWindow(m_data->m_dpy);
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
GLboolean res = glewXInit();
if (res==0)
{
printf("glewXInit OK\n");
} else
{
printf("glewXInit failed, exit\n");
exit(0);
}
#endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
if (ci.m_openglVersion < 3) if (ci.m_openglVersion < 3)
{ {
forceOpenGL3 = false; forceOpenGL3 = false;
@@ -328,17 +535,17 @@ printf("createWindow\n");
if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp ) if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp )
worst_fbc = i, worst_num_samp = samples; worst_fbc = i, worst_num_samp = samples;
} }
XFree( vi ); MyXFree( vi );
} }
m_data->m_bestFbc = fbc[ best_fbc ]; m_data->m_bestFbc = fbc[ best_fbc ];
// Be sure to free the FBConfig list allocated by glXChooseFBConfig() // Be sure to free the FBConfig list allocated by glXChooseFBConfig()
XFree( fbc ); MyXFree( fbc );
m_data->m_vi = glXGetVisualFromFBConfig( m_data->m_dpy, m_data->m_bestFbc ); m_data->m_vi = glXGetVisualFromFBConfig( m_data->m_dpy, m_data->m_bestFbc );
m_data->m_swa.colormap = m_data->m_cmap = XCreateColormap( m_data->m_dpy, m_data->m_swa.colormap = m_data->m_cmap = MyXCreateColormap( m_data->m_dpy,
RootWindow( m_data->m_dpy, m_data->m_vi->screen ), RootWindow( m_data->m_dpy, m_data->m_vi->screen ),
m_data->m_vi->visual, AllocNone ); m_data->m_vi->visual, AllocNone );
m_data->m_swa.background_pixmap = None ; m_data->m_swa.background_pixmap = None ;
@@ -347,12 +554,12 @@ printf("createWindow\n");
; ;
m_data->m_root = RootWindow( m_data->m_dpy, m_data->m_vi->screen ); m_data->m_root = RootWindow( m_data->m_dpy, m_data->m_vi->screen );
m_data->m_win = XCreateWindow( m_data->m_dpy, m_data->m_root, m_data->m_win = MyXCreateWindow( m_data->m_dpy, m_data->m_root,
0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput,
m_data->m_vi->visual, m_data->m_vi->visual,
CWBorderPixel|CWColormap|CWEventMask, &m_data->m_swa ); CWBorderPixel|CWColormap|CWEventMask, &m_data->m_swa );
//m_data->m_win = XCreateWindow(m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWColormap | CWEventMask, &m_data->m_swa); //m_data->m_win = m_data->m_x11_XCreateWindow(m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWColormap | CWEventMask, &m_data->m_swa);
if (!m_data->m_win) if (!m_data->m_win)
@@ -361,14 +568,16 @@ printf("createWindow\n");
exit(0); exit(0);
} }
XMapWindow(m_data->m_dpy, m_data->m_win); MyXMapWindow(m_data->m_dpy, m_data->m_win);
XStoreName(m_data->m_dpy, m_data->m_win, "OpenGL3 Window"); MyXStoreName(m_data->m_dpy, m_data->m_win, "OpenGL3 Window");
} else } else
{ {
m_data->m_vi = glXChooseVisual(m_data->m_dpy, 0, att); m_data->m_vi = glXChooseVisual(m_data->m_dpy, 0, att);
printf("4\n");
if(m_data->m_vi == NULL) { if(m_data->m_vi == NULL) {
printf("\n\tno appropriate visual found\n\n"); printf("\n\tno appropriate visual found\n\n");
exit(0); exit(0);
@@ -378,16 +587,18 @@ printf("createWindow\n");
} }
m_data->m_cmap = XCreateColormap(m_data->m_dpy, m_data->m_root, m_data->m_vi->visual, AllocNone); m_data->m_cmap = MyXCreateColormap(m_data->m_dpy, m_data->m_root, m_data->m_vi->visual, AllocNone);
m_data->m_swa.colormap = m_data->m_cmap; m_data->m_swa.colormap = m_data->m_cmap;
m_data->m_swa.event_mask = ExposureMask | KeyReleaseMask | KeyPressMask |ButtonPressMask | ButtonReleaseMask |PointerMotionMask|StructureNotifyMask; m_data->m_swa.event_mask = ExposureMask | KeyReleaseMask | KeyPressMask |ButtonPressMask | ButtonReleaseMask |PointerMotionMask|StructureNotifyMask;
m_data->m_win = MyXCreateWindow(m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWColormap | CWEventMask, &m_data->m_swa);
MyXMapWindow(m_data->m_dpy, m_data->m_win);
MyXStoreName(m_data->m_dpy, m_data->m_win, "OpenGL2 Window");
m_data->m_win = XCreateWindow(m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWColormap | CWEventMask, &m_data->m_swa);
XMapWindow(m_data->m_dpy, m_data->m_win);
XStoreName(m_data->m_dpy, m_data->m_win, "OpenGL3 Window");
} }
enableOpenGL(); enableOpenGL();
} }
@@ -395,15 +606,15 @@ void X11OpenGLWindow::closeWindow()
{ {
disableOpenGL(); disableOpenGL();
XDestroyWindow(m_data->m_dpy, m_data->m_win); MyXDestroyWindow(m_data->m_dpy, m_data->m_win);
XCloseDisplay(m_data->m_dpy); MyXCloseDisplay(m_data->m_dpy);
} }
int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode) int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode)
{ {
KeySym key, key_lc, key_uc; KeySym key, key_lc, key_uc;
key = XKeycodeToKeysym( m_data->m_dpy, keycode, 0 ); key = MyXKeycodeToKeysym( m_data->m_dpy, keycode, 0 );
switch( key ) switch( key )
{ {
case XK_Escape: return B3G_ESCAPE; case XK_Escape: return B3G_ESCAPE;
@@ -442,7 +653,7 @@ int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode)
case XK_F15: return B3G_F15; case XK_F15: return B3G_F15;
default: default:
// Make uppercase // Make uppercase
XConvertCase( key, &key_lc, &key_uc ); MyXConvertCase( key, &key_lc, &key_uc );
key = key_uc; key = key_uc;
// Valid ISO 8859-1 character? // Valid ISO 8859-1 character?
if( (key >= 32 && key <= 126) ||(key >= 160 && key <= 255) ) if( (key >= 32 && key <= 126) ||(key >= 160 && key <= 255) )
@@ -460,9 +671,9 @@ void X11OpenGLWindow::pumpMessage()
int buttonState = 1; int buttonState = 1;
// Process all pending events // Process all pending events
while( XPending( m_data->m_dpy ) ) while( MyXPending( m_data->m_dpy ) )
{ {
XNextEvent(m_data->m_dpy, &m_data->m_xev); MyXNextEvent(m_data->m_dpy, &m_data->m_xev);
// printf("#"); // printf("#");
// fflush(stdout); // fflush(stdout);
switch( m_data->m_xev.type ) switch( m_data->m_xev.type )
@@ -491,19 +702,19 @@ void X11OpenGLWindow::pumpMessage()
unsigned short is_retriggered = 0; unsigned short is_retriggered = 0;
///filter out keyboard repeat ///filter out keyboard repeat
//see http://stackoverflow.com/questions/2100654/ignore-auto-repeat-in-x11-applications //see http://stackoverflow.com/questions/2100654/ignore-auto-repeat-in-x11-applications
if (XEventsQueued(m_data->m_dpy, QueuedAfterReading)) if (MyXEventsQueued(m_data->m_dpy, QueuedAfterReading))
{ {
XEvent nev; XEvent nev;
XPeekEvent(m_data->m_dpy, &nev); MyXPeekEvent(m_data->m_dpy, &nev);
if (nev.type == KeyPress && nev.xkey.time == m_data->m_xev.xkey.time && if (nev.type == KeyPress && nev.xkey.time == m_data->m_xev.xkey.time &&
nev.xkey.keycode == m_data->m_xev.xkey.keycode) nev.xkey.keycode == m_data->m_xev.xkey.keycode)
{ {
fprintf (stdout, "key #%ld was retriggered.\n", fprintf (stdout, "key #%ld was retriggered.\n",
(long) XLookupKeysym (&nev.xkey, 0)); (long) MyXLookupKeysym(&nev.xkey, 0));
// delete retriggered KeyPress event // delete retriggered KeyPress event
XNextEvent (m_data->m_dpy, & m_data->m_xev); MyXNextEvent(m_data->m_dpy, & m_data->m_xev);
is_retriggered = 1; is_retriggered = 1;
} }
} }
@@ -620,7 +831,7 @@ void X11OpenGLWindow::startRendering()
{ {
pumpMessage(); pumpMessage();
XGetWindowAttributes(m_data->m_dpy, m_data->m_win, &m_data->m_gwa); MyXGetWindowAttributes(m_data->m_dpy, m_data->m_win, &m_data->m_gwa);
glViewport(0, 0, m_data->m_gwa.width, m_data->m_gwa.height); glViewport(0, 0, m_data->m_gwa.width, m_data->m_gwa.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear buffers
@@ -667,7 +878,7 @@ void X11OpenGLWindow::setRenderCallback( b3RenderCallback renderCallback)
void X11OpenGLWindow::setWindowTitle(const char* title) void X11OpenGLWindow::setWindowTitle(const char* title)
{ {
XStoreName(m_data->m_dpy, m_data->m_win, title); MyXStoreName(m_data->m_dpy, m_data->m_win, title);
} }