diff --git a/experimental/premake4.lua b/experimental/premake4.lua index d5f433f..0273ed2 100644 --- a/experimental/premake4.lua +++ b/experimental/premake4.lua @@ -21,7 +21,8 @@ solution "objview" includedirs { "./" } includedirs { "../../" } - buildoptions { "-std=c++11" } + flags { "c++11" } + --buildoptions { "-std=c++11" } if _OPTIONS['with-zlib'] then defines { 'ENABLE_ZLIB' } @@ -48,14 +49,15 @@ solution "objview" configuration { "windows" } -- Path to GLFW3 - includedirs { '../../../../local/glfw-3.1.2.bin.WIN64/include' } - libdirs { '../../../../local/glfw-3.1.2.bin.WIN64/lib-vc2013' } + includedirs { '../../../local/glfw-3.2.bin.WIN64/include' } + libdirs { '../../../local/glfw-3.2.bin.WIN64/lib-vc2015' } -- Path to GLEW - includedirs { '../../../../local/glew-1.13.0/include' } - libdirs { '../../../../local/glew-1.13.0/lib/Release/x64' } + includedirs { '../../../local/glew-1.13.0/include' } + libdirs { '../../../local/glew-1.13.0/lib/Release/x64' } links { "glfw3", "glew32", "gdi32", "winmm", "user32", "glu32","opengl32", "kernel32" } defines { "_CRT_SECURE_NO_WARNINGS" } + defines { "NOMINMAX" } configuration { "macosx" } includedirs { "/usr/local/include" } diff --git a/experimental/tinyobj_loader_opt.h b/experimental/tinyobj_loader_opt.h index d4e9eaf..3bee218 100644 --- a/experimental/tinyobj_loader_opt.h +++ b/experimental/tinyobj_loader_opt.h @@ -29,7 +29,7 @@ THE SOFTWARE. #ifndef TINOBJ_LOADER_OPT_H_ #define TINOBJ_LOADER_OPT_H_ -#ifdef _WIN64 +#ifdef _WIN32 #define atoll(S) _atoi64(S) #include #else @@ -1263,7 +1263,7 @@ bool parseObj(attrib_t *attrib, std::vector *shapes, ? std::thread::hardware_concurrency() : option.req_num_threads; num_threads = - std::max(1, std::min(static_cast(num_threads), kMaxThreads)); + (std::max)(1, (std::min)(static_cast(num_threads), kMaxThreads)); if (option.verbose) { std::cout << "# of threads = " << num_threads << std::endl; @@ -1295,7 +1295,7 @@ bool parseObj(attrib_t *attrib, std::vector *shapes, for (size_t t = 0; t < static_cast(num_threads); t++) { workers->push_back(std::thread([&, t]() { auto start_idx = (t + 0) * chunk_size; - auto end_idx = std::min((t + 1) * chunk_size, len - 1); + auto end_idx = (std::min)((t + 1) * chunk_size, len - 1); if (t == static_cast((num_threads - 1))) { end_idx = len - 1; } @@ -1325,7 +1325,7 @@ bool parseObj(attrib_t *attrib, std::vector *shapes, // Find extra line which spand across chunk boundary. if ((t < num_threads) && (buf[end_idx - 1] != '\n')) { - auto extra_span_idx = std::min(end_idx - 1 + chunk_size, len - 1); + auto extra_span_idx = (std::min)(end_idx - 1 + chunk_size, len - 1); for (size_t i = end_idx; i < extra_span_idx; i++) { if (is_line_ending(buf, i, extra_span_idx)) { LineInfo info; diff --git a/experimental/viewer.cc b/experimental/viewer.cc index 87db22b..3555b54 100644 --- a/experimental/viewer.cc +++ b/experimental/viewer.cc @@ -90,16 +90,24 @@ void CalcNormal(float N[3], float v0[3], float v1[3], float v2[3]) { const char *mmap_file(size_t *len, const char* filename) { (*len) = 0; -#ifdef _WIN64 +#ifdef _WIN32 HANDLE file = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); - assert(file != INVALID_HANDLE_VALUE); + assert(file != INVALID_HANDLE_VALUE); - HANDLE fileMapping = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL); - assert(fileMapping != INVALID_HANDLE_VALUE); + HANDLE fileMapping = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL); + assert(fileMapping != INVALID_HANDLE_VALUE); - LPVOID fileMapView = MapViewOfFile(fileMapping, FILE_MAP_READ, 0, 0, 0); - auto fileMapViewChar = (const char*)fileMapView; - assert(fileMapView != NULL); + LPVOID fileMapView = MapViewOfFile(fileMapping, FILE_MAP_READ, 0, 0, 0); + auto fileMapViewChar = (const char*)fileMapView; + assert(fileMapView != NULL); + + LARGE_INTEGER fileSize; + fileSize.QuadPart = 0; + GetFileSizeEx(file, &fileSize); + + (*len) = static_cast(fileSize.QuadPart); + return fileMapViewChar; + #else FILE* f = fopen(filename, "r" ); @@ -324,6 +332,10 @@ bool LoadObjAndConvert(float bmin[3], float bmax[3], const char* filename, int n option.verbose = verbose; bool ret = parseObj(&attrib, &shapes, &materials, data, data_len, option); + if (!ret) { + std::cerr << "Failed to parse .obj" << std::endl; + return false; + } bmin[0] = bmin[1] = bmin[2] = std::numeric_limits::max(); bmax[0] = bmax[1] = bmax[2] = -std::numeric_limits::max();