Unpacked project archives to get individual file history in subversion

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402564
This commit is contained in:
Sam Lantinga 2007-07-21 17:09:01 +00:00
parent 98ce0f8871
commit 316a61731f
199 changed files with 90702 additions and 16 deletions

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Description</key>
<string>This project builds an SDL-based application that uses OpenGL.</string>
<key>FilesToMacroExpand</key>
<array>
<string>English.lproj/InfoPlist.strings</string>
</array>
</dict>
</plist>

View file

@ -0,0 +1,478 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 38;
objects = {
080E96DDFE201D6D7F000001 = {
children = (
F5A47A9D01A0482F01D3D55B,
F5A47A9E01A0483001D3D55B,
);
isa = PBXGroup;
name = Classes;
refType = 4;
};
089C165CFE840E0CC02AAC07 = {
children = (
089C165DFE840E0CC02AAC07,
);
isa = PBXVariantGroup;
name = InfoPlist.strings;
refType = 4;
};
089C165DFE840E0CC02AAC07 = {
fileEncoding = 10;
isa = PBXFileReference;
name = English;
path = English.lproj/InfoPlist.strings;
refType = 4;
};
089C165EFE840E0CC02AAC07 = {
fileRef = 089C165CFE840E0CC02AAC07;
isa = PBXBuildFile;
settings = {
};
};
//080
//081
//082
//083
//084
//100
//101
//102
//103
//104
1058C7A0FEA54F0111CA2CBB = {
children = (
1058C7A1FEA54F0111CA2CBB,
B2F67ED704C74A3F00A80002,
B2F67F1E04C773E400A80002,
);
isa = PBXGroup;
name = "Linked Frameworks";
refType = 4;
};
1058C7A1FEA54F0111CA2CBB = {
isa = PBXFrameworkReference;
name = Cocoa.framework;
path = /System/Library/Frameworks/Cocoa.framework;
refType = 0;
};
1058C7A2FEA54F0111CA2CBB = {
children = (
29B97325FDCFA39411CA2CEA,
29B97324FDCFA39411CA2CEA,
);
isa = PBXGroup;
name = "Other Frameworks";
refType = 4;
};
1058C7A3FEA54F0111CA2CBB = {
fileRef = 1058C7A1FEA54F0111CA2CBB;
isa = PBXBuildFile;
settings = {
};
};
//100
//101
//102
//103
//104
//170
//171
//172
//173
//174
17587328FF379C6511CA2CBB = {
isa = PBXApplicationReference;
path = "«PROJECTNAME».app";
refType = 3;
};
//170
//171
//172
//173
//174
//190
//191
//192
//193
//194
19C28FACFE9D520D11CA2CBB = {
children = (
17587328FF379C6511CA2CBB,
);
isa = PBXGroup;
name = Products;
refType = 4;
};
//190
//191
//192
//193
//194
//290
//291
//292
//293
//294
29B97313FDCFA39411CA2CEA = {
buildStyles = (
4A9504CCFFE6A4B311CA0CBA,
4A9504CDFFE6A4B311CA0CBA,
);
hasScannedForEncodings = 1;
isa = PBXProject;
mainGroup = 29B97314FDCFA39411CA2CEA;
projectDirPath = "";
targets = (
29B97326FDCFA39411CA2CEA,
);
};
29B97314FDCFA39411CA2CEA = {
children = (
080E96DDFE201D6D7F000001,
29B97315FDCFA39411CA2CEA,
29B97317FDCFA39411CA2CEA,
29B97323FDCFA39411CA2CEA,
19C28FACFE9D520D11CA2CBB,
);
isa = PBXGroup;
name = "«PROJECTNAMEASXML»";
path = "";
refType = 4;
};
29B97315FDCFA39411CA2CEA = {
children = (
B2F67F1104C7737E00A80002,
F5A47A9F01A0483001D3D55B,
);
isa = PBXGroup;
name = "Other Sources";
path = "";
refType = 4;
};
29B97317FDCFA39411CA2CEA = {
children = (
089C165CFE840E0CC02AAC07,
);
isa = PBXGroup;
name = Resources;
path = "";
refType = 4;
};
29B97323FDCFA39411CA2CEA = {
children = (
1058C7A0FEA54F0111CA2CBB,
1058C7A2FEA54F0111CA2CBB,
);
isa = PBXGroup;
name = Frameworks;
path = "";
refType = 4;
};
29B97324FDCFA39411CA2CEA = {
isa = PBXFrameworkReference;
name = AppKit.framework;
path = /System/Library/Frameworks/AppKit.framework;
refType = 0;
};
29B97325FDCFA39411CA2CEA = {
isa = PBXFrameworkReference;
name = Foundation.framework;
path = /System/Library/Frameworks/Foundation.framework;
refType = 0;
};
29B97326FDCFA39411CA2CEA = {
buildPhases = (
29B97327FDCFA39411CA2CEA,
29B97328FDCFA39411CA2CEA,
29B9732BFDCFA39411CA2CEA,
29B9732DFDCFA39411CA2CEA,
);
buildSettings = {
FRAMEWORK_SEARCH_PATHS = "\"/Library/Frameworks\"";
HEADER_SEARCH_PATHS = "\"/Library/Frameworks/SDL.framework/Headers\"";
INSTALL_PATH = "$(HOME)/Applications";
LIBRARY_SEARCH_PATHS = "";
OPTIMIZATION_CFLAGS = "-O0";
OTHER_LDFLAGS = "-framework SDL";
PRODUCT_NAME = "«PROJECTNAME»";
SECTORDER_FLAGS = "";
WARNING_CFLAGS = "-Wmost -Wno-four-char-constants -Wno-unknown-pragmas";
WRAPPER_EXTENSION = app;
};
dependencies = (
);
isa = PBXApplicationTarget;
name = "«PROJECTNAME»";
productInstallPath = "$(HOME)/Applications";
productName = "«PROJECTNAME»";
productReference = 17587328FF379C6511CA2CBB;
productSettingsXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>«PROJECTNAMEASXML»</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.1</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
";
};
29B97327FDCFA39411CA2CEA = {
buildActionMask = 2147483647;
files = (
F5A47AA101A0483001D3D55B,
B2F67F1904C7737E00A80002,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
29B97328FDCFA39411CA2CEA = {
buildActionMask = 2147483647;
files = (
089C165EFE840E0CC02AAC07,
);
isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
29B9732BFDCFA39411CA2CEA = {
buildActionMask = 2147483647;
files = (
F5A47AA301A0483001D3D55B,
F5A47AA401A0483001D3D55B,
B2F67F1804C7737E00A80002,
B2F67F1A04C7737E00A80002,
B2F67F1B04C7737E00A80002,
B2F67F1C04C7737E00A80002,
B2F67F1D04C7737E00A80002,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
29B9732DFDCFA39411CA2CEA = {
buildActionMask = 2147483647;
files = (
1058C7A3FEA54F0111CA2CBB,
B2F67ED804C74A3F00A80002,
B2F67F1F04C773E400A80002,
);
isa = PBXFrameworksBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
//290
//291
//292
//293
//294
//4A0
//4A1
//4A2
//4A3
//4A4
4A9504CCFFE6A4B311CA0CBA = {
buildRules = (
);
buildSettings = {
COPY_PHASE_STRIP = NO;
OPTIMIZATION_CFLAGS = "-O0";
};
isa = PBXBuildStyle;
name = Development;
};
4A9504CDFFE6A4B311CA0CBA = {
buildRules = (
);
buildSettings = {
COPY_PHASE_STRIP = YES;
};
isa = PBXBuildStyle;
name = Deployment;
};
//4A0
//4A1
//4A2
//4A3
//4A4
//B20
//B21
//B22
//B23
//B24
B2F67ED704C74A3F00A80002 = {
isa = PBXFrameworkReference;
name = OpenGL.framework;
path = /System/Library/Frameworks/OpenGL.framework;
refType = 0;
};
B2F67ED804C74A3F00A80002 = {
fileRef = B2F67ED704C74A3F00A80002;
isa = PBXBuildFile;
settings = {
};
};
B2F67F1104C7737E00A80002 = {
children = (
B2F67F1204C7737E00A80002,
B2F67F1304C7737E00A80002,
B2F67F1404C7737E00A80002,
B2F67F1504C7737E00A80002,
B2F67F1604C7737E00A80002,
B2F67F1704C7737E00A80002,
);
isa = PBXGroup;
path = atlantis;
refType = 4;
};
B2F67F1204C7737E00A80002 = {
fileEncoding = 30;
isa = PBXFileReference;
path = atlantis.c;
refType = 4;
};
B2F67F1304C7737E00A80002 = {
fileEncoding = 30;
isa = PBXFileReference;
path = atlantis.h;
refType = 4;
};
B2F67F1404C7737E00A80002 = {
fileEncoding = 30;
isa = PBXFileReference;
path = dolphin.c;
refType = 4;
};
B2F67F1504C7737E00A80002 = {
fileEncoding = 30;
isa = PBXFileReference;
path = shark.c;
refType = 4;
};
B2F67F1604C7737E00A80002 = {
fileEncoding = 30;
isa = PBXFileReference;
path = swim.c;
refType = 4;
};
B2F67F1704C7737E00A80002 = {
fileEncoding = 30;
isa = PBXFileReference;
path = whale.c;
refType = 4;
};
B2F67F1804C7737E00A80002 = {
fileRef = B2F67F1204C7737E00A80002;
isa = PBXBuildFile;
settings = {
};
};
B2F67F1904C7737E00A80002 = {
fileRef = B2F67F1304C7737E00A80002;
isa = PBXBuildFile;
settings = {
};
};
B2F67F1A04C7737E00A80002 = {
fileRef = B2F67F1404C7737E00A80002;
isa = PBXBuildFile;
settings = {
};
};
B2F67F1B04C7737E00A80002 = {
fileRef = B2F67F1504C7737E00A80002;
isa = PBXBuildFile;
settings = {
};
};
B2F67F1C04C7737E00A80002 = {
fileRef = B2F67F1604C7737E00A80002;
isa = PBXBuildFile;
settings = {
};
};
B2F67F1D04C7737E00A80002 = {
fileRef = B2F67F1704C7737E00A80002;
isa = PBXBuildFile;
settings = {
};
};
B2F67F1E04C773E400A80002 = {
isa = PBXFrameworkReference;
name = GLUT.framework;
path = /System/Library/Frameworks/GLUT.framework;
refType = 0;
};
B2F67F1F04C773E400A80002 = {
fileRef = B2F67F1E04C773E400A80002;
isa = PBXBuildFile;
settings = {
};
};
//B20
//B21
//B22
//B23
//B24
//F50
//F51
//F52
//F53
//F54
F5A47A9D01A0482F01D3D55B = {
fileEncoding = 30;
isa = PBXFileReference;
path = SDLMain.h;
refType = 2;
};
F5A47A9E01A0483001D3D55B = {
fileEncoding = 30;
isa = PBXFileReference;
path = SDLMain.m;
refType = 2;
};
F5A47A9F01A0483001D3D55B = {
fileEncoding = 30;
isa = PBXFileReference;
path = main.c;
refType = 2;
};
F5A47AA101A0483001D3D55B = {
fileRef = F5A47A9D01A0482F01D3D55B;
isa = PBXBuildFile;
settings = {
};
};
F5A47AA301A0483001D3D55B = {
fileRef = F5A47A9E01A0483001D3D55B;
isa = PBXBuildFile;
settings = {
};
};
F5A47AA401A0483001D3D55B = {
fileRef = F5A47A9F01A0483001D3D55B;
isa = PBXBuildFile;
settings = {
};
};
};
rootObject = 29B97313FDCFA39411CA2CEA;
}

View file

@ -0,0 +1,11 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
Feel free to customize this file to suit your needs
*/
#import <Cocoa/Cocoa.h>
@interface SDLMain : NSObject
@end

View file

@ -0,0 +1,383 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
Feel free to customize this file to suit your needs
*/
#import "SDL.h"
#import "SDLMain.h"
#import <sys/param.h> /* for MAXPATHLEN */
#import <unistd.h>
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
but the method still is there and works. To avoid warnings, we declare
it ourselves here. */
@interface NSApplication(SDL_Missing_Methods)
- (void)setAppleMenu:(NSMenu *)menu;
@end
/* Use this flag to determine whether we use SDLMain.nib or not */
#define SDL_USE_NIB_FILE 0
/* Use this flag to determine whether we use CPS (docking) or not */
#define SDL_USE_CPS 1
#ifdef SDL_USE_CPS
/* Portions of CPS.h */
typedef struct CPSProcessSerNum
{
UInt32 lo;
UInt32 hi;
} CPSProcessSerNum;
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
#endif /* SDL_USE_CPS */
static int gArgc;
static char **gArgv;
static BOOL gFinderLaunch;
static BOOL gCalledAppMainline = FALSE;
static NSString *getApplicationName(void)
{
NSDictionary *dict;
NSString *appName = 0;
/* Determine the application name */
dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
if (dict)
appName = [dict objectForKey: @"CFBundleName"];
if (![appName length])
appName = [[NSProcessInfo processInfo] processName];
return appName;
}
#if SDL_USE_NIB_FILE
/* A helper category for NSString */
@interface NSString (ReplaceSubString)
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
@end
#endif
@interface SDLApplication : NSApplication
@end
@implementation SDLApplication
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
/* Post a SDL_QUIT event */
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
}
@end
/* The main class of the application, the application's delegate */
@implementation SDLMain
/* Set the working directory to the .app's parent directory */
- (void) setupWorkingDirectory:(BOOL)shouldChdir
{
if (shouldChdir)
{
char parentdir[MAXPATHLEN];
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
}
CFRelease(url);
CFRelease(url2);
}
}
#if SDL_USE_NIB_FILE
/* Fix menu to contain the real app name instead of "SDL App" */
- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
{
NSRange aRange;
NSEnumerator *enumerator;
NSMenuItem *menuItem;
aRange = [[aMenu title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
enumerator = [[aMenu itemArray] objectEnumerator];
while ((menuItem = [enumerator nextObject]))
{
aRange = [[menuItem title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
if ([menuItem hasSubmenu])
[self fixMenu:[menuItem submenu] withAppName:appName];
}
[ aMenu sizeToFit ];
}
#else
static void setApplicationMenu(void)
{
/* warning: this code is very odd */
NSMenu *appleMenu;
NSMenuItem *menuItem;
NSString *title;
NSString *appName;
appName = getApplicationName();
appleMenu = [[NSMenu alloc] initWithTitle:@""];
/* Add menu items */
title = [@"About " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Hide " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[menuItem setSubmenu:appleMenu];
[[NSApp mainMenu] addItem:menuItem];
/* Tell the application object that this is now the application menu */
[NSApp setAppleMenu:appleMenu];
/* Finally give up our references to the objects */
[appleMenu release];
[menuItem release];
}
/* Create a window menu */
static void setupWindowMenu(void)
{
NSMenu *windowMenu;
NSMenuItem *windowMenuItem;
NSMenuItem *menuItem;
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
/* "Minimize" item */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
[windowMenu addItem:menuItem];
[menuItem release];
/* Put menu into the menubar */
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
[windowMenuItem setSubmenu:windowMenu];
[[NSApp mainMenu] addItem:windowMenuItem];
/* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu];
/* Finally give up our references to the objects */
[windowMenu release];
[windowMenuItem release];
}
/* Replacement for NSApplicationMain */
static void CustomApplicationMain (int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDLMain *sdlMain;
/* Ensure the application object is initialised */
[SDLApplication sharedApplication];
#ifdef SDL_USE_CPS
{
CPSProcessSerNum PSN;
/* Tell the dock about us */
if (!CPSGetCurrentProcess(&PSN))
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
if (!CPSSetFrontProcess(&PSN))
[SDLApplication sharedApplication];
}
#endif /* SDL_USE_CPS */
/* Set up the menubar */
[NSApp setMainMenu:[[NSMenu alloc] init]];
setApplicationMenu();
setupWindowMenu();
/* Create SDLMain and make it the app delegate */
sdlMain = [[SDLMain alloc] init];
[NSApp setDelegate:sdlMain];
/* Start the main event loop */
[NSApp run];
[sdlMain release];
[pool release];
}
#endif
/*
* Catch document open requests...this lets us notice files when the app
* was launched by double-clicking a document, or when a document was
* dragged/dropped on the app's icon. You need to have a
* CFBundleDocumentsType section in your Info.plist to get this message,
* apparently.
*
* Files are added to gArgv, so to the app, they'll look like command line
* arguments. Previously, apps launched from the finder had nothing but
* an argv[0].
*
* This message may be received multiple times to open several docs on launch.
*
* This message is ignored once the app's mainline has been called.
*/
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
const char *temparg;
size_t arglen;
char *arg;
char **newargv;
if (!gFinderLaunch) /* MacOS is passing command line args. */
return FALSE;
if (gCalledAppMainline) /* app has started, ignore this document. */
return FALSE;
temparg = [filename UTF8String];
arglen = SDL_strlen(temparg) + 1;
arg = (char *) SDL_malloc(arglen);
if (arg == NULL)
return FALSE;
newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
if (newargv == NULL)
{
SDL_free(arg);
return FALSE;
}
gArgv = newargv;
SDL_strlcpy(arg, temparg, arglen);
gArgv[gArgc++] = arg;
gArgv[gArgc] = NULL;
return TRUE;
}
/* Called when the internal event loop has just started running */
- (void) applicationDidFinishLaunching: (NSNotification *) note
{
int status;
/* Set the working directory to the .app's parent directory */
[self setupWorkingDirectory:gFinderLaunch];
#if SDL_USE_NIB_FILE
/* Set the main menu to contain the real app name instead of "SDL App" */
[self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
#endif
/* Hand off to main application code */
gCalledAppMainline = TRUE;
status = SDL_main (gArgc, gArgv);
/* We're done, thank you for playing */
exit(status);
}
@end
@implementation NSString (ReplaceSubString)
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
{
unsigned int bufferSize;
unsigned int selfLen = [self length];
unsigned int aStringLen = [aString length];
unichar *buffer;
NSRange localRange;
NSString *result;
bufferSize = selfLen + aStringLen - aRange.length;
buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
/* Get first part into buffer */
localRange.location = 0;
localRange.length = aRange.location;
[self getCharacters:buffer range:localRange];
/* Get middle part into buffer */
localRange.location = 0;
localRange.length = aStringLen;
[aString getCharacters:(buffer+aRange.location) range:localRange];
/* Get last part into buffer */
localRange.location = aRange.location + aRange.length;
localRange.length = selfLen - localRange.location;
[self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
/* Build output string */
result = [NSString stringWithCharacters:buffer length:bufferSize];
NSDeallocateMemoryPages(buffer, bufferSize);
return result;
}
@end
#ifdef main
# undef main
#endif
/* Main entry point to executable - should *not* be SDL_main! */
int main (int argc, char **argv)
{
/* Copy the arguments into a global variable */
/* This is passed if we are launched by double-clicking */
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
gArgv[0] = argv[0];
gArgv[1] = NULL;
gArgc = 1;
gFinderLaunch = YES;
} else {
int i;
gArgc = argc;
gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
for (i = 0; i <= argc; i++)
gArgv[i] = argv[i];
gFinderLaunch = NO;
}
#if SDL_USE_NIB_FILE
[SDLApplication poseAsClass:[NSApplication class]];
NSApplicationMain (argc, argv);
#else
CustomApplicationMain (argc, argv);
#endif
return 0;
}

View file

@ -0,0 +1,459 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/**
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>
#include <GLUT/glut.h>
#include "atlantis.h"
fishRec sharks[NUM_SHARKS];
fishRec momWhale;
fishRec babyWhale;
fishRec dolph;
GLboolean Timing = GL_TRUE;
int w_win = 640;
int h_win = 480;
GLint count = 0;
GLenum StrMode = GL_VENDOR;
GLboolean moving;
static double mtime(void)
{
struct timeval tk_time;
struct timezone tz;
gettimeofday(&tk_time, &tz);
return 4294.967296 * tk_time.tv_sec + 0.000001 * tk_time.tv_usec;
}
static double filter(double in, double *save)
{
static double k1 = 0.9;
static double k2 = 0.05;
save[3] = in;
save[1] = save[0]*k1 + k2*(save[3] + save[2]);
save[0]=save[1];
save[2]=save[3];
return(save[1]);
}
void DrawStr(const char *str)
{
GLint i = 0;
if(!str) return;
while(str[i])
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, str[i]);
i++;
}
}
void
InitFishs(void)
{
int i;
for (i = 0; i < NUM_SHARKS; i++) {
sharks[i].x = 70000.0 + rand() % 6000;
sharks[i].y = rand() % 6000;
sharks[i].z = rand() % 6000;
sharks[i].psi = rand() % 360 - 180.0;
sharks[i].v = 1.0;
}
dolph.x = 30000.0;
dolph.y = 0.0;
dolph.z = 6000.0;
dolph.psi = 90.0;
dolph.theta = 0.0;
dolph.v = 3.0;
momWhale.x = 70000.0;
momWhale.y = 0.0;
momWhale.z = 0.0;
momWhale.psi = 90.0;
momWhale.theta = 0.0;
momWhale.v = 3.0;
babyWhale.x = 60000.0;
babyWhale.y = -2000.0;
babyWhale.z = -2000.0;
babyWhale.psi = 90.0;
babyWhale.theta = 0.0;
babyWhale.v = 3.0;
}
void
Atlantis_Init(void)
{
static float ambient[] = {0.2, 0.2, 0.2, 1.0};
static float diffuse[] = {1.0, 1.0, 1.0, 1.0};
static float position[] = {0.0, 1.0, 0.0, 0.0};
static float mat_shininess[] = {90.0};
static float mat_specular[] = {0.8, 0.8, 0.8, 1.0};
static float mat_diffuse[] = {0.46, 0.66, 0.795, 1.0};
static float mat_ambient[] = {0.3, 0.4, 0.5, 1.0};
static float lmodel_ambient[] = {0.4, 0.4, 0.4, 1.0};
static float lmodel_localviewer[] = {0.0};
//GLfloat map1[4] = {0.0, 0.0, 0.0, 0.0};
//GLfloat map2[4] = {0.0, 0.0, 0.0, 0.0};
static float fog_color[] = {0.0, 0.5, 0.9, 1.0};
glFrontFace(GL_CCW);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
InitFishs();
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_EXP);
glFogf(GL_FOG_DENSITY, 0.0000025);
glFogfv(GL_FOG_COLOR, fog_color);
glClearColor(0.0, 0.5, 0.9, 1.0);
}
void
Atlantis_Reshape(int width, int height)
{
w_win = width;
h_win = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) width / (GLfloat) height, 20000.0, 300000.0);
glMatrixMode(GL_MODELVIEW);
}
void
Atlantis_Animate(void)
{
int i;
for (i = 0; i < NUM_SHARKS; i++) {
SharkPilot(&sharks[i]);
SharkMiss(i);
}
WhalePilot(&dolph);
dolph.phi++;
//glutPostRedisplay();
WhalePilot(&momWhale);
momWhale.phi++;
WhalePilot(&babyWhale);
babyWhale.phi++;
}
void
Atlantis_Key(unsigned char key, int x, int y)
{
switch (key) {
case 't':
Timing = !Timing;
break;
case ' ':
switch(StrMode)
{
case GL_EXTENSIONS:
StrMode = GL_VENDOR;
break;
case GL_VENDOR:
StrMode = GL_RENDERER;
break;
case GL_RENDERER:
StrMode = GL_VERSION;
break;
case GL_VERSION:
StrMode = GL_EXTENSIONS;
break;
}
break;
case 27: /* Esc will quit */
exit(1);
break;
case 's': /* "s" start animation */
moving = GL_TRUE;
//glutIdleFunc(Animate);
break;
case 'a': /* "a" stop animation */
moving = GL_FALSE;
//glutIdleFunc(NULL);
break;
case '.': /* "." will advance frame */
if (!moving) {
Atlantis_Animate();
}
}
}
/*
void Display(void)
{
static float P123[3] = {-448.94, -203.14, 9499.60};
static float P124[3] = {-442.64, -185.20, 9528.07};
static float P125[3] = {-441.07, -148.05, 9528.07};
static float P126[3] = {-443.43, -128.84, 9499.60};
static float P127[3] = {-456.87, -146.78, 9466.67};
static float P128[3] = {-453.68, -183.93, 9466.67};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
FishTransform(&dolph);
DrawDolphin(&dolph);
glPopMatrix();
glutSwapBuffers();
}
*/
void
Atlantis_Display(void)
{
int i;
static double th[4] = {0.0, 0.0, 0.0, 0.0};
static double t1 = 0.0, t2 = 0.0, t;
char num_str[128];
t1 = t2;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (i = 0; i < NUM_SHARKS; i++) {
glPushMatrix();
FishTransform(&sharks[i]);
DrawShark(&sharks[i]);
glPopMatrix();
}
glPushMatrix();
FishTransform(&dolph);
DrawDolphin(&dolph);
glPopMatrix();
glPushMatrix();
FishTransform(&momWhale);
DrawWhale(&momWhale);
glPopMatrix();
glPushMatrix();
FishTransform(&babyWhale);
glScalef(0.45, 0.45, 0.3);
DrawWhale(&babyWhale);
glPopMatrix();
if(Timing)
{
t2 = mtime();
t = t2 - t1;
if(t > 0.0001) t = 1.0 / t;
glDisable(GL_LIGHTING);
//glDisable(GL_DEPTH_TEST);
glColor3f(1.0, 0.0, 0.0);
glMatrixMode (GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, w_win, 0, h_win, -10.0, 10.0);
glRasterPos2f(5.0, 5.0);
switch(StrMode)
{
case GL_VENDOR:
sprintf(num_str, "%0.2f Hz, %dx%d, VENDOR: ", filter(t, th), w_win, h_win);
DrawStr(num_str);
DrawStr(glGetString(GL_VENDOR));
break;
case GL_RENDERER:
sprintf(num_str, "%0.2f Hz, %dx%d, RENDERER: ", filter(t, th), w_win, h_win);
DrawStr(num_str);
DrawStr(glGetString(GL_RENDERER));
break;
case GL_VERSION:
sprintf(num_str, "%0.2f Hz, %dx%d, VERSION: ", filter(t, th), w_win, h_win);
DrawStr(num_str);
DrawStr(glGetString(GL_VERSION));
break;
case GL_EXTENSIONS:
sprintf(num_str, "%0.2f Hz, %dx%d, EXTENSIONS: ", filter(t, th), w_win, h_win);
DrawStr(num_str);
DrawStr(glGetString(GL_EXTENSIONS));
break;
}
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_LIGHTING);
//glEnable(GL_DEPTH_TEST);
}
count++;
glutSwapBuffers();
}
/*
void
Visible(int state)
{
if (state == GLUT_VISIBLE) {
if (moving)
glutIdleFunc(Animate);
} else {
if (moving)
glutIdleFunc(NULL);
}
}
void
timingSelect(int value)
{
switch(value)
{
case 1:
StrMode = GL_VENDOR;
break;
case 2:
StrMode = GL_RENDERER;
break;
case 3:
StrMode = GL_VERSION;
break;
case 4:
StrMode = GL_EXTENSIONS;
break;
}
}
void
menuSelect(int value)
{
switch (value) {
case 1:
moving = GL_TRUE;
glutIdleFunc(Animate);
break;
case 2:
moving = GL_FALSE;
glutIdleFunc(NULL);
break;
case 4:
exit(0);
break;
}
}
int
main(int argc, char **argv)
{
GLboolean fullscreen = GL_FALSE;
GLint time_menu;
srand(0);
glutInit(&argc, argv);
if (argc > 1 && !strcmp(argv[1], "-w"))
fullscreen = GL_FALSE;
//glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitDisplayString("rgba double depth=24");
if (fullscreen) {
glutGameModeString("1024x768:32");
glutEnterGameMode();
} else {
glutInitWindowSize(320, 240);
glutCreateWindow("Atlantis Timing");
}
Init();
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutKeyboardFunc(Key);
moving = GL_TRUE;
glutIdleFunc(Animate);
glutVisibilityFunc(Visible);
time_menu = glutCreateMenu(timingSelect);
glutAddMenuEntry("GL_VENDOR", 1);
glutAddMenuEntry("GL_RENDERER", 2);
glutAddMenuEntry("GL_VERSION", 3);
glutAddMenuEntry("GL_EXTENSIONS", 4);
glutCreateMenu(menuSelect);
glutAddMenuEntry("Start motion", 1);
glutAddMenuEntry("Stop motion", 2);
glutAddSubMenu("Timing Mode", time_menu);
glutAddMenuEntry("Quit", 4);
//glutAttachMenu(GLUT_RIGHT_BUTTON);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0; // ANSI C requires main to return int.
}
*/

View file

@ -0,0 +1,65 @@
/**
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
#define RAD 57.295
#define RRAD 0.01745
#define NUM_SHARKS 4
#define SHARKSIZE 6000
#define SHARKSPEED 100.0
#define WHALESPEED 250.0
typedef struct _fishRec {
float x, y, z, phi, theta, psi, v;
float xt, yt, zt;
float htail, vtail;
float dtheta;
int spurt, attack;
} fishRec;
extern fishRec sharks[NUM_SHARKS];
extern fishRec momWhale;
extern fishRec babyWhale;
extern fishRec dolph;
extern void FishTransform(fishRec *);
extern void WhalePilot(fishRec *);
extern void SharkPilot(fishRec *);
extern void SharkMiss(int);
extern void DrawWhale(fishRec *);
extern void DrawShark(fishRec *);
extern void DrawDolphin(fishRec *);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,188 @@
/**
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
#include <math.h>
#include <stdlib.h> /* For rand(). */
#include <GLUT/glut.h>
#include "atlantis.h"
void
FishTransform(fishRec * fish)
{
glTranslatef(fish->y, fish->z, -fish->x);
glRotatef(-fish->psi, 0.0, 1.0, 0.0);
glRotatef(fish->theta, 1.0, 0.0, 0.0);
glRotatef(-fish->phi, 0.0, 0.0, 1.0);
}
void
WhalePilot(fishRec * fish)
{
fish->phi = -20.0;
fish->theta = 0.0;
fish->psi -= 0.5;
fish->x += WHALESPEED * fish->v * cos(fish->psi / RAD) * cos(fish->theta / RAD);
fish->y += WHALESPEED * fish->v * sin(fish->psi / RAD) * cos(fish->theta / RAD);
fish->z += WHALESPEED * fish->v * sin(fish->theta / RAD);
}
void
SharkPilot(fishRec * fish)
{
static int sign = 1;
float X, Y, Z, tpsi, ttheta, thetal;
fish->xt = 60000.0;
fish->yt = 0.0;
fish->zt = 0.0;
X = fish->xt - fish->x;
Y = fish->yt - fish->y;
Z = fish->zt - fish->z;
thetal = fish->theta;
ttheta = RAD * atan(Z / (sqrt(X * X + Y * Y)));
if (ttheta > fish->theta + 0.25) {
fish->theta += 0.5;
} else if (ttheta < fish->theta - 0.25) {
fish->theta -= 0.5;
}
if (fish->theta > 90.0) {
fish->theta = 90.0;
}
if (fish->theta < -90.0) {
fish->theta = -90.0;
}
fish->dtheta = fish->theta - thetal;
tpsi = RAD * atan2(Y, X);
fish->attack = 0;
if (fabs(tpsi - fish->psi) < 10.0) {
fish->attack = 1;
} else if (fabs(tpsi - fish->psi) < 45.0) {
if (fish->psi > tpsi) {
fish->psi -= 0.5;
if (fish->psi < -180.0) {
fish->psi += 360.0;
}
} else if (fish->psi < tpsi) {
fish->psi += 0.5;
if (fish->psi > 180.0) {
fish->psi -= 360.0;
}
}
} else {
if (rand() % 100 > 98) {
sign = 1 - sign;
}
fish->psi += sign;
if (fish->psi > 180.0) {
fish->psi -= 360.0;
}
if (fish->psi < -180.0) {
fish->psi += 360.0;
}
}
if (fish->attack) {
if (fish->v < 1.1) {
fish->spurt = 1;
}
if (fish->spurt) {
fish->v += 0.2;
}
if (fish->v > 5.0) {
fish->spurt = 0;
}
if ((fish->v > 1.0) && (!fish->spurt)) {
fish->v -= 0.2;
}
} else {
if (!(rand() % 400) && (!fish->spurt)) {
fish->spurt = 1;
}
if (fish->spurt) {
fish->v += 0.05;
}
if (fish->v > 3.0) {
fish->spurt = 0;
}
if ((fish->v > 1.0) && (!fish->spurt)) {
fish->v -= 0.05;
}
}
fish->x += SHARKSPEED * fish->v * cos(fish->psi / RAD) * cos(fish->theta / RAD);
fish->y += SHARKSPEED * fish->v * sin(fish->psi / RAD) * cos(fish->theta / RAD);
fish->z += SHARKSPEED * fish->v * sin(fish->theta / RAD);
}
void
SharkMiss(int i)
{
int j;
float avoid, thetal;
float X, Y, Z, R;
for (j = 0; j < NUM_SHARKS; j++) {
if (j != i) {
X = sharks[j].x - sharks[i].x;
Y = sharks[j].y - sharks[i].y;
Z = sharks[j].z - sharks[i].z;
R = sqrt(X * X + Y * Y + Z * Z);
avoid = 1.0;
thetal = sharks[i].theta;
if (R < SHARKSIZE) {
if (Z > 0.0) {
sharks[i].theta -= avoid;
} else {
sharks[i].theta += avoid;
}
}
sharks[i].dtheta += (sharks[i].theta - thetal);
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,179 @@
/* Simple program: Create a blank window, wait for keypress, quit.
Please see the SDL documentation for details on using the SDL API:
/Developer/Documentation/SDL/docs.html
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "SDL.h"
extern void Atlantis_Init ();
extern void Atlantis_Reshape (int w, int h);
extern void Atlantis_Animate ();
extern void Atlantis_Display ();
static SDL_Surface *gScreen;
static void initAttributes ()
{
// Setup attributes we want for the OpenGL context
int value;
// Don't set color bit sizes (SDL_GL_RED_SIZE, etc)
// Mac OS X will always use 8-8-8-8 ARGB for 32-bit screens and
// 5-5-5 RGB for 16-bit screens
// Request a 16-bit depth buffer (without this, there is no depth buffer)
value = 16;
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, value);
// Request double-buffered OpenGL
// The fact that windows are double-buffered on Mac OS X has no effect
// on OpenGL double buffering.
value = 1;
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, value);
}
static void printAttributes ()
{
// Print out attributes of the context we created
int nAttr;
int i;
int attr[] = { SDL_GL_RED_SIZE, SDL_GL_BLUE_SIZE, SDL_GL_GREEN_SIZE,
SDL_GL_ALPHA_SIZE, SDL_GL_BUFFER_SIZE, SDL_GL_DEPTH_SIZE };
char *desc[] = { "Red size: %d bits\n", "Blue size: %d bits\n", "Green size: %d bits\n",
"Alpha size: %d bits\n", "Color buffer size: %d bits\n",
"Depth bufer size: %d bits\n" };
nAttr = sizeof(attr) / sizeof(int);
for (i = 0; i < nAttr; i++) {
int value;
SDL_GL_GetAttribute (attr[i], &value);
printf (desc[i], value);
}
}
static void createSurface (int fullscreen)
{
Uint32 flags = 0;
flags = SDL_OPENGL;
if (fullscreen)
flags |= SDL_FULLSCREEN;
// Create window
gScreen = SDL_SetVideoMode (640, 480, 0, flags);
if (gScreen == NULL) {
fprintf (stderr, "Couldn't set 640x480 OpenGL video mode: %s\n",
SDL_GetError());
SDL_Quit();
exit(2);
}
}
static void initGL ()
{
Atlantis_Init ();
Atlantis_Reshape (gScreen->w, gScreen->h);
}
static void drawGL ()
{
Atlantis_Animate ();
Atlantis_Display ();
}
static void mainLoop ()
{
SDL_Event event;
int done = 0;
int fps = 24;
int delay = 1000/fps;
int thenTicks = -1;
int nowTicks;
while ( !done ) {
/* Check for events */
while ( SDL_PollEvent (&event) ) {
switch (event.type) {
case SDL_MOUSEMOTION:
break;
case SDL_MOUSEBUTTONDOWN:
break;
case SDL_KEYDOWN:
/* Any keypress quits the app... */
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
// Draw at 24 hz
// This approach is not normally recommended - it is better to
// use time-based animation and run as fast as possible
drawGL ();
SDL_GL_SwapBuffers ();
// Time how long each draw-swap-delay cycle takes
// and adjust delay to get closer to target framerate
if (thenTicks > 0) {
nowTicks = SDL_GetTicks ();
delay += (1000/fps - (nowTicks-thenTicks));
thenTicks = nowTicks;
if (delay < 0)
delay = 1000/fps;
}
else {
thenTicks = SDL_GetTicks ();
}
SDL_Delay (delay);
}
}
int main(int argc, char *argv[])
{
// Init SDL video subsystem
if ( SDL_Init (SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",
SDL_GetError());
exit(1);
}
// Set GL context attributes
initAttributes ();
// Create GL context
createSurface (0);
// Get GL context attributes
printAttributes ();
// Init GL state
initGL ();
// Draw, get events...
mainLoop ();
// Cleanup
SDL_Quit();
return 0;
}