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:
@@ -3,12 +3,25 @@
|
||||
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<X11/X.h>
|
||||
#include<X11/Xlib.h>
|
||||
#include<GL/gl.h>
|
||||
#include "GlewWindows/GL/glew.h"
|
||||
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
|
||||
#include "GlewWindows/GL/glxew.h"
|
||||
#else
|
||||
#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 <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -19,6 +32,84 @@
|
||||
GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
|
||||
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
|
||||
{
|
||||
Display* m_dpy;
|
||||
@@ -32,7 +123,30 @@ struct InternalData2
|
||||
XEvent m_xev;
|
||||
GLXFBConfig m_bestFbc;
|
||||
|
||||
b3WheelCallback m_wheelCallback;
|
||||
#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;
|
||||
b3MouseMoveCallback m_mouseMoveCallback;
|
||||
b3MouseButtonCallback m_mouseButtonCallback;
|
||||
b3ResizeCallback m_resizeCallback;
|
||||
@@ -47,7 +161,68 @@ struct InternalData2
|
||||
m_resizeCallback(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()
|
||||
{
|
||||
|
||||
|
||||
if (forceOpenGL3)
|
||||
{
|
||||
// Get the default screen's GLX extension list
|
||||
@@ -127,7 +303,8 @@ void X11OpenGLWindow::enableOpenGL()
|
||||
DefaultScreen( m_data->m_dpy ) );
|
||||
|
||||
// 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;
|
||||
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
|
||||
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
|
||||
@@ -142,7 +319,7 @@ void X11OpenGLWindow::enableOpenGL()
|
||||
// threads issuing X commands while this code is running.
|
||||
ctxErrorOccurred = false;
|
||||
int (*oldHandler)(Display*, XErrorEvent*) =
|
||||
XSetErrorHandler(&ctxErrorHandler);
|
||||
MyXSetErrorHandler(&ctxErrorHandler);
|
||||
|
||||
// Check for the GLX_ARB_create_context extension string and the function.
|
||||
// If either is not present, use GLX 1.3 context creation method.
|
||||
@@ -178,7 +355,7 @@ void X11OpenGLWindow::enableOpenGL()
|
||||
True, context_attribs );
|
||||
|
||||
// Sync to ensure any errors generated are processed.
|
||||
XSync( m_data->m_dpy, False );
|
||||
MyXSync( m_data->m_dpy, False );
|
||||
if ( !ctxErrorOccurred && ctx )
|
||||
printf( "Created GL 3.0 context\n" );
|
||||
else
|
||||
@@ -202,10 +379,10 @@ void X11OpenGLWindow::enableOpenGL()
|
||||
}
|
||||
|
||||
// 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
|
||||
XSetErrorHandler( oldHandler );
|
||||
MyXSetErrorHandler( oldHandler );
|
||||
|
||||
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);
|
||||
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);
|
||||
printf("GL_VENDOR=%s\n", ven);
|
||||
|
||||
@@ -260,8 +453,8 @@ void X11OpenGLWindow::disableOpenGL()
|
||||
|
||||
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) {
|
||||
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);
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
forceOpenGL3 = false;
|
||||
@@ -312,33 +519,33 @@ printf("createWindow\n");
|
||||
int i;
|
||||
for (i=0; i<fbcount; ++i)
|
||||
{
|
||||
XVisualInfo *vi = glXGetVisualFromFBConfig( m_data->m_dpy, fbc[i] );
|
||||
if ( vi )
|
||||
{
|
||||
int samp_buf, samples;
|
||||
glXGetFBConfigAttrib( m_data->m_dpy, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf );
|
||||
glXGetFBConfigAttrib( m_data->m_dpy, fbc[i], GLX_SAMPLES , &samples );
|
||||
XVisualInfo *vi = glXGetVisualFromFBConfig( m_data->m_dpy, fbc[i] );
|
||||
if ( vi )
|
||||
{
|
||||
int samp_buf, samples;
|
||||
glXGetFBConfigAttrib( m_data->m_dpy, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf );
|
||||
glXGetFBConfigAttrib( m_data->m_dpy, fbc[i], GLX_SAMPLES , &samples );
|
||||
|
||||
//printf( " Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d,"
|
||||
// " SAMPLES = %d\n",
|
||||
// i, vi -> visualid, samp_buf, samples );
|
||||
//printf( " Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d,"
|
||||
// " SAMPLES = %d\n",
|
||||
// i, vi -> visualid, samp_buf, samples );
|
||||
|
||||
if ( best_fbc < 0 || samp_buf && samples > best_num_samp )
|
||||
best_fbc = i, best_num_samp = samples;
|
||||
if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp )
|
||||
worst_fbc = i, worst_num_samp = samples;
|
||||
}
|
||||
XFree( vi );
|
||||
if ( best_fbc < 0 || samp_buf && samples > best_num_samp )
|
||||
best_fbc = i, best_num_samp = samples;
|
||||
if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp )
|
||||
worst_fbc = i, worst_num_samp = samples;
|
||||
}
|
||||
MyXFree( vi );
|
||||
}
|
||||
|
||||
m_data->m_bestFbc = fbc[ best_fbc ];
|
||||
// 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_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 ),
|
||||
m_data->m_vi->visual, AllocNone );
|
||||
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_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,
|
||||
m_data->m_vi->visual,
|
||||
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)
|
||||
@@ -361,14 +568,16 @@ printf("createWindow\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
XMapWindow(m_data->m_dpy, m_data->m_win);
|
||||
XStoreName(m_data->m_dpy, m_data->m_win, "OpenGL3 Window");
|
||||
MyXMapWindow(m_data->m_dpy, m_data->m_win);
|
||||
MyXStoreName(m_data->m_dpy, m_data->m_win, "OpenGL3 Window");
|
||||
|
||||
|
||||
} else
|
||||
{
|
||||
m_data->m_vi = glXChooseVisual(m_data->m_dpy, 0, att);
|
||||
|
||||
printf("4\n");
|
||||
|
||||
if(m_data->m_vi == NULL) {
|
||||
printf("\n\tno appropriate visual found\n\n");
|
||||
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.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();
|
||||
}
|
||||
|
||||
@@ -395,15 +606,15 @@ void X11OpenGLWindow::closeWindow()
|
||||
{
|
||||
disableOpenGL();
|
||||
|
||||
XDestroyWindow(m_data->m_dpy, m_data->m_win);
|
||||
XCloseDisplay(m_data->m_dpy);
|
||||
MyXDestroyWindow(m_data->m_dpy, m_data->m_win);
|
||||
MyXCloseDisplay(m_data->m_dpy);
|
||||
}
|
||||
|
||||
int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode)
|
||||
{
|
||||
KeySym key, key_lc, key_uc;
|
||||
|
||||
key = XKeycodeToKeysym( m_data->m_dpy, keycode, 0 );
|
||||
key = MyXKeycodeToKeysym( m_data->m_dpy, keycode, 0 );
|
||||
switch( key )
|
||||
{
|
||||
case XK_Escape: return B3G_ESCAPE;
|
||||
@@ -442,7 +653,7 @@ int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode)
|
||||
case XK_F15: return B3G_F15;
|
||||
default:
|
||||
// Make uppercase
|
||||
XConvertCase( key, &key_lc, &key_uc );
|
||||
MyXConvertCase( key, &key_lc, &key_uc );
|
||||
key = key_uc;
|
||||
// Valid ISO 8859-1 character?
|
||||
if( (key >= 32 && key <= 126) ||(key >= 160 && key <= 255) )
|
||||
@@ -460,9 +671,9 @@ void X11OpenGLWindow::pumpMessage()
|
||||
int buttonState = 1;
|
||||
|
||||
// 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("#");
|
||||
// fflush(stdout);
|
||||
switch( m_data->m_xev.type )
|
||||
@@ -491,19 +702,19 @@ void X11OpenGLWindow::pumpMessage()
|
||||
unsigned short is_retriggered = 0;
|
||||
///filter out keyboard repeat
|
||||
//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;
|
||||
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 &&
|
||||
nev.xkey.keycode == m_data->m_xev.xkey.keycode)
|
||||
{
|
||||
fprintf (stdout, "key #%ld was retriggered.\n",
|
||||
(long) XLookupKeysym (&nev.xkey, 0));
|
||||
(long) MyXLookupKeysym(&nev.xkey, 0));
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -620,7 +831,7 @@ void X11OpenGLWindow::startRendering()
|
||||
{
|
||||
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);
|
||||
|
||||
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)
|
||||
{
|
||||
XStoreName(m_data->m_dpy, m_data->m_win, title);
|
||||
MyXStoreName(m_data->m_dpy, m_data->m_win, title);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user