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+
1828void *
1929hs_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+
5162void *
5263hs_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