Merge pull request #144 from grahamboree/SDL2

Updated RecastDemo to SDL2
This commit is contained in:
Jakob Botsch Nielsen 2016-01-05 09:00:21 +01:00
commit 1b50ceaa9a
19 changed files with 292 additions and 3678 deletions

View File

@ -2,12 +2,6 @@ sudo: false
language: cpp language: cpp
# Install SDL 1.2 development libraries.
addons:
apt:
packages:
- libsdl1.2-dev
# Build with gcc and clang. # Build with gcc and clang.
compiler: compiler:
- gcc - gcc
@ -20,6 +14,18 @@ env:
- CONFIGURATION=release - CONFIGURATION=release
install: install:
# Download and build SDL2 from source.
- mkdir dummyprefix
- export PREFIX=$PWD/dummyprefix
- export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
- export PATH=$PATH:$PWD/dummyprefix/bin
- wget https://www.libsdl.org/release/SDL2-2.0.4.tar.gz -O SDL2.tar.gz
- tar -xzf SDL2.tar.gz
- cd SDL2-2.0.4
- ./configure --prefix=$PREFIX
- make -j5
- make install
- cd ..
# Download and build premake5 from source; the Travis environment doesn't have the right version of glibc6 for the prebuilt binaries to work. # Download and build premake5 from source; the Travis environment doesn't have the right version of glibc6 for the prebuilt binaries to work.
- wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha6/premake-5.0.0-alpha6-src.zip -O premake.zip - wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha6/premake-5.0.0-alpha6-src.zip -O premake.zip
- unzip premake.zip - unzip premake.zip

View File

@ -40,28 +40,39 @@ You can find a comprehensive demo project in RecastDemo folder. It is a kitchen
### Building RecastDemo ### Building RecastDemo
RecastDemo uses [premake5](http://premake.github.io/) to build platform specific projects. Download it and make sure it's available on your path, or specify the path to it. To build *RecastDemo*, in your favorite terminal navigate into the `RecastDemo` folder, then: RecastDemo uses [premake5](http://premake.github.io/) to build platform specific projects. Download it and make sure it's available on your path, or specify the path to it.
- *OS X*: `premake5 xcode4` #### Linux
- *Windows*: `"premake5" vs2015`
- *Linux*: `premake5 gmake`
See premake5 documentation for full list of supported build file types. The projects will be created in `RecastDemo/Build` folder. And after you have compiled the project, the *RecastDemo* executable will be located in `RecastDemo/Bin` folder. - Install SDl2 and its dependencies according to your distro's guidelines.
- run `premake5 gmake` from the `RecastDemo` folder.
- `cd Build/gmake` then `make`
- Run `RecastDemo\Bin\RecastDemo`
*Note:* On Windows, please use x86 version of the SDL.dll to run the demo Application. #### OSX
- Grab the latest SDL2 development library dmg from [here](https://www.libsdl.org/download-2.0.php) and place `SDL2.framework` in `/Library/Frameworks/`
- Navigate to the `RecastDemo` folder and run `premake5 xcode4`
- Open `Build/xcode4/recastnavigation.xcworkspace`
- Select the "RecastDemo" project in the left pane, go to the "BuildPhases" tab and expand "Link Binary With Libraries"
- Remove the existing entry for SDL2 (it should have a white box icon) and re-add it by hitting the plus, selecting "Add Other", and selecting `/Library/Frameworks/SDL2.framework`. It should now have a suitcase icon.
- Set the RecastDemo project as the target and build.
#### Windows
- Grab the latest SDL2 development library release from [here](https://www.libsdl.org/download-2.0.php) and unzip it `RecastDemo\Contrib`. Rename the SDL folder such that the path `RecastDemo\Contrib\SDL\lib\x86` is valid.
- Run `"premake5" vs2015` from the `RecastDemo` folder
- Open the solution, build, and run.
## Integrating with your own project ## Integrating with your own project
It is recommended to add the source directories `DebugUtils`, `Detour`, `DetourCrowd`, `DetourTileCache`, and `Recast` into your own project depending on which parts of the project you need. For example your level building tool could include DebugUtils, Recast, and Detour, and your game runtime could just include Detour. It is recommended to add the source directories `DebugUtils`, `Detour`, `DetourCrowd`, `DetourTileCache`, and `Recast` into your own project depending on which parts of the project you need. For example your level building tool could include DebugUtils, Recast, and Detour, and your game runtime could just include Detour.
## Discuss ## Discuss
- Discuss Recast & Detour: http://groups.google.com/group/recastnavigation - Discuss Recast & Detour: http://groups.google.com/group/recastnavigation
- Development blog: http://digestingduck.blogspot.com/ - Development blog: http://digestingduck.blogspot.com/
## License ## License
Recast & Detour is licensed under ZLib license, see License.txt for more information. Recast & Detour is licensed under ZLib license, see License.txt for more information.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,11 +0,0 @@
/* 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

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//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>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>Icon.icns</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME:identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

View File

@ -23,6 +23,11 @@
#include <float.h> #include <float.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"
#ifdef __APPLE__
# include <OpenGL/glu.h>
#else
# include <GL/glu.h>
#endif
#include "imgui.h" #include "imgui.h"
#include "CrowdTool.h" #include "CrowdTool.h"
#include "InputGeom.h" #include "InputGeom.h"
@ -38,7 +43,6 @@
# define snprintf _snprintf # define snprintf _snprintf
#endif #endif
static bool isectSegAABB(const float* sp, const float* sq, static bool isectSegAABB(const float* sp, const float* sq,
const float* amin, const float* amax, const float* amin, const float* amax,
float& tmin, float& tmax) float& tmin, float& tmax)

View File

@ -23,6 +23,11 @@
#include <string.h> #include <string.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"
#ifdef __APPLE__
# include <OpenGL/glu.h>
#else
# include <GL/glu.h>
#endif
#include "imgui.h" #include "imgui.h"
#include "NavMeshTesterTool.h" #include "NavMeshTesterTool.h"
#include "Sample.h" #include "Sample.h"

View File

@ -23,6 +23,11 @@
#include <float.h> #include <float.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"
#ifdef __APPLE__
# include <OpenGL/glu.h>
#else
# include <GL/glu.h>
#endif
#include "imgui.h" #include "imgui.h"
#include "OffMeshConnectionTool.h" #include "OffMeshConnectionTool.h"
#include "InputGeom.h" #include "InputGeom.h"

View File

@ -1,384 +0,0 @@
/* 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

@ -24,6 +24,11 @@
#include <new> #include <new>
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"
#ifdef __APPLE__
# include <OpenGL/glu.h>
#else
# include <GL/glu.h>
#endif
#include "imgui.h" #include "imgui.h"
#include "InputGeom.h" #include "InputGeom.h"
#include "Sample.h" #include "Sample.h"

View File

@ -22,6 +22,11 @@
#include <string.h> #include <string.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"
#ifdef __APPLE__
# include <OpenGL/glu.h>
#else
# include <GL/glu.h>
#endif
#include "imgui.h" #include "imgui.h"
#include "InputGeom.h" #include "InputGeom.h"
#include "Sample.h" #include "Sample.h"

View File

@ -19,7 +19,7 @@
#include "SlideShow.h" #include "SlideShow.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <SDL_opengl.h> #include "SDL_opengl.h"
//#define STBI_HEADER_FILE_ONLY //#define STBI_HEADER_FILE_ONLY
#include "stb_image.h" #include "stb_image.h"

View File

@ -26,6 +26,11 @@
#include "DetourCommon.h" #include "DetourCommon.h"
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"
#ifdef __APPLE__
# include <OpenGL/glu.h>
#else
# include <GL/glu.h>
#endif
#include "imgui.h" #include "imgui.h"
#include "PerfTimer.h" #include "PerfTimer.h"

View File

@ -17,7 +17,8 @@
// //
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include <math.h> #include <cmath>
#include <cstdio>
#include "imgui.h" #include "imgui.h"
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"

View File

@ -16,20 +16,27 @@
// 3. This notice may not be removed or altered from any source distribution. // 3. This notice may not be removed or altered from any source distribution.
// //
#include <stdio.h> #include <cstdio>
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include <math.h> #include <cmath>
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"
#ifdef __APPLE__
# include <OpenGL/glu.h>
#else
# include <GL/glu.h>
#endif
#include "imgui.h" #include "imgui.h"
#include "imguiRenderGL.h" #include "imguiRenderGL.h"
#include "Recast.h" #include "Recast.h"
#include "RecastDebugDraw.h" #include "RecastDebugDraw.h"
#include "InputGeom.h" #include "InputGeom.h"
#include "TestCase.h" #include "TestCase.h"
#include "Filelist.h" #include "Filelist.h"
#include "SlideShow.h" #include "SlideShow.h"
#include "Sample_SoloMesh.h" #include "Sample_SoloMesh.h"
#include "Sample_TileMesh.h" #include "Sample_TileMesh.h"
#include "Sample_TempObstacles.h" #include "Sample_TempObstacles.h"
@ -45,12 +52,10 @@ struct SampleItem
Sample* (*create)(); Sample* (*create)();
const char* name; const char* name;
}; };
Sample* createSolo() { return new Sample_SoloMesh(); } Sample* createSolo() { return new Sample_SoloMesh(); }
Sample* createTile() { return new Sample_TileMesh(); } Sample* createTile() { return new Sample_TileMesh(); }
Sample* createTempObstacle() { return new Sample_TempObstacles(); } Sample* createTempObstacle() { return new Sample_TempObstacles(); }
Sample* createDebug() { return new Sample_Debug(); } Sample* createDebug() { return new Sample_Debug(); }
static SampleItem g_samples[] = static SampleItem g_samples[] =
{ {
{ createSolo, "Solo Mesh" }, { createSolo, "Solo Mesh" },
@ -60,62 +65,62 @@ static SampleItem g_samples[] =
}; };
static const int g_nsamples = sizeof(g_samples) / sizeof(SampleItem); static const int g_nsamples = sizeof(g_samples) / sizeof(SampleItem);
int main(int /*argc*/, char** /*argv*/) int main(int /*argc*/, char** /*argv*/)
{ {
// Init SDL // Init SDL
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{ {
printf("Could not initialise SDL\n"); printf("Could not initialise SDL.\nError: %s\n", SDL_GetError());
return -1; return -1;
} }
// Center window // Enable depth buffer.
char env[] = "SDL_VIDEO_CENTERED=1";
putenv(env);
// Init OpenGL
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
// Set color channel depth.
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
//#ifndef WIN32
// 4x MSAA.
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
//#endif
const SDL_VideoInfo* vi = SDL_GetVideoInfo(); SDL_DisplayMode displayMode;
SDL_GetCurrentDisplayMode(0, &displayMode);
bool presentationMode = false; bool presentationMode = false;
Uint32 flags = SDL_WINDOW_OPENGL;
int width, height; int width;
SDL_Surface* screen = 0; int height;
if (presentationMode) if (presentationMode)
{ {
width = vi->current_w; // Create a fullscreen window at the native resolution.
height = vi->current_h; width = displayMode.w;
screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL|SDL_FULLSCREEN); height = displayMode.h;
flags |= SDL_WINDOW_FULLSCREEN;
} }
else else
{ {
width = rcMin(vi->current_w, (int)(vi->current_h * 16.0 / 9.0)); float aspect = 16.0f / 9.0f;
width = width - 80; width = rcMin(displayMode.w, (int)(displayMode.h * aspect)) - 80;
height = vi->current_h - 80; height = displayMode.h - 80;
screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
} }
if (!screen) SDL_Window* window;
SDL_Renderer* renderer;
int errorCode = SDL_CreateWindowAndRenderer(width, height, flags, &window, &renderer);
if (errorCode != 0 || !window || !renderer)
{ {
printf("Could not initialise SDL opengl\n"); printf("Could not initialise SDL opengl\nError: %s\n", SDL_GetError());
return -1; return -1;
} }
glEnable(GL_MULTISAMPLE); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
SDL_GL_CreateContext(window);
SDL_WM_SetCaption("Recast Demo", 0);
if (!imguiRenderGLInit("DroidSans.ttf")) if (!imguiRenderGLInit("DroidSans.ttf"))
{ {
@ -126,19 +131,24 @@ int main(int /*argc*/, char** /*argv*/)
float t = 0.0f; float t = 0.0f;
float timeAcc = 0.0f; float timeAcc = 0.0f;
Uint32 lastTime = SDL_GetTicks(); Uint32 prevFrameTime = SDL_GetTicks();
int mx = 0, my = 0; int mousePos[2] = {0, 0};
float rx = 45; float origMousePos[2] = {0, 0}; // Used to compute mouse movement totals across frames.
float ry = -45;
float cameraEulers[] = {45, -45};
float cameraPos[] = {0, 0, 0};
float camr = 1000;
float origCameraEulers[] = {0, 0}; // Used to compute rotational changes across frames.
float moveW = 0, moveS = 0, moveA = 0, moveD = 0; float moveW = 0, moveS = 0, moveA = 0, moveD = 0;
float camx = 0, camy = 0, camz = 0, camr = 1000;
float origrx = 0, origry = 0;
int origx = 0, origy = 0;
float scrollZoom = 0; float scrollZoom = 0;
bool rotate = false; bool rotate = false;
bool movedDuringRotate = false; bool movedDuringRotate = false;
float rays[3], raye[3]; float rayStart[3];
float rayEnd[3];
bool mouseOverMenu = false; bool mouseOverMenu = false;
bool showMenu = !presentationMode; bool showMenu = !presentationMode;
bool showLog = false; bool showLog = false;
bool showTools = true; bool showTools = true;
@ -146,6 +156,7 @@ int main(int /*argc*/, char** /*argv*/)
bool showSample = false; bool showSample = false;
bool showTestCases = false; bool showTestCases = false;
// Window scroll positions.
int propScroll = 0; int propScroll = 0;
int logScroll = 0; int logScroll = 0;
int toolsScroll = 0; int toolsScroll = 0;
@ -155,8 +166,8 @@ int main(int /*argc*/, char** /*argv*/)
FileList files; FileList files;
char meshName[128] = "Choose Mesh..."; char meshName[128] = "Choose Mesh...";
float mpos[3] = {0,0,0}; float markerPosition[3] = {0, 0, 0};
bool mposSet = false; bool markerPositionSet = false;
SlideShow slideShow; SlideShow slideShow;
slideShow.init("slides/"); slideShow.init("slides/");
@ -167,22 +178,22 @@ int main(int /*argc*/, char** /*argv*/)
BuildContext ctx; BuildContext ctx;
glEnable(GL_CULL_FACE); // Fog.
float fogColor[4] = { 0.32f, 0.31f, 0.30f, 1.0f };
float fogCol[4] = { 0.32f, 0.31f, 0.30f, 1.0f };
glEnable(GL_FOG); glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_LINEAR); glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, camr * 0.1f); glFogf(GL_FOG_START, camr * 0.1f);
glFogf(GL_FOG_END, camr * 1.25f); glFogf(GL_FOG_END, camr * 1.25f);
glFogfv(GL_FOG_COLOR, fogCol); glFogfv(GL_FOG_COLOR, fogColor);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
bool done = false; bool done = false;
while(!done) while(!done)
{ {
// Handle input events. // Handle input events.
int mscroll = 0; int mouseScroll = 0;
bool processHitTest = false; bool processHitTest = false;
bool processHitTestShift = false; bool processHitTestShift = false;
SDL_Event event; SDL_Event event;
@ -261,13 +272,13 @@ int main(int /*argc*/, char** /*argv*/)
camr = sqrtf(rcSqr(bmax[0] - bmin[0]) + camr = sqrtf(rcSqr(bmax[0] - bmin[0]) +
rcSqr(bmax[1] - bmin[1]) + rcSqr(bmax[1] - bmin[1]) +
rcSqr(bmax[2] - bmin[2])) / 2; rcSqr(bmax[2] - bmin[2])) / 2;
camx = (bmax[0] + bmin[0]) / 2 + camr; cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
camy = (bmax[1] + bmin[1]) / 2 + camr; cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
camz = (bmax[2] + bmin[2]) / 2 + camr; cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
camr *= 3; camr *= 3;
} }
rx = 45; cameraEulers[0] = 45;
ry = -45; cameraEulers[1] = -45;
glFogf(GL_FOG_START, camr * 0.2f); glFogf(GL_FOG_START, camr * 0.2f);
glFogf(GL_FOG_END, camr * 1.25f); glFogf(GL_FOG_END, camr * 1.25f);
} }
@ -282,6 +293,31 @@ int main(int /*argc*/, char** /*argv*/)
} }
break; break;
case SDL_MOUSEWHEEL:
if (event.wheel.y < 0)
{
// wheel down
if (mouseOverMenu)
{
mouseScroll++;
}
else
{
scrollZoom += 1.0f;
}
}
else
{
if (mouseOverMenu)
{
mouseScroll--;
}
else
{
scrollZoom -= 1.0f;
}
}
break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
if (event.button.button == SDL_BUTTON_RIGHT) if (event.button.button == SDL_BUTTON_RIGHT)
{ {
@ -290,26 +326,12 @@ int main(int /*argc*/, char** /*argv*/)
// Rotate view // Rotate view
rotate = true; rotate = true;
movedDuringRotate = false; movedDuringRotate = false;
origx = mx; origMousePos[0] = mousePos[0];
origy = my; origMousePos[1] = mousePos[1];
origrx = rx; origCameraEulers[0] = cameraEulers[0];
origry = ry; origCameraEulers[1] = cameraEulers[1];
} }
} }
else if (event.button.button == SDL_BUTTON_WHEELUP)
{
if (mouseOverMenu)
mscroll--;
else
scrollZoom -= 1.0f;
}
else if (event.button.button == SDL_BUTTON_WHEELDOWN)
{
if (mouseOverMenu)
mscroll++;
else
scrollZoom += 1.0f;
}
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
@ -338,17 +360,20 @@ int main(int /*argc*/, char** /*argv*/)
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
mx = event.motion.x; mousePos[0] = event.motion.x;
my = height-1 - event.motion.y; mousePos[1] = height-1 - event.motion.y;
if (rotate) if (rotate)
{ {
int dx = mx - origx; int dx = mousePos[0] - origMousePos[0];
int dy = my - origy; int dy = mousePos[1] - origMousePos[1];
rx = origrx - dy*0.25f; cameraEulers[0] = origCameraEulers[0] - dy * 0.25f;
ry = origry + dx*0.25f; cameraEulers[1] = origCameraEulers[1] + dx * 0.25f;
if (dx * dx + dy * dy > 3 * 3) if (dx * dx + dy * dy > 3 * 3)
{
movedDuringRotate = true; movedDuringRotate = true;
} }
}
break; break;
case SDL_QUIT: case SDL_QUIT:
@ -360,42 +385,41 @@ int main(int /*argc*/, char** /*argv*/)
} }
} }
unsigned char mbut = 0; unsigned char mouseButtonMask = 0;
if (SDL_GetMouseState(0, 0) & SDL_BUTTON_LMASK) if (SDL_GetMouseState(0, 0) & SDL_BUTTON_LMASK)
mbut |= IMGUI_MBUT_LEFT; mouseButtonMask |= IMGUI_MBUT_LEFT;
if (SDL_GetMouseState(0, 0) & SDL_BUTTON_RMASK) if (SDL_GetMouseState(0, 0) & SDL_BUTTON_RMASK)
mbut |= IMGUI_MBUT_RIGHT; mouseButtonMask |= IMGUI_MBUT_RIGHT;
Uint32 time = SDL_GetTicks(); Uint32 time = SDL_GetTicks();
float dt = (time - lastTime) / 1000.0f; float dt = (time - prevFrameTime) / 1000.0f;
lastTime = time; prevFrameTime = time;
t += dt; t += dt;
// Hit test mesh. // Hit test mesh.
if (processHitTest && geom && sample) if (processHitTest && geom && sample)
{ {
float hitt; float hitTime;
bool hit = geom->raycastMesh(rays, raye, hitt); bool hit = geom->raycastMesh(rayStart, rayEnd, hitTime);
if (hit) if (hit)
{ {
if (SDL_GetModState() & KMOD_CTRL) if (SDL_GetModState() & KMOD_CTRL)
{ {
// Marker // Marker
mposSet = true; markerPositionSet = true;
mpos[0] = rays[0] + (raye[0] - rays[0])*hitt; markerPosition[0] = rayStart[0] + (rayEnd[0] - rayStart[0]) * hitTime;
mpos[1] = rays[1] + (raye[1] - rays[1])*hitt; markerPosition[1] = rayStart[1] + (rayEnd[1] - rayStart[1]) * hitTime;
mpos[2] = rays[2] + (raye[2] - rays[2])*hitt; markerPosition[2] = rayStart[2] + (rayEnd[2] - rayStart[2]) * hitTime;
} }
else else
{ {
float pos[3]; float pos[3];
pos[0] = rays[0] + (raye[0] - rays[0])*hitt; pos[0] = rayStart[0] + (rayEnd[0] - rayStart[0]) * hitTime;
pos[1] = rays[1] + (raye[1] - rays[1])*hitt; pos[1] = rayStart[1] + (rayEnd[1] - rayStart[1]) * hitTime;
pos[2] = rays[2] + (raye[2] - rays[2])*hitt; pos[2] = rayStart[2] + (rayEnd[2] - rayStart[2]) * hitTime;
sample->handleClick(rays, pos, processHitTestShift); sample->handleClick(rayStart, pos, processHitTestShift);
} }
} }
else else
@ -403,7 +427,7 @@ int main(int /*argc*/, char** /*argv*/)
if (SDL_GetModState() & KMOD_CTRL) if (SDL_GetModState() & KMOD_CTRL)
{ {
// Marker // Marker
mposSet = false; markerPositionSet = false;
} }
} }
} }
@ -416,9 +440,8 @@ int main(int /*argc*/, char** /*argv*/)
while (timeAcc > DELTA_TIME) while (timeAcc > DELTA_TIME)
{ {
timeAcc -= DELTA_TIME; timeAcc -= DELTA_TIME;
if (simIter < 5) if (simIter < 5 && sample)
{ {
if (sample)
sample->handleUpdate(DELTA_TIME); sample->handleUpdate(DELTA_TIME);
} }
simIter++; simIter++;
@ -430,67 +453,73 @@ int main(int /*argc*/, char** /*argv*/)
{ {
int ms = (int)((MIN_FRAME_TIME - dt) * 1000.0f); int ms = (int)((MIN_FRAME_TIME - dt) * 1000.0f);
if (ms > 10) ms = 10; if (ms > 10) ms = 10;
if (ms >= 0) if (ms >= 0) SDL_Delay(ms);
SDL_Delay(ms);
} }
// Set the viewport.
// Update and render
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
// Clear the screen
glClearColor(0.3f, 0.3f, 0.32f, 1.0f); glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
// Render 3d
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
// Compute the projection matrix.
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluPerspective(50.0f, (float)width/(float)height, 1.0f, camr); gluPerspective(50.0f, (float)width/(float)height, 1.0f, camr);
GLdouble projectionMatrix[16];
glGetDoublev(GL_PROJECTION_MATRIX, projectionMatrix);
// Compute the modelview matrix.
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glRotatef(rx,1,0,0); glRotatef(cameraEulers[0], 1, 0, 0);
glRotatef(ry,0,1,0); glRotatef(cameraEulers[1], 0, 1, 0);
glTranslatef(-camx, -camy, -camz); glTranslatef(-cameraPos[0], -cameraPos[1], -cameraPos[2]);
GLdouble modelviewMatrix[16];
glGetDoublev(GL_MODELVIEW_MATRIX, modelviewMatrix);
// Get hit ray position and direction. // Get hit ray position and direction.
GLdouble proj[16];
GLdouble model[16];
GLint view[4];
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetDoublev(GL_MODELVIEW_MATRIX, model);
glGetIntegerv(GL_VIEWPORT, view);
GLdouble x, y, z; GLdouble x, y, z;
gluUnProject(mx, my, 0.0f, model, proj, view, &x, &y, &z); gluUnProject(mousePos[0], mousePos[1], 0.0f, modelviewMatrix, projectionMatrix, viewport, &x, &y, &z);
rays[0] = (float)x; rays[1] = (float)y; rays[2] = (float)z; rayStart[0] = (float)x;
gluUnProject(mx, my, 1.0f, model, proj, view, &x, &y, &z); rayStart[1] = (float)y;
raye[0] = (float)x; raye[1] = (float)y; raye[2] = (float)z; rayStart[2] = (float)z;
gluUnProject(mousePos[0], mousePos[1], 1.0f, modelviewMatrix, projectionMatrix, viewport, &x, &y, &z);
rayEnd[0] = (float)x;
rayEnd[1] = (float)y;
rayEnd[2] = (float)z;
// Handle keyboard movement. // Handle keyboard movement.
Uint8* keystate = SDL_GetKeyState(NULL); const Uint8* keystate = SDL_GetKeyboardState(NULL);
moveW = rcClamp(moveW + dt * 4 * (keystate[SDLK_w] ? 1 : -1), 0.0f, 1.0f); moveW = rcClamp(moveW + dt * 4 * (keystate[SDL_SCANCODE_W] ? 1 : -1), 0.0f, 1.0f);
moveS = rcClamp(moveS + dt * 4 * (keystate[SDLK_s] ? 1 : -1), 0.0f, 1.0f); moveA = rcClamp(moveA + dt * 4 * (keystate[SDL_SCANCODE_A] ? 1 : -1), 0.0f, 1.0f);
moveA = rcClamp(moveA + dt * 4 * (keystate[SDLK_a] ? 1 : -1), 0.0f, 1.0f); moveS = rcClamp(moveS + dt * 4 * (keystate[SDL_SCANCODE_S] ? 1 : -1), 0.0f, 1.0f);
moveD = rcClamp(moveD + dt * 4 * (keystate[SDLK_d] ? 1 : -1), 0.0f, 1.0f); moveD = rcClamp(moveD + dt * 4 * (keystate[SDL_SCANCODE_D] ? 1 : -1), 0.0f, 1.0f);
float keybSpeed = 22.0f; float keybSpeed = 22.0f;
if (SDL_GetModState() & KMOD_SHIFT) if (SDL_GetModState() & KMOD_SHIFT)
{
keybSpeed *= 4.0f; keybSpeed *= 4.0f;
}
float movex = (moveD - moveA) * keybSpeed * dt; float movex = (moveD - moveA) * keybSpeed * dt;
float movey = (moveS - moveW) * keybSpeed * dt; float movey = (moveS - moveW) * keybSpeed * dt + scrollZoom * 2.0f;
movey += scrollZoom * 2.0f;
scrollZoom = 0; scrollZoom = 0;
camx += movex * (float)model[0]; cameraPos[0] += movex * (float)modelviewMatrix[0];
camy += movex * (float)model[4]; cameraPos[1] += movex * (float)modelviewMatrix[4];
camz += movex * (float)model[8]; cameraPos[2] += movex * (float)modelviewMatrix[8];
camx += movey * (float)model[2]; cameraPos[0] += movey * (float)modelviewMatrix[2];
camy += movey * (float)model[6]; cameraPos[1] += movey * (float)modelviewMatrix[6];
camz += movey * (float)model[10]; cameraPos[2] += movey * (float)modelviewMatrix[10];
glEnable(GL_FOG); glEnable(GL_FOG);
@ -511,15 +540,15 @@ int main(int /*argc*/, char** /*argv*/)
mouseOverMenu = false; mouseOverMenu = false;
imguiBeginFrame(mx,my,mbut,mscroll); imguiBeginFrame(mousePos[0], mousePos[1], mouseButtonMask, mouseScroll);
if (sample) if (sample)
{ {
sample->handleRenderOverlay((double*)proj, (double*)model, (int*)view); sample->handleRenderOverlay((double*)projectionMatrix, (double*)modelviewMatrix, (int*)viewport);
} }
if (test) if (test)
{ {
if (test->handleRenderOverlay((double*)proj, (double*)model, (int*)view)) if (test->handleRenderOverlay((double*)projectionMatrix, (double*)modelviewMatrix, (int*)viewport))
mouseOverMenu = true; mouseOverMenu = true;
} }
@ -664,13 +693,13 @@ int main(int /*argc*/, char** /*argv*/)
camr = sqrtf(rcSqr(bmax[0]-bmin[0]) + camr = sqrtf(rcSqr(bmax[0]-bmin[0]) +
rcSqr(bmax[1]-bmin[1]) + rcSqr(bmax[1]-bmin[1]) +
rcSqr(bmax[2]-bmin[2])) / 2; rcSqr(bmax[2]-bmin[2])) / 2;
camx = (bmax[0] + bmin[0]) / 2 + camr; cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
camy = (bmax[1] + bmin[1]) / 2 + camr; cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
camz = (bmax[2] + bmin[2]) / 2 + camr; cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
camr *= 3; camr *= 3;
} }
rx = 45; cameraEulers[0] = 45;
ry = -45; cameraEulers[1] = -45;
glFogf(GL_FOG_START, camr*0.1f); glFogf(GL_FOG_START, camr*0.1f);
glFogf(GL_FOG_END, camr*1.25f); glFogf(GL_FOG_END, camr*1.25f);
} }
@ -740,13 +769,13 @@ int main(int /*argc*/, char** /*argv*/)
camr = sqrtf(rcSqr(bmax[0]-bmin[0]) + camr = sqrtf(rcSqr(bmax[0]-bmin[0]) +
rcSqr(bmax[1]-bmin[1]) + rcSqr(bmax[1]-bmin[1]) +
rcSqr(bmax[2]-bmin[2])) / 2; rcSqr(bmax[2]-bmin[2])) / 2;
camx = (bmax[0] + bmin[0]) / 2 + camr; cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
camy = (bmax[1] + bmin[1]) / 2 + camr; cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
camz = (bmax[2] + bmin[2]) / 2 + camr; cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
camr *= 3; camr *= 3;
} }
rx = 45; cameraEulers[0] = 45;
ry = -45; cameraEulers[1] = -45;
glFogf(GL_FOG_START, camr * 0.1f); glFogf(GL_FOG_START, camr * 0.1f);
glFogf(GL_FOG_END, camr * 1.25f); glFogf(GL_FOG_END, camr * 1.25f);
} }
@ -857,13 +886,13 @@ int main(int /*argc*/, char** /*argv*/)
camr = sqrtf(rcSqr(bmax[0] - bmin[0]) + camr = sqrtf(rcSqr(bmax[0] - bmin[0]) +
rcSqr(bmax[1] - bmin[1]) + rcSqr(bmax[1] - bmin[1]) +
rcSqr(bmax[2] - bmin[2])) / 2; rcSqr(bmax[2] - bmin[2])) / 2;
camx = (bmax[0] + bmin[0]) / 2 + camr; cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
camy = (bmax[1] + bmin[1]) / 2 + camr; cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
camz = (bmax[2] + bmin[2]) / 2 + camr; cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
camr *= 3; camr *= 3;
} }
rx = 45; cameraEulers[0] = 45;
ry = -45; cameraEulers[1] = -45;
glFogf(GL_FOG_START, camr * 0.2f); glFogf(GL_FOG_START, camr * 0.2f);
glFogf(GL_FOG_END, camr * 1.25f); glFogf(GL_FOG_END, camr * 1.25f);
} }
@ -888,7 +917,7 @@ int main(int /*argc*/, char** /*argv*/)
imguiEndScrollArea(); imguiEndScrollArea();
} }
// Tools // Left column tools menu
if (!showTestCases && showTools && showMenu) // && geom && sample) if (!showTestCases && showTools && showMenu) // && geom && sample)
{ {
if (imguiBeginScrollArea("Tools", 10, 10, 250, height - 20, &toolsScroll)) if (imguiBeginScrollArea("Tools", 10, 10, 250, height - 20, &toolsScroll))
@ -903,8 +932,8 @@ int main(int /*argc*/, char** /*argv*/)
slideShow.updateAndDraw(dt, (float)width, (float)height); slideShow.updateAndDraw(dt, (float)width, (float)height);
// Marker // Marker
if (mposSet && gluProject((GLdouble)mpos[0], (GLdouble)mpos[1], (GLdouble)mpos[2], if (markerPositionSet && gluProject((GLdouble)markerPosition[0], (GLdouble)markerPosition[1], (GLdouble)markerPosition[2],
model, proj, view, &x, &y, &z)) modelviewMatrix, projectionMatrix, viewport, &x, &y, &z))
{ {
// Draw marker circle // Draw marker circle
glLineWidth(5.0f); glLineWidth(5.0f);
@ -926,7 +955,7 @@ int main(int /*argc*/, char** /*argv*/)
imguiRenderGLDraw(); imguiRenderGLDraw();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
SDL_GL_SwapBuffers(); SDL_GL_SwapWindow(window);
} }
imguiRenderGLDestroy(); imguiRenderGLDestroy();

View File

@ -17,10 +17,10 @@ solution "recastnavigation"
flags { flags {
"ExtraWarnings", "ExtraWarnings",
"FloatFast", "FloatFast",
"NoExceptions",
"NoRTTI",
"Symbols" "Symbols"
} }
exceptionhandling "Off"
rtti "Off"
-- debug configs -- debug configs
configuration "Debug*" configuration "Debug*"
@ -135,12 +135,12 @@ project "RecastDemo"
-- linux library cflags and libs -- linux library cflags and libs
configuration { "linux", "gmake" } configuration { "linux", "gmake" }
buildoptions { buildoptions {
"`pkg-config --cflags sdl`", "`pkg-config --cflags sdl2`",
"`pkg-config --cflags gl`", "`pkg-config --cflags gl`",
"`pkg-config --cflags glu`" "`pkg-config --cflags glu`"
} }
linkoptions { linkoptions {
"`pkg-config --libs sdl`", "`pkg-config --libs sdl2`",
"`pkg-config --libs gl`", "`pkg-config --libs gl`",
"`pkg-config --libs glu`" "`pkg-config --libs glu`"
} }
@ -149,30 +149,26 @@ project "RecastDemo"
configuration { "windows" } configuration { "windows" }
includedirs { "../RecastDemo/Contrib/SDL/include" } includedirs { "../RecastDemo/Contrib/SDL/include" }
libdirs { "../RecastDemo/Contrib/SDL/lib/x86" } libdirs { "../RecastDemo/Contrib/SDL/lib/x86" }
debugdir "../RecastDemo/Bin/"
links { links {
"opengl32",
"glu32", "glu32",
"sdlmain", "opengl32",
"sdl" "SDL2",
"SDL2main",
}
postbuildcommands {
-- Copy the SDL2 dll to the Bin folder.
"{COPY} %{wks.location}../../Contrib/SDL/lib/x86/SDL2.dll %{cfg.targetdir}"
} }
-- mac includes and libs -- mac includes and libs
configuration { "macosx" } configuration { "macosx" }
kind "ConsoleApp" -- xcode4 failes to run the project if using WindowedApp kind "ConsoleApp" -- xcode4 failes to run the project if using WindowedApp
includedirs { "/Library/Frameworks/SDL.framework/Headers" } includedirs { "/Library/Frameworks/SDL2.framework/Headers" }
buildoptions { "-Wunused-value -Wshadow -Wreorder -Wsign-compare -Wall" } buildoptions { "-Wunused-value -Wshadow -Wreorder -Wsign-compare -Wall" }
links { links {
"OpenGL.framework", "OpenGL.framework",
"/Library/Frameworks/SDL.framework", "SDL2.framework",
"Cocoa.framework", "Cocoa.framework",
} }
files {
"../RecastDemo/Include/SDLMain.h",
"../RecastDemo/Source/SDLMain.m",
-- These don't seem to work in xcode4 target yet.
-- "Info.plist",
-- "Icon.icns",
-- "English.lproj/InfoPlist.strings",
-- "English.lproj/MainMenu.xib",
}

View File

@ -7,21 +7,20 @@ environment:
matrix: matrix:
- TOOLSET: vs2010 - TOOLSET: vs2010
- TOOLSET: vs2013 - TOOLSET: vs2013
# Can't use vs2015 toolset yet as it appears SDL 1.2 has some link errors with it. - TOOLSET: vs2015
# - TOOLSET: vs2015
install: install:
# Download Premake # Download Premake
- ps: Start-FileDownload 'https://github.com/premake/premake-core/releases/download/v5.0.0-alpha6/premake-5.0.0-alpha6-windows.zip' 'premake.zip' - ps: Start-FileDownload 'https://github.com/premake/premake-core/releases/download/v5.0.0-alpha7/premake-5.0.0-alpha7-windows.zip' 'premake.zip'
# Extract it in-place; premake5.exe is at the top level. # Extract it in-place; premake5.exe is at the top level.
- 7z x premake.zip - 7z x premake.zip
# Download SDL. # Download SDL.
- ps: Start-FileDownload 'https://www.libsdl.org/release/SDL-devel-1.2.15-VC.zip' 'RecastDemo/Contrib/SDL.zip' - ps: Start-FileDownload 'https://www.libsdl.org/release/SDL2-devel-2.0.4-VC.zip' 'RecastDemo/Contrib/SDL.zip'
# Extract it and put it in the right place. # Extract it, put it in the right place, and rename it.
- cd RecastDemo/Contrib && 7z x SDL.zip && mv SDL-1.2.15 SDL && cd ../.. - cd RecastDemo/Contrib && 7z x SDL.zip && ren SDL2-2.0.4 SDL && cd ../..
# Generate solution files using premake. # Generate solution files using premake.
- cd RecastDemo && "../premake5.exe" %TOOLSET% && cd .. - cd RecastDemo && "../premake5.exe" %TOOLSET% && cd ..