Integrated changes for MacOSX, submitted by Phil Atkin, with small mods by

Robert Osfield to maintain compatability under Linux.
This commit is contained in:
Robert Osfield 2001-10-03 21:44:07 +00:00
parent 1ebddc2af7
commit 2c6e85442b
29 changed files with 395 additions and 91 deletions

View File

@ -47,12 +47,15 @@ Ben Discoe <ben@vterrain.org>
Byan Woods <byran@tapestrysolutions.com>
- Port to MacOS, various code changes to support this.
- Metrowerks CodeWarrior makefiles.
- Metrowerks CodeWarrior makefiles.
Randall Hopper <aa8vb@yahoo.com>
- port to FreeBSD.
- warning fixes to IRIX compilation.
Phil Akin <Phil Atkin <philatkin@philatkin.com>
- port to OSX.
Ulrich Hertlein <u.hertlein@bit-side.com>
- support for IBM Mirror Repeat extension in osg::Texture
- support for texture subloading in osg::Texture

95
INSTALL
View File

@ -29,7 +29,7 @@ If you haven't already checked it out, for a list of distribution contents,
contacts and links to documentation check out index.html.
Environmental settings under Unix:
Environmental settings under Unix
---------------------------------
These enviromental settings are useful to help develop with an
@ -57,8 +57,8 @@ Environmental settings under Unix:
note: under IRIX you'll need to use LD_LIBRARYN32_PATH instead
of LD_LIBRARY_PATH.
Compiling under Linux :
-----------------------
Compiling under Linux
---------------------
To compile, from the OSG root directory, type:
@ -83,8 +83,8 @@ Compiling under Linux :
make help
Compiling under FreeBSD :
-------------------------
Compiling under FreeBSD
-----------------------
To compile, from the OSG root directory, type :
@ -104,8 +104,8 @@ Compiling under FreeBSD :
make help
Compiling under IRIX :
----------------------
Compiling under IRIX
--------------------
When setting up environmental variables, specified above,
LD_LIBRARY_PATH should of course be replaced by LD_LIBRARYN32_PATH.
@ -140,8 +140,8 @@ Compiling under IRIX :
make help
Compiling under Windows :
-------------------------
Compiling under Windows
-----------------------
The Microsoft Visual C++ 6.0 workspace file is VisualStudio.dsw located
in the VisualStudio\ below the OSG this root directory. The OSG will
@ -174,8 +174,9 @@ Compiling under Windows :
have been zipped up for your convienice, your find these on the OSG
release download directory.
Compiling under Mac :
---------------------
Compiling under MacOS 9
-----------------------
The Microwerks Codewarrior workspace files can be found under the
Microwerks directory. Further details to be fleshed out since
@ -185,6 +186,78 @@ Compiling under Mac :
have time to maintian the port please email robert@openscenegraph.org.
Compiling under MacOS X (instructions written by Phil Atkin)
------------------------------------------------------------
For anyone who's ever used a Unix box for development it really is so simple
it's insane.
You need to have installed the Developer tools from the CD that comes for
free with OS X. This gives you compilers, headers, frameworks - stuff like
GLUT and Carbon for developers.
Everything is done command-line, so you need to get to the underlying OS
rather than the Aqua gloss. The Mac comes with an app in
Applications/Utilities called Terminal - open up any Finder window (e.g
double-click on your hard disk icon), click on the Applications icon at the
top right of the window, then click on the Utilities folder to get access to
all the grubby apps which give away the real OS roots underneath the shiny
paintwork. Anyone developing will need Terminal so much they should put it
in their Dock. You do that by grabbing the icon of the app in the Utilities
folder and dragging it to the bottom of your screen, at which point the
other app icons in the Dock slide away to leave a gap which when you release
the mouse button leaves Terminal permanently available, just a mouse click
away on your desktop. When you start Terminal it brings you up a csh
running under Darwin (which is the BSD-with-knobs-on that underlies OS X),
and does a cd to ~ (otherwise /Users/username of whoever you are logged in
as, as far as the Finder in OS X is concerned you are in the Users/username
folder of the harddisk the machine booted from).
Then you are in Unix land, and it's all very familiar.
You will need a .cshrc file with $OSGHOME (as in your instructions), and
this is a filename that the Mac won't let you see from the Finder or in fact
generate from an app, so I used vi to create that. Then I just went
cd $OSGHOME
make clean
make macosx
And it sounds too good to be true but it is that simple. It's worth doing
some editing on the Makefiles in the Plugins and Demos directories so that
it only tries to build a subset, otherwise the developer will have to dig
out the support projects like jpeg etc. I have only built up to now sgv,
hangglide, osgcube, osgreflect, osgviews and in the Plugins have built osg
rgb 3ds and a couple others - will check and get back to you.
Tricky bit -
Installing the libdl.a is more trouble, as you have to enable the root
account on the machine, which by default is switched off as the machines
ship for security reasons. Rather than typing in and risking error through
paraphrase, here is a link to a site which tells you how to do this -
http://www.macos.utah.edu/Documentation/macosx/security/enablerootuser.html
Or alternately
http://www.thinkmacintosh.com/osxfaq.html
One you have a root account enabled, you have to su root you cd to the
directory which the Fink installer generates, and it puts libdl.a and the
associated .h files in sensible system places so the compiler just finds
them.
There is one oddball problem - if you rely on Path to find the resulting
executables, a weird Core Graphics error occurs - so even though I set up my
path to include $(OSGHOME)/bin, and when I cd to $OSGHOME and type for
example hangglide, the application starts fine (so it is in the path), but
at the point it tries to use GLUT to open a window it falls over with a CGS
error (which is I think Core Graphics System). If you explicitly go
bin/hangglide it works fine. Weird, it may be an OS X 10.04 issue which is
gone in 10.1 or it may be a weirdy in the Mac GLUT implementation, but
forewarned is forearmed.
Running the demos
-----------------

62
Make/makedefs.macosx Normal file
View File

@ -0,0 +1,62 @@
MAKEDIR = $(OSGHOME)/Make
INSTRULES = $(MAKEDIR)/instrules
MAKEDEPEND = Makedepend
OBJS = $(C++FILES:.cpp=.o) $(CFILES:.c=.o) $(YACCFILES:.y=.o) $(LEXFILES:.l=.o)
DEPFILES = $(OBJS:.o=.d)
C++ = cc
YFLAGS = -d
LCINCS += -I/usr/local/include
LC++INCS += ${LCINCS}
CFLAGS = -O2 -W -Wall $(LCINCS)
C++FLAGS = ${CFLAGS}
CPPFLAGS = ${CFLAGS}
LIBTOOL = libtool
LD = ld
PLUGINLIBS = ../../../lib/osgPlugins/osgdb_rgb.so ../../../lib/osgPlugins/osgdb_3ds.so ../../../lib/osgPlugins/osgdb_osg.so
MACOSXLIBS = ../../../lib/libosg.so ../../../lib/libosgUtil.so ../../../lib/libosgGLUT.so ../../../lib/libosgDB.so
PLUGINS = $(PLUGINLIBS)
LDFLAGS = -all_load -framework GLUT -framework Carbon -L/usr/local/lib -L/usr/lib -L../../../lib/osgPlugins -ldl -lstdc++ -lm
DYNAMICLIBRARYLIB =
PFLIBS =
#
# TARGET_DIRS are directories that would not exist on the system except
# for the presence of OpenSceneGraph. 'make instclean' removes these
# directories
#
TARGET_DIRS = \
/usr/include/osg \
/usr/include/osgDB \
/usr/include/osgGLUT \
/usr/include/osgUtil \
/usr/share/OpenSceneGraph\
/usr/share/OpenSceneGraph/data\
/usr/share/OpenSceneGraph/data/Images\
/usr/share/OpenSceneGraph/data/Test\
/usr/lib/osgPlugins\
TARGET_BIN = /usr/bin
TARGET_LIB = /usr/lib
TARGET_INCLUDE = /usr/include
TARGET_DATA = /usr/share/OpenSceneGraph/data
#
# This definitions are necessary for IRIX. The following statement
# does not work for smake using a sh:
#
# for variable in $(LIST); do ...; done
#
# .. if $(LIST) is a NULL variable. So we have to define 0 length
# strings and check for them inside the for loop
#
TARGET_LIB_FILES = ""
TARGET_BIN_FILES = ""
TARGET_INCLUDE_FILES = ""
TARGET_DATA_FILES = ""
TARGET_LOADER_FILES = ""

59
Make/makerules.macosx Normal file
View File

@ -0,0 +1,59 @@
all : $(MAKEDEPEND) $(TARGET) $(LIB) $(DYLIB)
$(TARGET) : $(OBJS) $(PLUGINLIBS) $(MACOSXLIBS)
$(C++) $(LDFLAGS) $(MACOSXLIBS) $(OBJS) $(PLUGINS) -o $@
$(LIB) : $(OBJS)
$(LIBTOOL) -static -o $@ $(OBJS)
$(DYLIB) : $(OBJS)
$(LIBTOOL) -static -o $@ $(OBJS)
clean :
rm -f $(OBJS) core $(TARGET) $(MAKEDEPEND)
touch $(MAKEDEPEND)
clobber : clean
rm -f $(TARGET) a.out $(LIB)
to_unix :
for f in *.cpp ; do to_unix $$f $$f; done
for f in *.h ; do to_unix $$f $$f; done
# force it
depend :
$(C++) $(C++FLAGS) -M $(C++FILES) $(CFILES) > $(MAKEDEPEND)
$(MAKEDEPEND) : $(C++FILES) $(CFILES)
$(C++) $(C++FLAGS) -M $(C++FILES) $(CFILES) > $(MAKEDEPEND)
%.o : %.cpp
$(C++) $(C++FLAGS) -c $*.cpp -o $*.o
%.o : %.c
$(C++) $(C++FLAGS) -c $*.c -o $*.o
docs:
[ "$(TARGET_BASENAME)" != "" ] && \
mkdir -p ../../doc/doc++/$(TARGET_BASENAME) && \
doc++ -d ../../doc/doc++/$(TARGET_BASENAME) -H -A ../../include/$(TARGET_BASENAME)/* && \
echo $(TARGET_BASENAME) HTML documentation created in ../../doc/doc++/$(TARGET_BASENAME)
install : home
@ $(MAKE) __install
instlinks : home
@ $(MAKE) __instlinks
instclean : home
@ $(MAKE) __instclean
home :
@ [ -n "$(OSGHOME)" ] || (echo ; echo "-------------> Please define OSGHOME"; echo)
@ [ -n "$(OSGHOME)" ] && echo > /dev/null;
sinclude $(INSTRULES)
include $(MAKEDEPEND)

View File

@ -56,6 +56,13 @@ irix.old:
ln -sf makerules.irix makerules
$(MAKE)
macosx:
cd Make;\
ln -sf makedefs.macosx makedefs;\
ln -sf makerules.macosx makerules
$(MAKE)
help :
@echo Usage :
@echo \ $(MAKE)

View File

@ -5,7 +5,11 @@
// non windows, doesn't require nonsense as seen below :-)
#ifndef __gl_h_
#include <GL/gl.h>
#ifdef __APPLE_CC__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#endif
// required for compatibility with glext.h sytle function definitions of

10
include/osg/GLU Normal file
View File

@ -0,0 +1,10 @@
#ifndef OSG_GLU
#define OSG_GL 1
#ifdef __APPLE_CC__
#include <OpenGL/glu.h>
#else
#include <GL/glu.h>
#endif
#endif // __osgGL_h

72
include/osg/Math Normal file
View File

@ -0,0 +1,72 @@
#ifndef __OSG_MATH
#define __OSG_MATH
#include <math.h>
// #define USE_DEGREES_INTERNALLY
#if defined(WIN32) || defined (macintosh)
#define M_E 2.7182818284590452354
#define M_LOG2E 1.4426950408889634074
#define M_LOG10E 0.43429448190325182765
#define M_LN2 0.69314718055994530942
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.78539816339744830962
#define M_1_PI 0.31830988618379067154
#define M_2_PI 0.63661977236758134308
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.70710678118654752440
#endif
// PJA MAC OSX
// This appears to be the simplest way to get these defined under MACOSX
// where they arent in math.h
#ifndef acosf
#define acosf acos
#endif
#ifndef asinf
#define asinf asin
#endif
#ifndef cosf
#define cosf cos
#endif
#ifndef sinf
#define sinf sin
#endif
#ifndef logf
#define logf log
#endif
#ifndef floorf
#define floorf floor
#endif
#ifndef powf
#define powf pow
#endif
#ifndef sqrtf
#define sqrtf sqrt
#endif
namespace osg {
#ifdef USE_DEGREES_INTERNALLY
inline double inDegrees(float angle) { return angle; }
inline double inRadians(float angle) { return angle*180.0/M_PI; }
#else
inline double inDegrees(float angle) { return angle*M_PI/180.0; }
inline double inRadians(float angle) { return angle; }
#endif
};
#endif // __OSG_MATH

View File

@ -34,6 +34,12 @@ enum NotifySeverity {
/** global notify level. */
SG_EXPORT extern NotifySeverity g_NotifyLevel;
/** global notify nul stream. added for Mac OSX */
SG_EXPORT extern ofstream *g_NotifyNulStream;
/** global notify nul stream. added for Mac OSX */
SG_EXPORT extern bool g_NotifyInit;
/** set the notify level, overriding the default or value set by
* the environmental variable OSGNOTIFYLEVEL.
*/
@ -59,31 +65,25 @@ SG_EXPORT extern bool initNotifyLevel();
* with your code simply use the notify function as a normal file
* stream (like cout) i.e osg::notify(osg::DEBUG) << "Hello Bugs!"<<endl;
*/
inline ostream& notify(const NotifySeverity severity=INFO)
//
// PJA MAC OSX 30-09-01
// previous implementation was causing Mac OSX to misbehave. This version
// places less stress on compiler and runs on Mac
inline ostream& notify(const NotifySeverity severity)
{
static bool s_initialized = initNotifyLevel();
#ifdef __GNUC__
/* a little hack to prevent gcc's warning message (will be optimized away) */
if ( 0 && s_initialized )
;
#endif
#ifdef WIN32
static ofstream s_abosorbStr("nul");
#else
static ofstream s_abosorbStr("/dev/null");
#endif
if (!g_NotifyInit) initNotifyLevel();
if (severity<=g_NotifyLevel)
{
if (severity<=osg::WARN) return cerr;
else return cout;
}
return s_abosorbStr;
return *osg::g_NotifyNulStream;
}
inline ostream& notify(void) { return notify(osg::INFO); }
};
#endif

View File

@ -14,6 +14,8 @@ namespace osg {
typedef unsigned long long Timer_t;
#elif defined(unix)
typedef unsigned long long Timer_t;
#elif defined __APPLE__ // MACOSX PJA
typedef double Timer_t;
#else
#include <ctime>
typedef std::clock_t Timer_t;
@ -27,8 +29,14 @@ class SG_EXPORT Timer {
Timer();
~Timer() {}
inline Timer_t tick();
#ifdef __APPLE__
// PJA MAC OSX - inline Tick() pollutes namespace so badly
// we cant compile, due to Carbon.h ...
Timer_t tick();
#else
inline Timer_t tick();
#endif
inline double delta_s( Timer_t t1, Timer_t t2 ) const { return (double)(t2 - t1)*_secsPerClick; }
inline double delta_m( Timer_t t1, Timer_t t2 ) const { return delta_s(t1,t2)*1e3; }
inline double delta_u( Timer_t t1, Timer_t t2 ) const { return delta_s(t1,t2)*1e6; }
@ -138,7 +146,7 @@ namespace osg{
}
};
#else
#elif !defined (__APPLE_CC__)
// no choice, always use std::clock()
@ -149,4 +157,6 @@ namespace osg{
#endif
// note, MacOSX compiled in the Timer.cpp.
#endif

View File

@ -8,34 +8,6 @@ typedef unsigned short ushort;
typedef unsigned char uchar;
typedef uchar ubyte;
#if defined(WIN32) || defined (macintosh)
#define M_E 2.7182818284590452354
#define M_LOG2E 1.4426950408889634074
#define M_LOG10E 0.43429448190325182765
#define M_LN2 0.69314718055994530942
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.78539816339744830962
#define M_1_PI 0.31830988618379067154
#define M_2_PI 0.63661977236758134308
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.70710678118654752440
#else
#include <math.h>
#endif
#define USE_DEGREES_INTERNALLY
#ifdef USE_DEGREES_INTERNALLY
inline double inDegrees(float angle) { return angle; }
inline double inRadians(float angle) { return angle*180.0/M_PI; }
#else
inline double inDegrees(float angle) { return angle*M_PI/180.0; }
inline double inRadians(float angle) { return angle; }
#endif
};
#endif

View File

@ -1,7 +1,7 @@
#ifndef OSG_VEC2
#define OSG_VEC2 1
#include <math.h>
#include <osg/Math>
#ifdef OSG_USE_IO_DOT_H
#include <iostream.h>

View File

@ -1,7 +1,7 @@
#ifndef OSG_VEC3
#define OSG_VEC3 1
#include <math.h>
#include <osg/Math>
#ifdef OSG_USE_IO_DOT_H
#include <iostream.h>

View File

@ -1,7 +1,7 @@
#ifndef OSG_VEC4
#define OSG_VEC4 1
#include <math.h>
#include <osg/Math>
#ifdef OSG_USE_IO_DOT_H
#include <iostream.h>

10
include/osgGLUT/glut Normal file
View File

@ -0,0 +1,10 @@
#ifndef OSG_GLU
#define OSG_GL 1
#ifdef __APPLE__
#include </System/Library/Frameworks/GLUT.Framework/Versions/A/Headers/glut.h>
#else
#include <GL/glut.h>
#endif
#endif // __osgGL_h

View File

@ -7,7 +7,7 @@
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <GL/glut.h>
#include <osgGLUT/glut>
#include <osgGLUT/Viewer>
#include "GliderManipulator.h"

View File

@ -3,8 +3,8 @@
#pragma warning( disable : 4244 )
#endif
#include <GL/gl.h>
#include <math.h>
#include <osg/GL>
#include <osg/Math>
#include <stdio.h>
#include "terrain_data.h"

View File

@ -10,10 +10,9 @@
#include <osgUtil/TrackballManipulator>
#include <osgGLUT/Viewer>
#include <osgGLUT/glut>
#include <GL/glut.h>
#include <math.h>
#include <osg/Math>
// ----------------------------------------------------------------------
// Global variables - this is basically the stuff which will be animated

View File

@ -16,7 +16,7 @@
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <GL/glut.h>
#include <osgGLUT/glut>
#include <osgGLUT/Viewer>

View File

@ -12,7 +12,7 @@
#include <osgUtil/FlightManipulator>
#include <osgUtil/DriveManipulator>
#include <GL/glut.h>
#include <osgGLUT/glut>
#include <osgGLUT/Viewer>
#include <osgUtil/OptimizeStateVisitor>

View File

@ -1,13 +1,14 @@
#include "osg/Image"
#include "osg/GL"
#include "osg/Notify"
#include <osg/GL>
#include <osg/GLU>
#include <osg/Image>
#include <osg/Notify>
#include <osg/Geode>
#include <osg/GeoSet>
#include <osg/StateSet>
#include <osg/Texture>
#include <GL/glu.h>
using namespace osg;

View File

@ -2,6 +2,8 @@
#include <string>
osg::NotifySeverity osg::g_NotifyLevel = osg::NOTICE;
ofstream *osg::g_NotifyNulStream;
bool osg::g_NotifyInit = false;
void osg::setNotifyLevel(osg::NotifySeverity severity)
{
@ -19,11 +21,16 @@ osg::NotifySeverity osg::getNotifyLevel()
bool osg::initNotifyLevel()
{
static bool s_local_intialized = false;
if (g_NotifyInit) return true;
if (s_local_intialized) return true;
s_local_intialized = true;
g_NotifyInit = true;
// set up global notify null stream for inline notify
#ifdef WIN32
g_NotifyNulStream = new ofstream ("nul");
#else
g_NotifyNulStream = new ofstream ("/dev/null");
#endif
// g_NotifyLevel
// =============

View File

@ -1,7 +1,7 @@
#include <osg/State>
#include <osg/Notify>
#include <GL/glu.h>
#include <osg/GLU>
using namespace osg;

View File

@ -9,7 +9,7 @@
#include <osg/Notify>
#include <osg/GLExtensions>
#include <GL/glu.h>
#include <osg/GLU>
using namespace osg;
@ -176,7 +176,7 @@ void Texture::apply(State& state) const
const uint contextID = state.getContextID();
// get the globj for the current contextID.
uint& handle = getHandle(contextID);
GLuint& handle = getHandle(contextID);
// For multi-texturing will need something like...
// glActiveTextureARB((GLenum)(GL_TEXTURE0_ARB+_textureUnit));
@ -548,7 +548,7 @@ void Texture::copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, i
const uint contextID = state.getContextID();
// get the globj for the current contextID.
uint& handle = getHandle(contextID);
GLuint& handle = getHandle(contextID);
if (handle)
{

View File

@ -180,7 +180,23 @@ using namespace osg;
_secsPerClick = (double)(cycleval)* 1e-12;
}
}
#elif defined (__APPLE_CC__) // MACOSX PJA
#include <Carbon/Carbon.h> // do I really have to link against the Carbon framework just for this?
Timer_t Timer::tick(void)
{
UnsignedWide usecs;
Microseconds(&usecs);
return (usecs.hi * 4294967296.0) + usecs.lo;
}
Timer::Timer( void )
{
_useStandardClock = false;
_secsPerClick = 1e-6; // Carbon timer's precision.
}
#elif defined(unix)

View File

@ -1,5 +1,5 @@
#include "osgGLUT/GLUTEventAdapter"
#include "GL/glut.h"
#include <osgGLUT/glut>
using namespace osgGLUT;

View File

@ -8,7 +8,7 @@
#include <sys/time.h>
#endif
#include <stdio.h>
#include <math.h>
#include <osg/Math>
#include <string>
@ -48,7 +48,7 @@
#define USE_GLUT
#endif
#include <GL/glut.h>
#include <osgGLUT/glut>
#ifdef WIN32
#include <sys/timeb.h>
@ -1049,7 +1049,7 @@ void Viewer::keyboard(unsigned char key, int x, int y)
if (_printStats>4) _printStats=0;
if (_printStats==4) { // count depth complexity by incrementing the stencil buffer every
// time a pixel is hit
int nsten=0; // Number of stencil planes available
GLint nsten=0; // Number of stencil planes available
glGetIntegerv(GL_STENCIL_BITS , &nsten);
if (nsten>0) {
glEnable(GL_STENCIL_TEST);

View File

@ -6,7 +6,7 @@
#include <osg/AlphaFunc>
#include <osg/TexEnv>
#include <GL/glu.h>
#include <osg/GLU>
using namespace osg;
using namespace osgUtil;

View File

@ -1,10 +1,9 @@
#include <osg/GL>
#include <osg/GLU>
#include <osg/Notify>
#include <osgUtil/Tesselator>
#include <GL/glu.h>
using namespace osg;
using namespace osgUtil;