Slideshow stuff for demo purposes.

This commit is contained in:
Mikko Mononen 2010-04-13 11:11:22 +00:00
parent 193f44a388
commit d6d51b73ee
9 changed files with 5136 additions and 1355 deletions

File diff suppressed because it is too large Load Diff

View File

@ -197,7 +197,48 @@
<key>Notifications</key>
<array/>
<key>OpenEditors</key>
<array/>
<array>
<dict>
<key>Content</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>6BF5F29911747CFA000502A6</string>
<key>PBXProjectModuleLabel</key>
<string>glimage.h</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>6BF5F29A11747CFA000502A6</string>
<key>PBXProjectModuleLabel</key>
<string>glimage.h</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>6BF5F30511748884000502A6</string>
<key>history</key>
<array>
<string>6BF5F2B811747E6F000502A6</string>
</array>
</dict>
<key>SplitCount</key>
<string>1</string>
</dict>
<key>StatusBarVisibility</key>
<true/>
</dict>
<key>Geometry</key>
<dict>
<key>Frame</key>
<string>{{0, 20}, {1214, 625}}</string>
<key>PBXModuleWindowStatusBarHidden2</key>
<false/>
<key>RubberWindowFrame</key>
<string>15 107 1214 666 0 0 1280 778 </string>
</dict>
</dict>
</array>
<key>PerspectiveWidths</key>
<array>
<integer>1256</integer>
@ -267,10 +308,7 @@
<array>
<string>29B97314FDCFA39411CA2CEA</string>
<string>080E96DDFE201D6D7F000001</string>
<string>6BB93C7610CFE1BD00F74F2B</string>
<string>6BDD9E030F91110C00904EEF</string>
<string>6B555DF5100B25FC00247EA3</string>
<string>6BB7FE8E10F4A175006DA0A6</string>
<string>6B137C7D0F7FCBE800459200</string>
<string>29B97315FDCFA39411CA2CEA</string>
<string>29B97317FDCFA39411CA2CEA</string>
<string>29B97323FDCFA39411CA2CEA</string>
@ -282,14 +320,13 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>37</integer>
<integer>33</integer>
<integer>20</integer>
<integer>1</integer>
<integer>0</integer>
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
<string>{{0, 217}, {264, 643}}</string>
<string>{{0, 82}, {264, 643}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
@ -324,7 +361,7 @@
<key>PBXProjectModuleGUID</key>
<string>6B8632A30F78115100E2684A</string>
<key>PBXProjectModuleLabel</key>
<string>DetourNavMesh.cpp</string>
<string>main.cpp</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
@ -332,11 +369,11 @@
<key>PBXProjectModuleGUID</key>
<string>6B8632A40F78115100E2684A</string>
<key>PBXProjectModuleLabel</key>
<string>DetourNavMesh.cpp</string>
<string>main.cpp</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>6BED8AF81174570F00582F38</string>
<string>6BF5F2FB11748884000502A6</string>
<key>history</key>
<array>
<string>6BBB4A94115B4F3400CF791D</string>
@ -358,10 +395,8 @@
<string>6BBB4AA6115B4F3400CF791D</string>
<string>6BBB4AA7115B4F3400CF791D</string>
<string>6BBB4AA8115B4F3400CF791D</string>
<string>6BBB4AA9115B4F3400CF791D</string>
<string>6BBB4AAA115B4F3400CF791D</string>
<string>6BBB4AAB115B4F3400CF791D</string>
<string>6BBB4AAC115B4F3400CF791D</string>
<string>6BBB4AB0115B4F3400CF791D</string>
<string>6BBB4AB1115B4F3400CF791D</string>
<string>6BBB4AB2115B4F3400CF791D</string>
@ -380,7 +415,6 @@
<string>6BBB4AC4115B4F3400CF791D</string>
<string>6BBB4AC5115B4F3400CF791D</string>
<string>6BBB4AC6115B4F3400CF791D</string>
<string>6BBB4AC7115B4F3400CF791D</string>
<string>6BBB4AC8115B4F3400CF791D</string>
<string>6BBB4AC9115B4F3400CF791D</string>
<string>6BBB4ACB115B4F3400CF791D</string>
@ -397,11 +431,16 @@
<string>6BED8AE2117451EB00582F38</string>
<string>6BED8AEE117455CB00582F38</string>
<string>6BED8AF21174567000582F38</string>
<string>6BED8AF31174567000582F38</string>
</array>
<key>nextStack</key>
<array>
<string>6BED8AF41174567000582F38</string>
<string>6BF5F231117474CF000502A6</string>
<string>6BF5F27011747CFA000502A6</string>
<string>6BF5F27311747CFA000502A6</string>
<string>6BF5F2E411748884000502A6</string>
<string>6BF5F2E511748884000502A6</string>
<string>6BF5F2E611748884000502A6</string>
<string>6BF5F2E711748884000502A6</string>
<string>6BF5F2E911748884000502A6</string>
<string>6BF5F2EA11748884000502A6</string>
<string>6BF5F2EB11748884000502A6</string>
</array>
<key>prevStack</key>
<array>
@ -418,7 +457,6 @@
<string>6BBB4AE2115B4F3400CF791D</string>
<string>6BBB4AE3115B4F3400CF791D</string>
<string>6BBB4AE4115B4F3400CF791D</string>
<string>6BBB4AE5115B4F3400CF791D</string>
<string>6BBB4AE6115B4F3400CF791D</string>
<string>6BBB4AE7115B4F3400CF791D</string>
<string>6BBB4AE8115B4F3400CF791D</string>
@ -463,6 +501,25 @@
<string>6BBB4C3B115B7A3D00CF791D</string>
<string>6BED8AD61174509800582F38</string>
<string>6BED8AF0117455CB00582F38</string>
<string>6BF5F233117474CF000502A6</string>
<string>6BF5F27811747CFA000502A6</string>
<string>6BF5F28011747CFA000502A6</string>
<string>6BF5F28D11747CFA000502A6</string>
<string>6BF5F2EC11748884000502A6</string>
<string>6BF5F2ED11748884000502A6</string>
<string>6BF5F2EE11748884000502A6</string>
<string>6BF5F2EF11748884000502A6</string>
<string>6BF5F2F011748884000502A6</string>
<string>6BF5F2F111748884000502A6</string>
<string>6BF5F2F211748884000502A6</string>
<string>6BF5F2F311748884000502A6</string>
<string>6BF5F2F411748884000502A6</string>
<string>6BF5F2F511748884000502A6</string>
<string>6BF5F2F611748884000502A6</string>
<string>6BF5F2F711748884000502A6</string>
<string>6BF5F2F811748884000502A6</string>
<string>6BF5F2F911748884000502A6</string>
<string>6BF5F2FA11748884000502A6</string>
</array>
</dict>
<key>SplitCount</key>
@ -476,18 +533,18 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {970, 564}}</string>
<string>{{0, 0}, {970, 578}}</string>
<key>RubberWindowFrame</key>
<string>13 75 1256 702 0 0 1280 778 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
<string>564pt</string>
<string>578pt</string>
</dict>
<dict>
<key>Proportion</key>
<string>92pt</string>
<string>78pt</string>
<key>Tabs</key>
<array>
<dict>
@ -501,9 +558,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {970, 65}}</string>
<key>RubberWindowFrame</key>
<string>13 75 1256 702 0 0 1280 778 </string>
<string>{{10, 27}, {970, 92}}</string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
@ -519,7 +574,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {970, -27}}</string>
<string>{{10, 27}, {970, 287}}</string>
</dict>
<key>Module</key>
<string>PBXProjectFindModule</string>
@ -557,7 +612,9 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {970, 65}}</string>
<string>{{10, 27}, {970, 51}}</string>
<key>RubberWindowFrame</key>
<string>13 75 1256 702 0 0 1280 778 </string>
</dict>
<key>Module</key>
<string>PBXBuildResultsModule</string>
@ -585,11 +642,11 @@
</array>
<key>TableOfContents</key>
<array>
<string>6BED8AE6117451EB00582F38</string>
<string>6BF5F2FC11748884000502A6</string>
<string>1CA23ED40692098700951B8B</string>
<string>6BED8AE7117451EB00582F38</string>
<string>6BF5F2FD11748884000502A6</string>
<string>6B8632A30F78115100E2684A</string>
<string>6BED8AE8117451EB00582F38</string>
<string>6BF5F2FE11748884000502A6</string>
<string>1CA23EDF0692099D00951B8B</string>
<string>1CA23EE00692099D00951B8B</string>
<string>1CA23EE10692099D00951B8B</string>
@ -738,14 +795,14 @@
</array>
<key>TableOfContents</key>
<array>
<string>6BED8AE9117451EB00582F38</string>
<string>6BF5F2FF11748884000502A6</string>
<string>1CCC7628064C1048000F2A68</string>
<string>1CCC7629064C1048000F2A68</string>
<string>6BED8AEA117451EB00582F38</string>
<string>6BED8AEB117451EB00582F38</string>
<string>6BED8AEC117451EB00582F38</string>
<string>6BED8AED117451EB00582F38</string>
<string>6B8632A30F78115100E2684A</string>
<string>6BF5F30011748884000502A6</string>
<string>6BF5F30111748884000502A6</string>
<string>6BF5F30211748884000502A6</string>
<string>6BF5F30311748884000502A6</string>
<string>6BF5F30411748884000502A6</string>
</array>
<key>ToolbarConfigUserDefaultsMinorVersion</key>
<string>2</string>
@ -777,6 +834,7 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
<string>6BF5F29911747CFA000502A6</string>
<string>/Users/memon/Code/recastnavigation/RecastDemo/Build/Xcode/Recast.xcodeproj</string>
</array>
<key>WindowString</key>

View File

@ -43,6 +43,8 @@
6BB93C7F10CFE1D500F74F2B /* RecastDebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB93C7C10CFE1D500F74F2B /* RecastDebugDraw.cpp */; };
6BB93CF610CFEC4500F74F2B /* RecastDump.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB93CF510CFEC4500F74F2B /* RecastDump.cpp */; };
6BCF32361104CD05009445BF /* OffMeshConnectionTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BCF32351104CD05009445BF /* OffMeshConnectionTool.cpp */; };
6BF5F23A11747606000502A6 /* Filelist.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BF5F23911747606000502A6 /* Filelist.cpp */; };
6BF5F2401174763B000502A6 /* SlideShow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BF5F23F1174763B000502A6 /* SlideShow.cpp */; };
6BF7C1401111953A002B3F46 /* TestCase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BF7C13F1111953A002B3F46 /* TestCase.cpp */; };
6BF7C4541115C277002B3F46 /* RecastArea.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BF7C4531115C277002B3F46 /* RecastArea.cpp */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
@ -118,6 +120,11 @@
6BB93CF510CFEC4500F74F2B /* RecastDump.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RecastDump.cpp; path = ../../../DebugUtils/Source/RecastDump.cpp; sourceTree = SOURCE_ROOT; };
6BCF32341104CD05009445BF /* OffMeshConnectionTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OffMeshConnectionTool.h; path = ../../Include/OffMeshConnectionTool.h; sourceTree = SOURCE_ROOT; };
6BCF32351104CD05009445BF /* OffMeshConnectionTool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OffMeshConnectionTool.cpp; path = ../../Source/OffMeshConnectionTool.cpp; sourceTree = SOURCE_ROOT; };
6BF5F23911747606000502A6 /* Filelist.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Filelist.cpp; path = ../../Source/Filelist.cpp; sourceTree = SOURCE_ROOT; };
6BF5F23C11747614000502A6 /* Filelist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Filelist.h; path = ../../Include/Filelist.h; sourceTree = SOURCE_ROOT; };
6BF5F23E1174763B000502A6 /* SlideShow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SlideShow.h; path = ../../Include/SlideShow.h; sourceTree = SOURCE_ROOT; };
6BF5F23F1174763B000502A6 /* SlideShow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SlideShow.cpp; path = ../../Source/SlideShow.cpp; sourceTree = SOURCE_ROOT; };
6BF5F2C511747E9F000502A6 /* stb_image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = stb_image.h; path = ../../Contrib/stb_image.h; sourceTree = SOURCE_ROOT; };
6BF7C13E11119520002B3F46 /* TestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestCase.h; path = ../../Include/TestCase.h; sourceTree = SOURCE_ROOT; };
6BF7C13F1111953A002B3F46 /* TestCase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TestCase.cpp; path = ../../Source/TestCase.cpp; sourceTree = SOURCE_ROOT; };
6BF7C4531115C277002B3F46 /* RecastArea.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RecastArea.cpp; path = ../../../Recast/Source/RecastArea.cpp; sourceTree = SOURCE_ROOT; };
@ -142,13 +149,18 @@
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
6B555DF6100B273500247EA3 /* stb_truetype.h */,
6BB93C7610CFE1BD00F74F2B /* DebugUtils */,
6BDD9E030F91110C00904EEF /* Detour */,
6B137C7D0F7FCBE800459200 /* Recast */,
6B555DF5100B25FC00247EA3 /* Samples */,
6BB7FE8E10F4A175006DA0A6 /* Tools */,
6B25B6180FFA62BE004F1BC4 /* main.cpp */,
6BF5F2C511747E9F000502A6 /* stb_image.h */,
6BF5F23E1174763B000502A6 /* SlideShow.h */,
6BF5F23F1174763B000502A6 /* SlideShow.cpp */,
6BF5F23C11747614000502A6 /* Filelist.h */,
6BF5F23911747606000502A6 /* Filelist.cpp */,
6B555DF6100B273500247EA3 /* stb_truetype.h */,
6B137C7A0F7FCBE400459200 /* imgui.h */,
6B137C6C0F7FCBBB00459200 /* imgui.cpp */,
6B555DAE100B211D00247EA3 /* imguiRenderGL.h */,
@ -405,6 +417,8 @@
6BF7C4541115C277002B3F46 /* RecastArea.cpp in Sources */,
6B324C66111C5D9A00EBD2FD /* ConvexVolumeTool.cpp in Sources */,
6B8036AE113BAABE005ED67B /* Sample_Debug.cpp in Sources */,
6BF5F23A11747606000502A6 /* Filelist.cpp in Sources */,
6BF5F2401174763B000502A6 /* SlideShow.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -453,6 +467,7 @@
"-Wall",
);
PRODUCT_NAME = Recast;
USER_HEADER_SEARCH_PATHS = "";
};
name = Debug;
};
@ -478,6 +493,7 @@
"-Wall",
);
PRODUCT_NAME = Recast;
USER_HEADER_SEARCH_PATHS = "";
};
name = Release;
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
//
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef FILELIST_H
#define FILELIST_H
struct FileList
{
static const int MAX_FILES = 256;
FileList();
~FileList();
char* files[MAX_FILES];
int size;
};
void scanDirectory(const char* path, const char* ext, FileList& list);
#endif // FILELIST_H

View File

@ -0,0 +1,53 @@
//
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef SLIDESHOW_H
#define SLIDESHOW_H
#include "Filelist.h"
class SlideShow
{
FileList m_files;
char m_path[256];
int m_width;
int m_height;
unsigned int m_texId;
void purgeImage();
bool loadImage(const char* path);
bool m_showSlides;
bool m_showCurSlide;
float m_slideAlpha;
int m_curSlide;
int m_nextSlide;
public:
SlideShow();
~SlideShow();
bool init(const char* path);
void nextSlide();
void prevSlide();
void setSlide(int n);
void updateAndDraw(float dt, const float w, const float h);
};
#endif // SLIDESHOW_H

View File

@ -0,0 +1,100 @@
//
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include "Filelist.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
# include <io.h>
#else
# include <dirent.h>
#endif
static void fileListAdd(FileList& list, const char* path)
{
if (list.size >= FileList::MAX_FILES)
return;
int n = strlen(path);
list.files[list.size] = new char[n+1];
strcpy(list.files[list.size], path);
list.size++;
}
static void fileListClear(FileList& list)
{
for (int i = 0; i < list.size; ++i)
delete [] list.files[i];
list.size = 0;
}
FileList::FileList() : size(0)
{
memset(files, 0, sizeof(char*)*MAX_FILES);
}
FileList::~FileList()
{
fileListClear(*this);
}
static int cmp(const void* a, const void* b)
{
return strcmp(*(const char**)a, *(const char**)b);
}
void scanDirectory(const char* path, const char* ext, FileList& list)
{
fileListClear(list);
#ifdef WIN32
_finddata_t dir;
char pathWithExt[MAX_PATH];
long fh;
strcpy(pathWithExt, path);
strcat(pathWithExt, "/*");
strcat(pathWithExt, ext);
fh = _findfirst(pathWithExt, &dir);
if (fh == -1L)
return;
do
{
fileListAdd(list, dir.name);
}
while (_findnext(fh, &dir) == 0);
_findclose(fh);
#else
dirent* current = 0;
DIR* dp = opendir(path);
if (!dp)
return;
while ((current = readdir(dp)) != 0)
{
int len = strlen(current->d_name);
if (len > 4 && strncmp(current->d_name+len-4, ext, 4) == 0)
{
fileListAdd(list, current->d_name);
}
}
closedir(dp);
#endif
if (list.size > 1)
qsort(list.files, list.size, sizeof(char*), cmp);
}

View File

@ -0,0 +1,159 @@
//
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include "SlideShow.h"
#include <string.h>
#include <stdio.h>
#include <SDL_Opengl.h>
//#define STBI_HEADER_FILE_ONLY
#include "stb_image.h"
SlideShow::SlideShow() :
m_width(0),
m_height(0),
m_texId(0),
m_showCurSlide(true),
m_slideAlpha(1.0f),
m_curSlide(-1),
m_nextSlide(0)
{
}
SlideShow::~SlideShow()
{
purgeImage();
}
void SlideShow::purgeImage()
{
if (m_texId)
{
glDeleteTextures(1, (GLuint*)&m_texId);
m_texId = 0;
m_width = 0;
m_height = 0;
}
}
bool SlideShow::loadImage(const char* path)
{
purgeImage();
int bpp;
unsigned char* data = stbi_load(path, &m_width, &m_height, &bpp, 4);
if (!data)
{
printf("Could not load file '%s': %s\n", path, stbi_failure_reason());
return false;
}
glGenTextures(1, (GLuint*)&m_texId);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_texId);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, m_width, m_height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
stbi_image_free(data);
return true;
}
bool SlideShow::init(const char* path)
{
strcpy(m_path, path);
scanDirectory(m_path, ".png", m_files);
return true;
}
void SlideShow::nextSlide()
{
setSlide(m_nextSlide+1);
}
void SlideShow::prevSlide()
{
setSlide(m_nextSlide-1);
}
void SlideShow::setSlide(int n)
{
const int maxIdx = m_files.size ? m_files.size-1 : 0;
m_nextSlide = n;
if (m_nextSlide < 0) m_nextSlide = 0;
if (m_nextSlide > maxIdx) m_nextSlide = maxIdx;
}
void SlideShow::updateAndDraw(float dt, const float w, const float h)
{
float slideAlphaTarget = (m_showCurSlide && m_texId) ? 1 : 0;
if (m_curSlide != m_nextSlide)
slideAlphaTarget = 0;
if (slideAlphaTarget > m_slideAlpha)
m_slideAlpha += dt*4;
else if (slideAlphaTarget < m_slideAlpha)
m_slideAlpha -= dt*4;
if (m_slideAlpha < 0) m_slideAlpha = 0;
if (m_slideAlpha > 1) m_slideAlpha = 1;
if (m_curSlide != m_nextSlide && m_slideAlpha < 0.01f)
{
m_curSlide = m_nextSlide;
if (m_curSlide >= 0 && m_curSlide < m_files.size)
{
char path[256];
strcpy(path, m_path);
strcat(path, m_files.files[m_curSlide]);
loadImage(path);
}
}
if (m_slideAlpha > 0.01f && m_texId)
{
unsigned char alpha = (unsigned char)(m_slideAlpha*255.0f);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_texId);
const float tw = m_width;
const float th = m_height;
const float hw = tw/2; //w*0.5f;
const float hh = th/2; //h*0.5f;
glColor4ub(255,255,255,alpha);
glBegin(GL_QUADS);
glTexCoord2f(0,th);
glVertex2f(hw-tw/2,hh-th/2);
glTexCoord2f(tw,th);
glVertex2f(hw+tw/2,hh-th/2);
glTexCoord2f(tw,0);
glVertex2f(hw+tw/2,hh+th/2);
glTexCoord2f(0,0);
glVertex2f(hw-tw/2,hh+th/2);
glEnd();
glDisable(GL_TEXTURE_RECTANGLE_ARB);
}
}

View File

@ -19,12 +19,6 @@
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#ifdef WIN32
# include <io.h>
#else
# include <dirent.h>
#endif
#include "SDL.h"
#include "SDL_opengl.h"
#include "imgui.h"
@ -33,6 +27,8 @@
#include "RecastDebugDraw.h"
#include "InputGeom.h"
#include "TestCase.h"
#include "Filelist.h"
#include "SlideShow.h"
#include "Sample_SoloMeshSimple.h"
#include "Sample_SoloMeshTiled.h"
@ -43,91 +39,6 @@
# define snprintf _snprintf
#endif
struct FileList
{
static const int MAX_FILES = 256;
inline FileList() : size(0)
{
memset(files, 0, sizeof(char*)*MAX_FILES);
}
inline ~FileList()
{
clear();
}
void clear()
{
for (int i = 0; i < size; ++i)
delete [] files[i];
size = 0;
}
void add(const char* path)
{
if (size >= MAX_FILES)
return;
int n = strlen(path);
files[size] = new char[n+1];
strcpy(files[size], path);
size++;
}
static int cmp(const void* a, const void* b)
{
return strcmp(*(const char**)a, *(const char**)b);
}
void sort()
{
if (size > 1)
qsort(files, size, sizeof(char*), cmp);
}
char* files[MAX_FILES];
int size;
};
static void scanDirectory(const char* path, const char* ext, FileList& list)
{
list.clear();
#ifdef WIN32
_finddata_t dir;
char pathWithExt[MAX_PATH];
long fh;
strcpy(pathWithExt, path);
strcat(pathWithExt, "/*");
strcat(pathWithExt, ext);
fh = _findfirst(pathWithExt, &dir);
if (fh == -1L)
return;
do
{
list.add(dir.name);
}
while (_findnext(fh, &dir) == 0);
_findclose(fh);
#else
dirent* current = 0;
DIR* dp = opendir(path);
if (!dp)
return;
while ((current = readdir(dp)) != 0)
{
int len = strlen(current->d_name);
if (len > 4 && strncmp(current->d_name+len-4, ext, 4) == 0)
{
list.add(current->d_name);
}
}
closedir(dp);
#endif
list.sort();
}
struct SampleItem
{
Sample* (*create)();
@ -219,6 +130,9 @@ int main(int /*argc*/, char** /*argv*/)
float mpos[3] = {0,0,0};
bool mposSet = false;
SlideShow slideShow;
slideShow.init("slides/");
InputGeom* geom = 0;
Sample* sample = 0;
TestCase* test = 0;
@ -257,13 +171,17 @@ int main(int /*argc*/, char** /*argv*/)
{
done = true;
}
else if (event.key.keysym.sym == SDLK_TAB)
else if (event.key.keysym.sym == SDLK_t)
{
showLevels = false;
showSample = false;
showTestCases = true;
scanDirectory("Tests", ".txt", files);
}
else if (event.key.keysym.sym == SDLK_TAB)
{
showMenu = !showMenu;
}
else if (event.key.keysym.sym == SDLK_SPACE)
{
if (sample)
@ -325,6 +243,14 @@ int main(int /*argc*/, char** /*argv*/)
glFogf(GL_FOG_END, camr*1.25f);
}
}
else if (event.key.keysym.sym == SDLK_RIGHT)
{
slideShow.nextSlide();
}
else if (event.key.keysym.sym == SDLK_LEFT)
{
slideShow.prevSlide();
}
break;
case SDL_MOUSEBUTTONDOWN:
@ -899,6 +825,8 @@ int main(int /*argc*/, char** /*argv*/)
imguiEndScrollArea();
}
slideShow.updateAndDraw(dt, width, height);
// Marker
if (mposSet && gluProject((GLdouble)mpos[0], (GLdouble)mpos[1], (GLdouble)mpos[2],
model, proj, view, &x, &y, &z))