[m-rev.] diff: make opengl and glut bindings work on OS X

Julien Fischer juliensf at cs.mu.OZ.AU
Tue Jun 28 19:37:56 AEST 2005


Estimated hours taken: 3
Branches: main, release

Make the OpenGL/GLUT bindings compatible with OS X.

extras/graphics/mercury_opengl/mogl.m:
extras/graphics/mercury_opengl/mglu.m:
extras/graphics/mercury_glut/glut*.m:
	Make sure the appropriate header files are included on OS X
	systems.

	Remove some unecessary imports and change the imports so that
	they are one-per-line.

	Workaround a problem with Apple's OpenGL implementation.

extras/graphics/mercury_glut/README:
extras/graphics/mercury_opengl/README:
	Refer users to Mmakefile.MacOSX for instructions on how to build
	the binding on OS X.

extras/graphics/mercury_opengl/Mmakefile.MacOSX:
extras/graphics/mercury_glut/Mmakefile.MacOSX:
	New file.  OS X specific Mmakefile for the GLUT binding.

extras/graphics/samples/gears/*.m:
	Remove unecessary module imports.  Import modules
	one-per-line.

extras/graphics/*/.cvsignore:
	Add .cvsignore files.

Julien.

Index: mercury_glut/.cvsignore
===================================================================
RCS file: mercury_glut/.cvsignore
diff -N mercury_glut/.cvsignore
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mercury_glut/.cvsignore	28 Jun 2005 09:29:06 -0000
@@ -0,0 +1,17 @@
+*.c
+*.c_date
+*.d
+*.int*
+*.date*
+*.opt
+*.optdate
+*.trans_opt
+*.trans_opt_date
+*.mh
+*.mih
+*.dylib
+*.pic_o
+*.err
+*.dep
+*.dv
+*.init
Index: mercury_glut/Mmakefile.MacOSX
===================================================================
RCS file: mercury_glut/Mmakefile.MacOSX
diff -N mercury_glut/Mmakefile.MacOSX
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mercury_glut/Mmakefile.MacOSX	28 Jun 2005 09:29:06 -0000
@@ -0,0 +1,23 @@
+# To build the GLUT binding on MacOS X, do the following:
+#
+# $ mmake -f Mmakefile.MacOSX depend
+# $ mmake -f Mmakefile.MacOSX
+#
+# After which you can install by ...
+#
+# $ mmake -f Mmakefile.MacOSX install
+
+MAIN_TARGET = libmercury_glut
+
+MCFLAGS-mercury_glut+=--no-warn-nothing-exported --no-warn-interface-imports
+
+MCFLAGS += --halt-at-warn --transitive-intermodule-optimization \
+	--enable-termination --analyse-exceptions
+
+MGNUCFLAGS = --pic-reg
+
+MLLIBS = -framework GLUT
+
+depend: mercury_glut.depend
+
+install: libmercury_glut.install
Index: mercury_glut/README
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/README,v
retrieving revision 1.1
diff -u -r1.1 README
--- mercury_glut/README	17 May 2004 08:28:51 -0000	1.1
+++ mercury_glut/README	28 Jun 2005 09:29:06 -0000
@@ -8,5 +8,6 @@
 See <http://www.opengl.org/resources/libraries/glut.html> for further
 details.

-The Mmakefile includes instructions for building and installing
-the library.
+The Mmakefile includes instructions for building and installing the
+library on Linux based systems.  Users of MacOS X, should instead see
+the file Mmakefile.MacOSX for instructions on how to build the binding.
Index: mercury_glut/glut.callback.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/glut.callback.m,v
retrieving revision 1.1
diff -u -r1.1 glut.callback.m
--- mercury_glut/glut.callback.m	17 May 2004 08:28:51 -0000	1.1
+++ mercury_glut/glut.callback.m	28 Jun 2005 09:29:06 -0000
@@ -210,17 +210,21 @@

 :- implementation.

-:- import_module io, int.
-
-:- pragma foreign_decl("C", "
+:- pragma foreign_decl("C",
+"
 	#include <stdio.h>
-	#include <GL/glut.h>
+
+	#if defined(__APPLE__) && defined(__MACH__)
+		#include <GLUT/glut.h>
+	#else
+		#include <GL/glut.h>
+	#endif
 ").

 %-----------------------------------------------------------------------------%

-
 	% Global callbacks.
+	%
 :- pragma foreign_decl("C", "
 	void MGLUT_idle_callback(void);

@@ -228,6 +232,7 @@
 ").

 	% Window specific callbacks.
+	%
 :- pragma foreign_decl("C", "

 	void MGLUT_display_callback(void);
Index: mercury_glut/glut.color_map.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/glut.color_map.m,v
retrieving revision 1.1
diff -u -r1.1 glut.color_map.m
--- mercury_glut/glut.color_map.m	17 May 2004 08:28:51 -0000	1.1
+++ mercury_glut/glut.color_map.m	28 Jun 2005 09:29:06 -0000
@@ -45,7 +45,15 @@

 :- implementation.

-:- pragma foreign_decl("C", "#include <GL/glut.h>").
+:- pragma foreign_decl("C",
+"
+	#if defined(__APPLE__) && defined(__MACH__)
+		#include <GLUT/glut.h>
+	#else
+		#include <GL/glut.h>
+
+	#endif
+").

 %-----------------------------------------------------------------------------%

Index: mercury_glut/glut.font.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/glut.font.m,v
retrieving revision 1.1
diff -u -r1.1 glut.font.m
--- mercury_glut/glut.font.m	9 Jun 2004 04:44:41 -0000	1.1
+++ mercury_glut/glut.font.m	28 Jun 2005 09:29:06 -0000
@@ -80,7 +80,14 @@

 :- implementation.

-:- pragma foreign_decl("C", "#include <GL/glut.h>").
+:- pragma foreign_decl("C",
+"
+	#if defined(__APPLE__) && defined(__MACH__)
+		#include <GLUT/glut.h>
+	#else
+		#include <GL/glut.h>
+	#endif
+").

 :- type font_ptr.
 :- pragma foreign_type("C", font_ptr, "void *").
Index: mercury_glut/glut.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/glut.m,v
retrieving revision 1.3
diff -u -r1.3 glut.m
--- mercury_glut/glut.m	30 Nov 2004 14:54:38 -0000	1.3
+++ mercury_glut/glut.m	28 Jun 2005 09:29:09 -0000
@@ -24,7 +24,14 @@

 :- import_module glut.window.

-:- import_module bool, char, float, int, io, list, string, std_util.
+:- import_module bool.
+:- import_module char.
+:- import_module float.
+:- import_module int.
+:- import_module io.
+:- import_module list.
+:- import_module string.
+:- import_module std_util.

 %-----------------------------------------------------------------------------%
 %
@@ -141,9 +148,18 @@

 :- implementation.

-:- import_module map, require.
+:- import_module map.
+:- import_module require.

-:- pragma foreign_decl("C", "#include <GL/glut.h>").
+:- pragma foreign_decl("C",
+"
+	#if defined(__APPLE__) && defined(__MACH__)
+		#include <GLUT/glut.h>
+	#else
+		#include <GL/glut.h>
+
+	#endif
+").

 %-----------------------------------------------------------------------------%

Index: mercury_glut/glut.model.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/glut.model.m,v
retrieving revision 1.1
diff -u -r1.1 glut.model.m
--- mercury_glut/glut.model.m	17 May 2004 08:28:51 -0000	1.1
+++ mercury_glut/glut.model.m	28 Jun 2005 09:29:09 -0000
@@ -82,7 +82,15 @@

 :- implementation.

-:- pragma foreign_decl("C", "#include <GL/glut.h>").
+:- pragma foreign_decl("C",
+"
+	#if defined(__APPLE__) && defined(__MACH__)
+		#include <GLUT/glut.h>
+	#else
+		#include <GL/glut.h>
+
+	#endif
+").

 %-----------------------------------------------------------------------------%

Index: mercury_glut/glut.overlay.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/glut.overlay.m,v
retrieving revision 1.2
diff -u -r1.2 glut.overlay.m
--- mercury_glut/glut.overlay.m	30 Nov 2004 14:54:39 -0000	1.2
+++ mercury_glut/glut.overlay.m	28 Jun 2005 09:29:09 -0000
@@ -17,8 +17,6 @@

 :- import_module glut.window.

-:- import_module bool, std_util.
-
 %-----------------------------------------------------------------------------%

 :- type layer ---> normal ; overlay.
@@ -92,7 +90,14 @@

 :- implementation.

-:- pragma foreign_decl("C", "#include <GL/glut.h>").
+:- pragma foreign_decl("C",
+"
+	#if defined(__APPLE__) && defined(__MACH__)
+		#include <GLUT/glut.h>
+	#else
+		#include <GL/glut.h>
+	#endif
+").

 %-----------------------------------------------------------------------------%

Index: mercury_glut/glut.window.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/glut.window.m,v
retrieving revision 1.2
diff -u -r1.2 glut.window.m
--- mercury_glut/glut.window.m	30 Nov 2004 14:54:39 -0000	1.2
+++ mercury_glut/glut.window.m	28 Jun 2005 09:29:09 -0000
@@ -241,7 +241,14 @@

 :- implementation.

-:- pragma foreign_decl("C", "#include <GL/glut.h>").
+:- pragma foreign_decl("C",
+"
+	#if defined(__APPLE__) && defined(__MACH__)
+		#include <GLUT/glut.h>
+	#else
+		#include <GL/glut.h>
+	#endif
+").

 :- type window == int.

Index: mercury_opengl/.cvsignore
===================================================================
RCS file: mercury_opengl/.cvsignore
diff -N mercury_opengl/.cvsignore
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mercury_opengl/.cvsignore	28 Jun 2005 09:29:09 -0000
@@ -0,0 +1,20 @@
+mogl.c
+mglu.c
+mtogl.c
+mercury_opengl.c
+*.c_date
+*.d
+*.int*
+*.date*
+*.opt
+*.optdate
+*.trans_opt
+*.trans_opt_date
+*.mh
+*.mih
+*.dylib
+*.pic_o
+*.err
+*.dep
+*.dv
+*.init
Index: mercury_opengl/Mmakefile.MacOSX
===================================================================
RCS file: mercury_opengl/Mmakefile.MacOSX
diff -N mercury_opengl/Mmakefile.MacOSX
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mercury_opengl/Mmakefile.MacOSX	28 Jun 2005 09:29:09 -0000
@@ -0,0 +1,25 @@
+# To build the OpenGL binding on OS X, do the following:
+#
+# $ mmake -f Mmakefile.MacOSX depend
+# $ mmake -f Mmakefile.MacOSX
+#
+# After which you can install by ....
+#
+# $ mmake -f Mmakefile.MacOSX install
+
+MAIN_TARGET = libmercury_opengl
+
+# Don't issue a warning because mercury_opengl doesn't export anything.
+MCFLAGS-mercury_opengl = --no-warn-nothing-exported
+
+# This is necessary for a couple of predicates that have not been
+# implemented completely.
+MCFLAGS-mogl = --no-warn-inferred-erroneous
+
+MCFLAGS = --halt-at-warn --intermodule-optimization
+
+MLLIBS = -framework OpenGL
+
+depend: mercury_opengl.depend
+
+install: libmercury_opengl.install
Index: mercury_opengl/README
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_opengl/README,v
retrieving revision 1.3
diff -u -r1.3 README
--- mercury_opengl/README	1 Dec 2004 01:45:30 -0000	1.3
+++ mercury_opengl/README	28 Jun 2005 09:29:09 -0000
@@ -33,6 +33,8 @@
 	files

 See the file Mmakefile for instructions on how to build the OpenGL binding.
+The file Mmakefile.MacOSX contains instructions on how to build the binding
+on systems with MacOS X.
 The file Mmakefile.mtogl contains instructions on how to build mtogl.

 See HOWTO for details on how to link the package in with your own
Index: mercury_opengl/mglu.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_opengl/mglu.m,v
retrieving revision 1.7
diff -u -r1.7 mglu.m
--- mercury_opengl/mglu.m	19 May 2005 07:45:24 -0000	1.7
+++ mercury_opengl/mglu.m	28 Jun 2005 09:29:12 -0000
@@ -96,7 +96,12 @@

 :- pragma foreign_decl("C", "
 	#include <math.h>
-	#include <GL/glu.h>
+
+	#if defined(__APPLE__) && (__MACH__)
+		#include <OpenGL/glu.h>
+	#else
+		#include <GL/glu.h>
+	#endif
 ").

 %------------------------------------------------------------------------------%
Index: mercury_opengl/mogl.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_opengl/mogl.m,v
retrieving revision 1.16
diff -u -r1.16 mogl.m
--- mercury_opengl/mogl.m	19 May 2005 07:45:24 -0000	1.16
+++ mercury_opengl/mogl.m	28 Jun 2005 09:29:18 -0000
@@ -1139,7 +1139,12 @@
 	#include <stdio.h>
 	#include <math.h>
 	#include <assert.h>
-	#include <GL/gl.h>
+
+	#if defined(__APPLE__) && defined(__MACH__)
+		#include <OpenGL/gl.h>
+	#else
+		#include <GL/gl.h>
+	#endif
 ").

 %------------------------------------------------------------------------------%
@@ -5056,7 +5061,16 @@
 	push_client_attrib(IO0::di, IO::uo),
 	[will_not_call_mercury, promise_pure],
 "
-	glPushClientAttrib(GL_ALL_CLIENT_ATTRIB_BITS);
+	/*
+ 	** XXX Apple's OpenGL implementation is broken.
+	** It doesn't define GL_ALL_CLIENT_ATTRIB_BITS.
+	*/
+	#if defined(__APPLE__) && defined(__MACH__)
+		glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
+		glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
+	#else
+		glPushClientAttrib(GL_ALL_CLIENT_ATTRIB_BITS);
+	#endif
 	IO = IO0;
 ").

Index: samples/gears/.cvsignore
===================================================================
RCS file: samples/gears/.cvsignore
diff -N samples/gears/.cvsignore
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ samples/gears/.cvsignore	28 Jun 2005 09:29:18 -0000
@@ -0,0 +1,13 @@
+gears
+*.c
+*.c_date
+*.d
+*.date
+*.dep
+*.err
+*.mh
+*.mih
+*.o
+*.dv
+*.int
+*.int2
Index: samples/gears/Mmakefile.MacOSX
===================================================================
RCS file: samples/gears/Mmakefile.MacOSX
diff -N samples/gears/Mmakefile.MacOSX
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ samples/gears/Mmakefile.MacOSX	28 Jun 2005 09:29:18 -0000
@@ -0,0 +1,30 @@
+# This Mmakefile is for building the gears example on MacOS 10.3 and
+# 10.4.  To build the examples in place, ie. without having installed
+# the GLUT and OpenGL bindings, set the environment variable
+# DYLD_LIBRARY_PATH to point to the paths where the bindings were built.
+# e.g.
+#
+# export DYLD_LIBRARY_PATH=../../mercury_glut:../../mercury_opengl
+
+MAIN_TARGET = gears
+
+# Specify the location of the `mercury_opengl' and `mercury_glut'
+# packages.
+MERCURY_OPENGL_DIR = ../../mercury_opengl
+MERCURY_GLUT_DIR = ../../mercury_glut
+
+MGNUCFLAGS = -I$(MERCURY_OPENGL_DIR) -I$(MERCURY_GLUT_DIR)
+
+VPATH = $(MERCURY_OPENGL_DIR):$(MERCURY_GLUT_DIR):$(MMAKE_VPATH)
+
+MCFLAGS = -I$(MERCURY_OPENGL_DIR) -I$(MERCURY_GLUT_DIR) \
+	$(EXTRA_MCFLAGS)
+MLFLAGS = -R$(MERCURY_OPENGL_DIR) -R$(MERCURY_GLUT_DIR) \
+	-L$(MERCURY_OPENGL_DIR) -L$(MERCURY_GLUT_DIR) $(EXTRA_MLFLAGS)
+
+MLLIBS = -lobjC -lmercury_glut -lmercury_opengl -framework GLUT -framework OpenGL
+
+C2INITARGS = $(MERCURY_OPENGL_DIR)/mercury_opengl.init \
+	$(MERCURY_GLUT_DIR)/mercury_glut.init
+
+depend: gears.depend
Index: samples/gears/gears.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/samples/gears/gears.m,v
retrieving revision 1.2
diff -u -r1.2 gears.m
--- samples/gears/gears.m	6 Jan 2005 05:45:19 -0000	1.2
+++ samples/gears/gears.m	28 Jun 2005 09:29:20 -0000
@@ -25,11 +25,20 @@

 :- implementation.

-:- import_module mogl, mglu.
-:- import_module glut, glut.window, glut.callback.
 :- import_module globals.
+:- import_module glut.
+:- import_module glut.callback.
+:- import_module glut.window.
+:- import_module mglu.
+:- import_module mogl.

-:- import_module std_util, char, float, int, list, math, string.
+:- import_module char.
+:- import_module float.
+:- import_module int.
+:- import_module list.
+:- import_module math.
+:- import_module std_util.
+:- import_module string.

 %-----------------------------------------------------------------------------%

Index: samples/gears/globals.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/samples/gears/globals.m,v
retrieving revision 1.1
diff -u -r1.1 globals.m
--- samples/gears/globals.m	14 Jun 2004 11:34:06 -0000	1.1
+++ samples/gears/globals.m	28 Jun 2005 09:29:20 -0000
@@ -4,7 +4,8 @@

 :- interface.

-:- import_module io, string.
+:- import_module io.
+:- import_module string.

 %-----------------------------------------------------------------------------%

@@ -19,7 +20,9 @@

 :- implementation.

-:- import_module io, string, map, require, std_util.
+:- import_module map.
+:- import_module require.
+:- import_module std_util.

 %-----------------------------------------------------------------------------%

Index: samples/maze/.cvsignore
===================================================================
RCS file: samples/maze/.cvsignore
diff -N samples/maze/.cvsignore
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ samples/maze/.cvsignore	28 Jun 2005 09:29:20 -0000
@@ -0,0 +1,13 @@
+maze
+*.c
+*.c_date
+*.d
+*.date
+*.dep
+*.err
+*.mh
+*.mih
+*.o
+*.dv
+*.int
+*.int2
Index: samples/maze/Mmakefile.MacOSX
===================================================================
RCS file: samples/maze/Mmakefile.MacOSX
diff -N samples/maze/Mmakefile.MacOSX
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ samples/maze/Mmakefile.MacOSX	28 Jun 2005 09:29:20 -0000
@@ -0,0 +1,30 @@
+# This Mmakefile is for building the gears example on MacOS 10.3 and
+# 10.4.  To build the examples in place, ie. without having installed
+# the GLUT and OpenGL bindings, set the environment variable
+# DYLD_LIBRARY_PATH to point to paths where the bindings were built.
+# e.g.
+#
+# export DYLD_LIBRARY_PATH=../../mercury_glut:../../mercury_opengl
+
+MAIN_TARGET = maze
+
+# Specify the location of the `mercury_opengl' and `mercury_glut'
+# packages.
+MERCURY_OPENGL_DIR = ../../mercury_opengl
+MERCURY_GLUT_DIR = ../../mercury_glut
+
+MGNUCFLAGS = -I$(MERCURY_OPENGL_DIR) -I$(MERCURY_GLUT_DIR)
+
+VPATH = $(MERCURY_OPENGL_DIR):$(MERCURY_GLUT_DIR):$(MMAKE_VPATH)
+
+MCFLAGS = -I$(MERCURY_OPENGL_DIR) -I$(MERCURY_GLUT_DIR) \
+	$(EXTRA_MCFLAGS)
+MLFLAGS = -R$(MERCURY_OPENGL_DIR) -R$(MERCURY_GLUT_DIR) \
+	-L$(MERCURY_OPENGL_DIR) -L$(MERCURY_GLUT_DIR) $(EXTRA_MLFLAGS)
+
+MLLIBS += -lobjC -lmercury_glut -lmercury_opengl -framework GLUT -framework OpenGL
+
+C2INITARGS = $(MERCURY_OPENGL_DIR)/mercury_opengl.init \
+	$(MERCURY_GLUT_DIR)/mercury_glut.init
+
+depend: maze.depend
Index: samples/maze/globals.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/samples/maze/globals.m,v
retrieving revision 1.4
diff -u -r1.4 globals.m
--- samples/maze/globals.m	20 Jan 2005 04:50:22 -0000	1.4
+++ samples/maze/globals.m	28 Jun 2005 09:29:20 -0000
@@ -11,7 +11,8 @@

 :- interface.

-:- import_module io, string.
+:- import_module io.
+:- import_module string.

 %-----------------------------------------------------------------------------%

@@ -26,7 +27,9 @@

 :- implementation.

-:- import_module io, string, map, require, std_util.
+:- import_module map.
+:- import_module require.
+:- import_module std_util.

 %-----------------------------------------------------------------------------%

Index: samples/maze/maze.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/samples/maze/maze.m,v
retrieving revision 1.4
diff -u -r1.4 maze.m
--- samples/maze/maze.m	20 Jan 2005 04:50:22 -0000	1.4
+++ samples/maze/maze.m	28 Jun 2005 09:29:20 -0000
@@ -34,12 +34,25 @@
 :- implementation.

 :- import_module globals.
+:- import_module glut.
+:- import_module glut.callback.
+:- import_module glut.window.
+:- import_module mglu.
+:- import_module mogl.

-:- import_module glut, glut.window, glut.callback.
-:- import_module mogl, mglu.
-
-:- import_module bool, char, float, getopt, int, list, map, math.
-:- import_module random, require, set, std_util, string.
+:- import_module bool.
+:- import_module char.
+:- import_module float.
+:- import_module getopt.
+:- import_module int.
+:- import_module list.
+:- import_module map.
+:- import_module math.
+:- import_module random.
+:- import_module require.
+:- import_module set.
+:- import_module std_util.
+:- import_module string.

 %-----------------------------------------------------------------------------%


--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list