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

@@ -6,8 +6,8 @@ Copyright (c) 2003-2014 Erwin Coumans http://bulletphysics.org
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
@@ -133,7 +133,7 @@ int main(int argc, char* argv[])
window->setMouseMoveCallback(MyMouseMoveCallback);
window->setKeyboardCallback(MyKeyboardCallback);
//window->setWindowTitle("render test");
// window->setWindowTitle("render test");
int majorGlVersion, minorGlVersion;
@@ -153,7 +153,7 @@ int main(int argc, char* argv[])
#endif // _WIN32
glewInit();
#endif
//we ned to call glGetError twice, because of some Ubuntu/Intel/OpenGL issue
GLuint err = glGetError();
@@ -181,7 +181,7 @@ int main(int argc, char* argv[])
}
// glClearColor(0.2,0.2,0.2,1);
@@ -189,9 +189,9 @@ int main(int argc, char* argv[])
BasicDemoPhysicsSetup physicsSetup;
GraphicsPhysicsBridge br;
physicsSetup.initPhysics(br);
struct MyAppie : public DemoApplication
struct MyAppie : public DemoApplication
{
virtual void initPhysics()
{
@@ -210,7 +210,7 @@ int main(int argc, char* argv[])
if (isCtrlPressed)
m_modifierKeys |= BT_ACTIVE_CTRL;
if (isShiftPressed)
m_modifierKeys |= BT_ACTIVE_SHIFT;
@@ -228,8 +228,8 @@ int main(int argc, char* argv[])
physicsSetup.m_dynamicsWorld->setDebugDrawer(&draw);
btClock timer;
unsigned long prevTime = timer.getTimeMicroseconds();
do
do
{
unsigned long curTime = timer.getTimeMicroseconds();
if (!appie.isIdle())
@@ -242,7 +242,7 @@ int main(int argc, char* argv[])
appie.renderme();
physicsSetup.m_dynamicsWorld->debugDrawWorld();
window->endRendering();
} while (!window->requestedExit());
}
window->closeWindow();
@@ -252,4 +252,4 @@ int main(int argc, char* argv[])
printf("hello\n");
}
}

View File

@@ -4,24 +4,24 @@
** Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
** Copyright (C) 2002, Lev Povalahev
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
@@ -31,6 +31,7 @@
#define GLEW_NO_GLU
//#define GLEW_INIT_OPENGL11_FUNCTIONS 1
//#define GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS 1
/*
* Mesa 3-D graphics library
@@ -58,7 +59,7 @@
/*
** Copyright (c) 2007 The Khronos Group Inc.
**
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
@@ -66,10 +67,10 @@
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -19061,6 +19062,10 @@ GLEWAPI const GLubyte * GLEWAPIENTRY glewGetString (GLenum name);
GLEWAPI GLboolean GLEWAPIENTRY glewOpenGL11Init(void);
#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
}
#endif

View File

@@ -4,24 +4,24 @@
** Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
** Copyright (C) 2002, Lev Povalahev
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
@@ -55,7 +55,7 @@
/*
** Copyright (c) 2007 The Khronos Group Inc.
**
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
@@ -63,10 +63,10 @@
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -97,7 +97,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xmd.h>
#include <GL/glew.h>
#include "glew.h"
#ifdef __cplusplus
extern "C" {
@@ -141,8 +141,50 @@ typedef struct __glXContextRec *GLXContext;
typedef struct __GLXcontextRec *GLXContext;
#endif
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 glXQueryVersion (Display *dpy, int *major, int *minor);
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 glXSwapBuffers (Display *dpy, GLXDrawable drawable);
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)
@@ -174,9 +217,22 @@ extern void glXUseXFont (Font font, int first, int count, int listBase);
#define GLX_VERSION 0x2
#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* glXGetClientString (Display *dpy, 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)
@@ -263,21 +319,21 @@ typedef XID GLXWindow;
typedef struct __GLXFBConfigRec *GLXFBConfig;
typedef struct {
int event_type;
int draw_type;
unsigned long serial;
Bool send_event;
Display *display;
GLXDrawable drawable;
unsigned int buffer_mask;
unsigned int aux_buffer;
int x, y;
int width, height;
int count;
int event_type;
int draw_type;
unsigned long serial;
Bool send_event;
Display *display;
GLXDrawable drawable;
unsigned int buffer_mask;
unsigned int aux_buffer;
int x, y;
int width, height;
int count;
} GLXPbufferClobberEvent;
typedef union __GLXEvent {
GLXPbufferClobberEvent glxpbufferclobber;
long pad[24];
GLXPbufferClobberEvent glxpbufferclobber;
long pad[24];
} GLXEvent;
typedef GLXFBConfig* ( * PFNGLXCHOOSEFBCONFIGPROC) (Display *dpy, int screen, const int *attrib_list, int *nelements);
@@ -460,7 +516,13 @@ typedef GLXContext ( * PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display* dpy, GLXFBCo
#ifndef GLX_ARB_get_proc_address
#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);
#endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#define GLXEW_ARB_get_proc_address GLXEW_GET_VAR(__GLXEW_ARB_get_proc_address)
@@ -1161,32 +1223,32 @@ typedef XVisualInfo* ( * PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) (Display *dpy, GLX
#define GLX_HYPERPIPE_ID_SGIX 0x8030
typedef struct {
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int networkId;
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int networkId;
} GLXHyperpipeNetworkSGIX;
typedef struct {
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int XOrigin;
int YOrigin;
int maxHeight;
int maxWidth;
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int XOrigin;
int YOrigin;
int maxHeight;
int maxWidth;
} GLXPipeRectLimits;
typedef struct {
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int channel;
unsigned int participationType;
int timeSlice;
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int channel;
unsigned int participationType;
int timeSlice;
} GLXHyperpipeConfigSGIX;
typedef struct {
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int srcXOrigin;
int srcYOrigin;
int srcWidth;
int srcHeight;
int destXOrigin;
int destYOrigin;
int destWidth;
int destHeight;
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int srcXOrigin;
int srcYOrigin;
int srcWidth;
int srcHeight;
int destXOrigin;
int destYOrigin;
int destWidth;
int destHeight;
} GLXPipeRect;
typedef int ( * PFNGLXBINDHYPERPIPESGIXPROC) (Display *dpy, int hpId);
@@ -1421,6 +1483,24 @@ typedef int ( * PFNGLXVIDEORESIZESUNPROC) (Display* display, GLXDrawable window,
#define GLXEW_VAR_EXPORT GLEW_VAR_EXPORT
#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 PFNGLXCHOOSEFBCONFIGPROC __glewXChooseFBConfig;
@@ -1453,6 +1533,7 @@ GLXEW_FUN_EXPORT PFNGLXMAKEASSOCIATEDCONTEXTCURRENTAMDPROC __glewXMakeAssociated
GLXEW_FUN_EXPORT PFNGLXCREATECONTEXTATTRIBSARBPROC __glewXCreateContextAttribsARB;
GLXEW_FUN_EXPORT PFNGLXBINDTEXIMAGEATIPROC __glewXBindTexImageATI;
GLXEW_FUN_EXPORT PFNGLXDRAWABLEATTRIBATIPROC __glewXDrawableAttribATI;
GLXEW_FUN_EXPORT PFNGLXRELEASETEXIMAGEATIPROC __glewXReleaseTexImageATI;

View File

@@ -4,24 +4,24 @@
** Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
** Copyright (C) 2002, Lev Povalahev
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
@@ -34,7 +34,38 @@
#if defined(_WIN32)
# include <GL/wglew.h>
#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
/*
@@ -102,7 +133,7 @@ void* NSGLGetProcAddress (const GLubyte *name)
{
static void* image = NULL;
void* addr;
if (NULL == image)
if (NULL == image)
{
#ifdef GLEW_REGAL
image = dlopen("libRegal.dylib", RTLD_LAZY);
@@ -169,7 +200,11 @@ void* NSGLGetProcAddress (const GLubyte *name)
#elif defined(__native_client__)
# define glewGetProcAddress(name) NULL /* TODO */
#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)
#endif//GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#endif
/*
@@ -9469,7 +9504,7 @@ static GLboolean _glewInit_GL_WIN_swap_hint (GLEW_CONTEXT_ARG_DEF_INIT)
/* ------------------------------------------------------------------------- */
GLboolean GLEWAPIENTRY glewGetExtension (const char* name)
{
{
const GLubyte* start;
const GLubyte* end;
start = (const GLubyte*)glGetString(GL_EXTENSIONS);
@@ -9496,7 +9531,7 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST)
dot = _glewStrCLen(s, '.');
if (dot == 0)
return GLEW_ERROR_NO_GL_VERSION;
major = s[dot-1]-'0';
minor = s[dot+1]-'0';
@@ -9504,7 +9539,7 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST)
minor = 0;
if (major<0 || major>9)
return GLEW_ERROR_NO_GL_VERSION;
if (major == 1 && minor == 0)
{
@@ -9521,12 +9556,12 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST)
CONST_CAST(GLEW_VERSION_3_2) = GLEW_VERSION_3_3 == GL_TRUE || ( major == 3 && minor >= 2 ) ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_3_1) = GLEW_VERSION_3_2 == GL_TRUE || ( major == 3 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_3_0) = GLEW_VERSION_3_1 == GL_TRUE || ( major == 3 ) ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_2_1) = GLEW_VERSION_3_0 == GL_TRUE || ( major == 2 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_2_1) = GLEW_VERSION_3_0 == GL_TRUE || ( major == 2 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_2_0) = GLEW_VERSION_2_1 == GL_TRUE || ( major == 2 ) ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_1_5) = GLEW_VERSION_2_0 == GL_TRUE || ( major == 1 && minor >= 5 ) ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_1_4) = GLEW_VERSION_1_5 == GL_TRUE || ( major == 1 && minor >= 4 ) ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_1_3) = GLEW_VERSION_1_4 == GL_TRUE || ( major == 1 && minor >= 3 ) ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_1_2_1) = GLEW_VERSION_1_3 == GL_TRUE ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_1_2_1) = GLEW_VERSION_1_3 == GL_TRUE ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_1_2) = GLEW_VERSION_1_2_1 == GL_TRUE || ( major == 1 && minor >= 2 ) ? GL_TRUE : GL_FALSE;
CONST_CAST(GLEW_VERSION_1_1) = GLEW_VERSION_1_2 == GL_TRUE || ( major == 1 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
}
@@ -12099,7 +12134,7 @@ static PFNWGLGETEXTENSIONSSTRINGARBPROC _wglewGetExtensionsStringARB = NULL;
static PFNWGLGETEXTENSIONSSTRINGEXTPROC _wglewGetExtensionsStringEXT = NULL;
GLboolean GLEWAPIENTRY wglewGetExtension (const char* name)
{
{
const GLubyte* start;
const GLubyte* end;
if (_wglewGetExtensionsStringARB == NULL)
@@ -12326,6 +12361,24 @@ GLenum GLEWAPIENTRY wglewContextInit (WGLEW_CONTEXT_ARG_DEF_LIST)
#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;
PFNGLXCHOOSEFBCONFIGPROC __glewXChooseFBConfig = NULL;
@@ -13164,7 +13217,7 @@ static GLboolean _glewInit_GLX_SUN_video_resize (GLXEW_CONTEXT_ARG_DEF_INIT)
/* ------------------------------------------------------------------------ */
GLboolean glxewGetExtension (const char* name)
{
{
const GLubyte* start;
const GLubyte* end;
@@ -13476,6 +13529,34 @@ extern GLenum GLEWAPIENTRY wglewContextInit (void);
extern GLenum GLEWAPIENTRY glxewContextInit (void);
#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
@@ -14160,6 +14241,10 @@ GLboolean GLEWAPIENTRY glewOpenGL11Init(void)
r = ((glVertexPointer = (PFNGLVERTEXPOINTERPROC)glewGetProcAddress(fqn_from_convention(glew_convention, "glVertexPointer"))) == 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;
}
#endif //GLEW_INIT_OPENGL11_FUNCTIONS

View File

@@ -1,10 +1,10 @@
/*
Copyright (c) 2012 Advanced Micro Devices, Inc.
Copyright (c) 2012 Advanced Micro Devices, Inc.
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
@@ -27,14 +27,14 @@ subject to the following restrictions:
#include <OpenGL/gl3.h>
#else
#include <GL/glew.h>
#include "GlewWindows/GL/glew.h"
#ifdef _WINDOWS
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
//#include <GL/gl.h>
//#include <GL/glu.h>
#else
#include <GL/gl.h>
//#include <GL/gl.h>
//#include <GL/glu.h>
#endif //_WINDOWS
#endif //APPLE

View File

@@ -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);
}