From 61440c49699c2c7f9ff96399d5589a9589cdfd43 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Mon, 30 Jan 2017 23:21:00 +0100 Subject: [PATCH] compatibility with winXP. .bmp loader now handles 32-bit images and more modern headers. --- McZapkie/Mover.cpp | 12 ++---------- PyInt.h | 8 ++++++-- Texture.cpp | 49 ++++++++++++++++++++++++++++------------------ Texture.h | 2 +- Timer.cpp | 8 ++++++++ maszyna.vcxproj | 4 ++-- targetver.h | 3 ++- 7 files changed, 51 insertions(+), 35 deletions(-) diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 94c63b4c..3f1c1a31 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -5826,16 +5826,8 @@ bool TMoverParameters::readBPT(/*int const ln,*/ std::string const &line) bool TMoverParameters::readDList( std::string const &line ) { cParser parser( line ); - parser.getTokens( 4, false ); -/* warning disabled until i know what to expect ._. - if( false == parser.getTokens( 4, false ) ) { - WriteLog( "Read DList: arguments missing in line " + std::to_string( DLISTLINE + 1 ) ); - return false; - } -*/ - ++DLISTLINE; - int idx = 0; - parser >> idx; + parser.getTokens( 3, false ); + auto idx = DLISTLINE++; if( idx >= sizeof( RList ) ) { WriteLog( "Read DList: number of entries exceeded capacity of the data table" ); return false; diff --git a/PyInt.h b/PyInt.h index 9db84b7b..8146c79c 100644 --- a/PyInt.h +++ b/PyInt.h @@ -1,13 +1,17 @@ #ifndef PyIntH #define PyIntH -#undef _DEBUG // bez tego macra Py_DECREF powoduja problemy przy linkowaniu - #include #include #include +#ifdef _DEBUG +#undef _DEBUG // bez tego macra Py_DECREF powoduja problemy przy linkowaniu #include "Python.h" +#define _DEBUG +#else +#include "Python.h" +#endif #include "parser.h" #include "Model3d.h" diff --git a/Texture.cpp b/Texture.cpp index 16f3b432..8506bb8b 100644 --- a/Texture.cpp +++ b/Texture.cpp @@ -54,14 +54,14 @@ TTexturesManager::Names::iterator TTexturesManager::LoadFromFile(std::string fil AlphaValue texinfo; - if (ext == "tga") + if( ext == "dds" ) + texinfo = LoadDDS( realFileName, filter ); + else if( ext == "tga" ) texinfo = LoadTGA(realFileName, filter); else if (ext == "tex") texinfo = LoadTEX(realFileName); else if (ext == "bmp") texinfo = LoadBMP(realFileName); - else if (ext == "dds") - texinfo = LoadDDS(realFileName, filter); _alphas.insert( texinfo); // zapamiętanie stanu przezroczystości tekstury - można by tylko przezroczyste @@ -242,11 +242,11 @@ bool TTexturesManager::GetAlpha(GLuint id) return (iter != _alphas.end() ? iter->second : false); } -TTexturesManager::AlphaValue TTexturesManager::LoadBMP(std::string fileName) +TTexturesManager::AlphaValue TTexturesManager::LoadBMP(std::string const &fileName) { AlphaValue fail(0, false); - std::ifstream file(fileName.c_str(), std::ios::binary); + std::ifstream file(fileName, std::ios::binary); if (!file.is_open()) { @@ -259,42 +259,44 @@ TTexturesManager::AlphaValue TTexturesManager::LoadBMP(std::string fileName) file.read((char *)&header, sizeof(BITMAPFILEHEADER)); if (file.eof()) { - file.close(); return fail; } // Read in bitmap information structure BITMAPINFO info; - long infoSize = header.bfOffBits - sizeof(BITMAPFILEHEADER); - file.read((char *)&info, infoSize); + unsigned int infoSize = header.bfOffBits - sizeof(BITMAPFILEHEADER); + if( infoSize > sizeof( info ) ) { + WriteLog( "Warning - BMP header is larger than expected, possible format difference." ); + } + file.read((char *)&info, std::min(infoSize, sizeof(info))); if (file.eof()) { - file.close(); return fail; }; GLuint width = info.bmiHeader.biWidth; GLuint height = info.bmiHeader.biHeight; + bool hasalpha = ( info.bmiHeader.biBitCount == 32 ); + + if( info.bmiHeader.biCompression != BI_RGB ) { + ErrorLog( "Compressed BMP textures aren't supported." ); + return fail; + } unsigned long bitSize = info.bmiHeader.biSizeImage; if (!bitSize) bitSize = (width * info.bmiHeader.biBitCount + 7) / 8 * height; - GLubyte *data = new GLubyte[bitSize]; - file.read((char *)data, bitSize); + std::shared_ptr data( new GLubyte[ bitSize ], std::default_delete() ); + file.read((char *)data.get(), bitSize); if (file.eof()) { - delete[] data; - file.close(); return fail; }; - file.close(); - GLuint id; - glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -308,10 +310,19 @@ TTexturesManager::AlphaValue TTexturesManager::LoadBMP(std::string fileName) glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, data); +// glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, data.get()); + glTexImage2D( + GL_TEXTURE_2D, + 0, + hasalpha ? GL_RGBA : GL_RGB, + width, + height, + 0, + hasalpha ? GL_BGRA : GL_BGR, + GL_UNSIGNED_BYTE, + data.get() ); - delete[] data; - return std::make_pair(id, false); + return std::make_pair(id, hasalpha); }; TTexturesManager::AlphaValue TTexturesManager::LoadTGA(std::string fileName, int filter) diff --git a/Texture.h b/Texture.h index 1ca35246..8810d537 100644 --- a/Texture.h +++ b/Texture.h @@ -43,7 +43,7 @@ class TTexturesManager static Names::iterator LoadFromFile(std::string name, int filter = -1); - static AlphaValue LoadBMP(std::string fileName); + static AlphaValue LoadBMP(std::string const &fileName); static AlphaValue LoadTEX(std::string fileName); static AlphaValue LoadTGA(std::string fileName, int filter = -1); static AlphaValue LoadDDS(std::string fileName, int filter = -1); diff --git a/Timer.cpp b/Timer.cpp index ff4d1b9f..d6934f65 100644 --- a/Timer.cpp +++ b/Timer.cpp @@ -70,7 +70,11 @@ double GetFPS() void ResetTimers() { // double CurrentTime= +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA ::GetTickCount64(); +#else + ::GetTickCount(); +#endif DeltaTime = 0.1; DeltaRenderTime = 0; fSoundTimer = 0; @@ -102,7 +106,11 @@ void UpdateTimers(bool pause) oldCount = count; // Keep track of the time lapse and frame count +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA double fTime = ::GetTickCount64() * 0.001f; // Get current time in seconds +#else + double fTime = ::GetTickCount() * 0.001f; // Get current time in seconds +#endif ++dwFrames; // licznik ramek // update the frame rate once per second if (fTime - fLastTime > 1.0f) diff --git a/maszyna.vcxproj b/maszyna.vcxproj index 6d38e9fc..2eb00999 100644 --- a/maszyna.vcxproj +++ b/maszyna.vcxproj @@ -18,12 +18,12 @@ Application true - v120 + v120_xp Application false - v120 + v120_xp diff --git a/targetver.h b/targetver.h index 8128c7d5..a67b820a 100644 --- a/targetver.h +++ b/targetver.h @@ -7,7 +7,8 @@ #include #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0600 // _WIN32_WINNT_VISTA +//#define _WIN32_WINNT 0x0600 // _WIN32_WINNT_VISTA +#define _WIN32_WINNT 0x0501 // _WIN32_WINNT_WINXP #endif #include