Skip to content

Commit a386914

Browse files
committed
Try to load versioned GLUT library, too. Bumped version to 2.7.0.11.
1 parent aafadc5 commit a386914

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.7.0.11
2+
--------
3+
* Linux: Try to load versioned GLUT library, too, because the unversioned one is often in *-dev packages only.
4+
15
2.7.0.10
26
--------
37
* Mac OS X: Search public frameworks first, then system frameworks.

GLUT.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: GLUT
2-
version: 2.7.0.10
2+
version: 2.7.0.11
33
synopsis: A binding for the OpenGL Utility Toolkit
44
description:
55
A Haskell binding for the OpenGL Utility Toolkit, a window system independent

cbits/HsGLUT.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@
1515
#define WIN32_LEAN_AND_MEAN
1616
#include <windows.h>
1717

18+
static LPCTSTR libNames[] = {
19+
/* Try to load freeglut first, it has a few extra features compared to classic
20+
GLUT. */
21+
TEXT("freeglut"),
22+
/* The MinGW-w64 version of freeglut prefixes "lib" onto the DLL name. */
23+
TEXT("libfreeglut"),
24+
/* If no freeglut version is found, try plain old glut32 instead. */
25+
TEXT("glut32")
26+
};
27+
1828
void*
1929
hs_GLUT_getProcAddress(const char *name)
2030
{
2131
static int firstTime = 1;
2232
static HMODULE handle = NULL;
2333

2434
if (firstTime) {
35+
int i, numNames = (int)(sizeof(libNames) / sizeof(libNames[0]));
2536
firstTime = 0;
26-
27-
/* Try to load freeglut first, it has a few extra features compared to
28-
classic GLUT. */
29-
handle = LoadLibrary(TEXT("freeglut"));
30-
31-
/* The MinGW-w64 version of freeglut prefixes "lib" onto the DLL name. */
32-
if (!handle) {
33-
handle = LoadLibrary(TEXT("libfreeglut"));
34-
}
35-
36-
/* If no freeglut version is found, try plain old glut32 instead. */
37-
if (!handle) {
38-
handle = LoadLibrary(TEXT("glut32"));
37+
for (i = 0; (!handle) && (i < numNames); ++i) {
38+
handle = LoadLibrary(libNames[i]);
3939
}
4040
}
4141

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

51+
static const char* libNames[] = {
52+
#ifdef __APPLE__
53+
/* Try public framework path first. */
54+
"/Library/Frameworks/GLUT.framework/GLUT",
55+
/* If the public path failed, try the system framework path. */
56+
"/System/Library/Frameworks/GLUT.framework/GLUT"
57+
#else
58+
"libglut.so", "libglut.so.3"
59+
#endif
60+
};
61+
5162
void*
5263
hs_GLUT_getProcAddress(const char *name)
5364
{
5465
static int firstTime = 1;
5566
static void *handle = NULL;
5667

5768
if (firstTime) {
69+
int i, numNames = (int)(sizeof(libNames) / sizeof(libNames[0]));
5870
firstTime = 0;
59-
60-
#ifdef __APPLE__
61-
/* Try public framework path first. */
62-
handle = dlopen("/Library/Frameworks/GLUT.framework/GLUT", RTLD_LAZY | RTLD_GLOBAL);
63-
64-
/* If the public path failed, try the system framework path. */
65-
if (!handle) {
66-
handle = dlopen("/System/Library/Frameworks/GLUT.framework/GLUT", RTLD_LAZY | RTLD_GLOBAL);
71+
for (i = 0; (!handle) && (i < numNames); ++i) {
72+
handle = dlopen(libNames[i], RTLD_LAZY | RTLD_GLOBAL);
6773
}
68-
#else
69-
handle = dlopen("libglut.so", RTLD_LAZY | RTLD_GLOBAL);
70-
#endif
7174
}
7275

7376
return handle ? dlsym(handle, name) : NULL;

0 commit comments

Comments
 (0)