compatibility with winXP. .bmp loader now handles 32-bit images and more modern headers.

This commit is contained in:
tmj-fstate
2017-01-30 23:21:00 +01:00
parent 3c0edb3ec3
commit 61440c4969
7 changed files with 51 additions and 35 deletions

View File

@@ -5826,16 +5826,8 @@ bool TMoverParameters::readBPT(/*int const ln,*/ std::string const &line)
bool TMoverParameters::readDList( std::string const &line ) { bool TMoverParameters::readDList( std::string const &line ) {
cParser parser( line ); cParser parser( line );
parser.getTokens( 4, false ); parser.getTokens( 3, false );
/* warning disabled until i know what to expect ._. auto idx = DLISTLINE++;
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;
if( idx >= sizeof( RList ) ) { if( idx >= sizeof( RList ) ) {
WriteLog( "Read DList: number of entries exceeded capacity of the data table" ); WriteLog( "Read DList: number of entries exceeded capacity of the data table" );
return false; return false;

View File

@@ -1,13 +1,17 @@
#ifndef PyIntH #ifndef PyIntH
#define PyIntH #define PyIntH
#undef _DEBUG // bez tego macra Py_DECREF powoduja problemy przy linkowaniu
#include <vector> #include <vector>
#include <set> #include <set>
#include <string> #include <string>
#ifdef _DEBUG
#undef _DEBUG // bez tego macra Py_DECREF powoduja problemy przy linkowaniu
#include "Python.h" #include "Python.h"
#define _DEBUG
#else
#include "Python.h"
#endif
#include "parser.h" #include "parser.h"
#include "Model3d.h" #include "Model3d.h"

View File

@@ -54,14 +54,14 @@ TTexturesManager::Names::iterator TTexturesManager::LoadFromFile(std::string fil
AlphaValue texinfo; AlphaValue texinfo;
if (ext == "tga") if( ext == "dds" )
texinfo = LoadDDS( realFileName, filter );
else if( ext == "tga" )
texinfo = LoadTGA(realFileName, filter); texinfo = LoadTGA(realFileName, filter);
else if (ext == "tex") else if (ext == "tex")
texinfo = LoadTEX(realFileName); texinfo = LoadTEX(realFileName);
else if (ext == "bmp") else if (ext == "bmp")
texinfo = LoadBMP(realFileName); texinfo = LoadBMP(realFileName);
else if (ext == "dds")
texinfo = LoadDDS(realFileName, filter);
_alphas.insert( _alphas.insert(
texinfo); // zapamiętanie stanu przezroczystości tekstury - można by tylko przezroczyste 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); 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); AlphaValue fail(0, false);
std::ifstream file(fileName.c_str(), std::ios::binary); std::ifstream file(fileName, std::ios::binary);
if (!file.is_open()) if (!file.is_open())
{ {
@@ -259,42 +259,44 @@ TTexturesManager::AlphaValue TTexturesManager::LoadBMP(std::string fileName)
file.read((char *)&header, sizeof(BITMAPFILEHEADER)); file.read((char *)&header, sizeof(BITMAPFILEHEADER));
if (file.eof()) if (file.eof())
{ {
file.close();
return fail; return fail;
} }
// Read in bitmap information structure // Read in bitmap information structure
BITMAPINFO info; BITMAPINFO info;
long infoSize = header.bfOffBits - sizeof(BITMAPFILEHEADER); unsigned int infoSize = header.bfOffBits - sizeof(BITMAPFILEHEADER);
file.read((char *)&info, infoSize); 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()) if (file.eof())
{ {
file.close();
return fail; return fail;
}; };
GLuint width = info.bmiHeader.biWidth; GLuint width = info.bmiHeader.biWidth;
GLuint height = info.bmiHeader.biHeight; 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; unsigned long bitSize = info.bmiHeader.biSizeImage;
if (!bitSize) if (!bitSize)
bitSize = (width * info.bmiHeader.biBitCount + 7) / 8 * height; bitSize = (width * info.bmiHeader.biBitCount + 7) / 8 * height;
GLubyte *data = new GLubyte[bitSize]; std::shared_ptr<GLubyte> data( new GLubyte[ bitSize ], std::default_delete<GLubyte[]>() );
file.read((char *)data, bitSize); file.read((char *)data.get(), bitSize);
if (file.eof()) if (file.eof())
{ {
delete[] data;
file.close();
return fail; return fail;
}; };
file.close();
GLuint id; GLuint id;
glGenTextures(1, &id); glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 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_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 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, hasalpha);
return std::make_pair(id, false);
}; };
TTexturesManager::AlphaValue TTexturesManager::LoadTGA(std::string fileName, int filter) TTexturesManager::AlphaValue TTexturesManager::LoadTGA(std::string fileName, int filter)

View File

@@ -43,7 +43,7 @@ class TTexturesManager
static Names::iterator LoadFromFile(std::string name, int filter = -1); 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 LoadTEX(std::string fileName);
static AlphaValue LoadTGA(std::string fileName, int filter = -1); static AlphaValue LoadTGA(std::string fileName, int filter = -1);
static AlphaValue LoadDDS(std::string fileName, int filter = -1); static AlphaValue LoadDDS(std::string fileName, int filter = -1);

View File

@@ -70,7 +70,11 @@ double GetFPS()
void ResetTimers() void ResetTimers()
{ {
// double CurrentTime= // double CurrentTime=
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
::GetTickCount64(); ::GetTickCount64();
#else
::GetTickCount();
#endif
DeltaTime = 0.1; DeltaTime = 0.1;
DeltaRenderTime = 0; DeltaRenderTime = 0;
fSoundTimer = 0; fSoundTimer = 0;
@@ -102,7 +106,11 @@ void UpdateTimers(bool pause)
oldCount = count; oldCount = count;
// Keep track of the time lapse and frame 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 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 ++dwFrames; // licznik ramek
// update the frame rate once per second // update the frame rate once per second
if (fTime - fLastTime > 1.0f) if (fTime - fLastTime > 1.0f)

View File

@@ -18,12 +18,12 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">

View File

@@ -7,7 +7,8 @@
#include <winsdkver.h> #include <winsdkver.h>
#ifndef _WIN32_WINNT #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 #endif
#include <SDKDDKVer.h> #include <SDKDDKVer.h>