Skip to content

Commit

Permalink
Try to load versioned GLUT library, too. Bumped version to 2.7.0.11.
Browse files Browse the repository at this point in the history
  • Loading branch information
svenpanne committed Jan 26, 2017
1 parent aafadc5 commit a386914
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.7.0.11
--------
* Linux: Try to load versioned GLUT library, too, because the unversioned one is often in *-dev packages only.

2.7.0.10
--------
* Mac OS X: Search public frameworks first, then system frameworks.
Expand Down
2 changes: 1 addition & 1 deletion GLUT.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: GLUT
version: 2.7.0.10
version: 2.7.0.11
synopsis: A binding for the OpenGL Utility Toolkit
description:
A Haskell binding for the OpenGL Utility Toolkit, a window system independent
Expand Down
51 changes: 27 additions & 24 deletions cbits/HsGLUT.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

static LPCTSTR libNames[] = {
/* Try to load freeglut first, it has a few extra features compared to classic
GLUT. */
TEXT("freeglut"),
/* The MinGW-w64 version of freeglut prefixes "lib" onto the DLL name. */
TEXT("libfreeglut"),
/* If no freeglut version is found, try plain old glut32 instead. */
TEXT("glut32")
};

void*
hs_GLUT_getProcAddress(const char *name)
{
static int firstTime = 1;
static HMODULE handle = NULL;

if (firstTime) {
int i, numNames = (int)(sizeof(libNames) / sizeof(libNames[0]));
firstTime = 0;

/* Try to load freeglut first, it has a few extra features compared to
classic GLUT. */
handle = LoadLibrary(TEXT("freeglut"));

/* The MinGW-w64 version of freeglut prefixes "lib" onto the DLL name. */
if (!handle) {
handle = LoadLibrary(TEXT("libfreeglut"));
}

/* If no freeglut version is found, try plain old glut32 instead. */
if (!handle) {
handle = LoadLibrary(TEXT("glut32"));
for (i = 0; (!handle) && (i < numNames); ++i) {
handle = LoadLibrary(libNames[i]);
}
}

Expand All @@ -48,26 +48,29 @@ hs_GLUT_getProcAddress(const char *name)
#include <stdlib.h>
#include <dlfcn.h>

static const char* libNames[] = {
#ifdef __APPLE__
/* Try public framework path first. */
"/Library/Frameworks/GLUT.framework/GLUT",
/* If the public path failed, try the system framework path. */
"/System/Library/Frameworks/GLUT.framework/GLUT"
#else
"libglut.so", "libglut.so.3"
#endif
};

void*
hs_GLUT_getProcAddress(const char *name)
{
static int firstTime = 1;
static void *handle = NULL;

if (firstTime) {
int i, numNames = (int)(sizeof(libNames) / sizeof(libNames[0]));
firstTime = 0;

#ifdef __APPLE__
/* Try public framework path first. */
handle = dlopen("/Library/Frameworks/GLUT.framework/GLUT", RTLD_LAZY | RTLD_GLOBAL);

/* If the public path failed, try the system framework path. */
if (!handle) {
handle = dlopen("/System/Library/Frameworks/GLUT.framework/GLUT", RTLD_LAZY | RTLD_GLOBAL);
for (i = 0; (!handle) && (i < numNames); ++i) {
handle = dlopen(libNames[i], RTLD_LAZY | RTLD_GLOBAL);
}
#else
handle = dlopen("libglut.so", RTLD_LAZY | RTLD_GLOBAL);
#endif
}

return handle ? dlsym(handle, name) : NULL;
Expand Down

0 comments on commit a386914

Please sign in to comment.