diff --git a/mk/linux/Jamfile b/mk/linux/Jamfile index 7e67c726..73606ef1 100644 --- a/mk/linux/Jamfile +++ b/mk/linux/Jamfile @@ -26,7 +26,7 @@ for i in $(LIB_DIRS) { } Library glestlib : $(LIB_SOURCES) ; -ExternalLibs glestlib : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA ; +ExternalLibs glestlib : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA JPEG PNG ; IncludeDir glestlib : $(LIB_INCLUDE_DIRS) ; #### Game #### @@ -55,7 +55,7 @@ for i in $(GLEST_DIRS) { Application glest.bin : $(GLEST_SOURCES) ; LinkWith glest.bin : glestlib ; -ExternalLibs glest.bin : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA ; +ExternalLibs glest.bin : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA JPEG PNG ; IncludeDir glest.bin : ../shared_lib/include/$(LIB_INCLUDE_DIRS) $(GLEST_DIRS) ; #### Editor #### diff --git a/mk/linux/configure.ac b/mk/linux/configure.ac index 52a0fd26..cf1d579d 100644 --- a/mk/linux/configure.ac +++ b/mk/linux/configure.ac @@ -103,6 +103,25 @@ NP_FINDLIB([OPENAL], [OpenAL], [OpenAL], [AC_MSG_ERROR([Please intall OpenAL])], [], []) +NP_FINDLIB([JPEG], [LibJPEG], [LibJPEG], + NP_LANG_PROGRAM([ + #include + #include + #include ], + [jpeg_create_decompress(0);]), + [], [-ljpeg], + [], + [AC_MSG_ERROR([Please intall libjpeg])], + [], []) + +NP_FINDLIB([PNG], [LibPng], [LibPNG], + NP_LANG_PROGRAM([#include ], + [png_sig_cmp(0, 0, 8);]), + [], [-lpng], + [], + [AC_MSG_ERROR([Please intall libpng])], + [], []) + CHECK_LUA([], [AC_MSG_ERROR([Please install lua 5.1])]) AX_CHECK_GL diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index c5641c71..f14f1e4c 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -478,7 +478,8 @@ void Game::mouseMove(int x, int y, const MouseState *ms){ void Game::eventMouseWheel(int x, int y, int zDelta) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //gameCamera.transitionXYZ(0.0f, -(float)zDelta / 30.0f, 0.0f); - gameCamera.zoom((float)zDelta / 30.0f); + gameCamera.zoom((float)zDelta / 60.0f); + //gameCamera.setMoveY(1); } void Game::keyDown(char key){ diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index a48d584d..33a51635 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2005 Martiño Figueroa +// Copyright (C) 2001-2005 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -139,7 +139,7 @@ void MenuStateJoinGame::mouseClick(int x, int y, MouseButton mouseButton) { if(clientInterface->isConnected() == true) { - string sQuitText = clientInterface->getHostName() + " has chosen to leave the game!"; + string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!"; clientInterface->sendTextMessage(sQuitText,-1); } clientInterface->close(); diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index fd72d014..9cc61edb 100755 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -55,7 +55,7 @@ ClientInterface::~ClientInterface() if(clientSocket != NULL && clientSocket->isConnected() == true) { - string sQuitText = getHostName() + " has chosen to leave the game!"; + string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!"; sendTextMessage(sQuitText,-1); } @@ -85,7 +85,7 @@ void ClientInterface::reset() { if(getSocket() != NULL) { - string sQuitText = getHostName() + " has chosen to leave the game!"; + string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!"; sendTextMessage(sQuitText,-1); close(); } @@ -554,7 +554,7 @@ void ClientInterface::quitGame(bool userManuallyQuit) if(clientSocket != NULL && userManuallyQuit == true) { - string sQuitText = getHostName() + " has chosen to leave the game!"; + string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!"; sendTextMessage(sQuitText,-1); close(); } diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 088243d7..5a70c5dc 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -357,7 +357,7 @@ void ServerInterface::quitGame(bool userManuallyQuit) { if(userManuallyQuit == true) { - string sQuitText = getHostName() + " has chosen to leave the game!"; + string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!"; NetworkMessageText networkMessageText(sQuitText,getHostName(),-1); broadcastMessage(&networkMessageText, -1); } diff --git a/source/shared_lib/include/graphics/BMPReader.h b/source/shared_lib/include/graphics/BMPReader.h new file mode 100644 index 00000000..89e59838 --- /dev/null +++ b/source/shared_lib/include/graphics/BMPReader.h @@ -0,0 +1,34 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2010 Martiño Figueroa and others +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef BMPREADER_H +#define BMPREADER_H + +// ===================================== +// class BMPReader +// ===================================== + +#include "FileReader.h" +#include "pixmap.h" + +namespace Shared{ namespace Graphics{ + +class BMPReader: FileReader { +public: + BMPReader(); + + Pixmap2D* read(ifstream& in, const string& path, Pixmap2D* ret) const; +}; + + +}} //end namespace + +#endif diff --git a/source/shared_lib/include/graphics/FileReader.h b/source/shared_lib/include/graphics/FileReader.h new file mode 100644 index 00000000..482fe45a --- /dev/null +++ b/source/shared_lib/include/graphics/FileReader.h @@ -0,0 +1,274 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2010 Martiño Figueroa and others +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef FILE_READER_H +#define FILE_READER_H + +#include "platform_util.h" + +#include +#include +#include +#include +#include +#include + +using std::map; +using std::string; +using std::vector; +using std::ifstream; +using std::ios; +using std::runtime_error; + +using Shared::Platform::extractExtension; + +namespace Shared{ + +// ===================================================== +// class FileReader +// ===================================================== + +template +class FileReader { +protected: + string const * extensions; + + /**Creates a filereader being able to possibly load files + * from the specified extension + **/ + FileReader(string const * extensions); + +public: + /*Return the - existing and initialized - fileReadersMap + */ + static map const * >* >& getFileReadersMap() { + static map const * >* > fileReaderByExtension; + return fileReaderByExtension; + } + static vector const * > fileReaders; + + +public: + + /**Tries to read a file + * This method tries to read the file with the specified filepath. + * If it fails, either null is returned or an exception + * is thrown*/ + static T* readPath(const string& filepath); + + /**Tries to read a file from an object + * This method tries to read the file with the specified filepath. + * If it fails, either null is returned or an exception + * is thrown*/ + static T* readPath(const string& filepath, T* object); + + /**Gives a quick estimation of whether the specified file + * can be read or not depending on the filename*/ + virtual bool canRead(const string& filepath) const; + + /**Gives a better estimation of whether the specified file + * can be read or not depending on the file content*/ + virtual bool canRead(ifstream& file) const; + + /**Reads a file + * This method tries to read the file with the specified filepath + * If it fails, either null is returned or an exception + * is thrown + */ + virtual T* read(const string& filepath) const; + + /**Reads a file to an object + * This method tries to read the file with the specified filepath + * If it fails, either null is returned or an exception + * is thrown + */ + virtual T* read(const string& filepath, T* object) const; + + /**Reads a file + * This method tries to read the specified file + * If it failes, either null is returned or an exception + * Default implementation generates an object using T() + * is thrown + */ + virtual T* read(ifstream& file, const string& path) const { + T* obj = new T(); + T* ret = read(file,path,obj); + if (obj != ret) { + delete obj; + } + return ret; + } + + + /**Reads a file onto the specified object + * This method tries to read the specified file + * If it failes, either null is returned or an exception + * is thrown + */ + virtual T* read(ifstream& file, const string& path, T* former) const = 0; + + virtual ~FileReader() { + /*for (typename vector const * >::const_iterator i = fileReaders.begin(); i != fileReaders.end(); ++i) { + delete const_cast* >(*i); //Segfault + }*/ + }; //Well ... these objects aren't supposed to be destroyed +}; + +template +static inline T* readFromFileReaders(vector const *>* readers, const string& filepath) { + for (typename vector const *>::const_iterator i = readers->begin(); i != readers->end(); ++i) { + try { + FileReader const * reader = *i; + T* ret = reader->read(filepath); //It is guaranteed that at least the filepath matches ... + if (ret != NULL) { + return ret; + } + } catch (...) { //TODO: Specific exceptions + } + } + return NULL; +} + +template +static inline T* readFromFileReaders(vector const *>* readers, const string& filepath, T* object) { + for (typename vector const *>::const_iterator i = readers->begin(); i != readers->end(); ++i) { + try { + FileReader const * reader = *i; + T* ret = reader->read(filepath, object); //It is guaranteed that at least the filepath matches ... + if (ret != NULL) { + return ret; + } + } catch (...) { //TODO: Specific exceptions + } + } + std::cerr << "Could not parse filepath: " << filepath << std::endl; + return NULL; +} + +/**Tries to read a file + * This method tries to read the file with the specified filepath. + * If it fails, either null is returned or an exception + * is thrown*/ +template +T* FileReader::readPath(const string& filepath) { + const string& extension = extractExtension(filepath); + vector const * >* possibleReaders = (getFileReadersMap())[extension]; + if (possibleReaders != NULL) { + //Search in these possible readers + T* ret = readFromFileReaders(possibleReaders, filepath); + if (ret != NULL) { + return ret; + } + } + T* ret = readFromFileReaders(&fileReaders, filepath); //Try all other + return ret; +} + +/**Tries to read a file + * This method tries to read the file with the specified filepath. + * If it fails, either null is returned or an exception + * is thrown*/ +template +T* FileReader::readPath(const string& filepath, T* object) { + const string& extension = extractExtension(filepath); + vector const * >* possibleReaders = (getFileReadersMap())[extension]; + if (possibleReaders != NULL) { + //Search in these possible readers + T* ret = readFromFileReaders(possibleReaders, filepath, object); + if (ret != NULL) { + return ret; + } + } + T* ret = readFromFileReaders(&fileReaders, filepath, object); //Try all other + return ret; +} + + +template +vector const * > FileReader::fileReaders; + +template +FileReader::FileReader(string const * extensions): extensions(extensions) { + fileReaders.push_back(this); + string const * nextExtension = extensions; + while (((*nextExtension) != "")) { + vector const* >* curPossibleReaders = (getFileReadersMap())[*nextExtension]; + if (curPossibleReaders == NULL) { + (getFileReadersMap())[*nextExtension] = (curPossibleReaders = new vector const *>()); + } + curPossibleReaders->push_back(this); + ++nextExtension; + } +} + + + +/**Gives a quick estimation of whether the specified file + * can be read or not depending on the filename*/ +template +bool FileReader::canRead(const string& filepath) const { + const string& realExtension = extractExtension(filepath); + const string* haveExtension = extensions; + while (*haveExtension != "") { + if (realExtension == *haveExtension) { + return true; + } + ++haveExtension; + } + return false; +} + +/**Gives a better estimation of whether the specified file + * can be read or not depending on the file content*/ +template +bool FileReader::canRead(ifstream& file) const { + try { + T* wouldRead = read(file,"unknown file"); + bool ret = (wouldRead != NULL); + delete wouldRead; + return ret; + } catch (...) { + return false; + } +} + +/**Reads a file + * This method tries to read the file with the specified filepath + * If it fails, either null is returned or an exception + * is thrown + */ +template +T* FileReader::read(const string& filepath) const { + ifstream file(filepath.c_str(), ios::in | ios::binary); + if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message? + throw runtime_error("Could not open file " + filepath); + } + return read(file,filepath); +} + +/**Reads a file + * This method tries to read the file with the specified filepath + * If it fails, either null is returned or an exception + * is thrown + */ +template +T* FileReader::read(const string& filepath, T* object) const { + ifstream file(filepath.c_str(), ios::in | ios::binary); + if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message? + throw runtime_error("Could not open file " + filepath); + } + read(file,filepath,object); +} + + +} //end namespace + +#endif diff --git a/source/shared_lib/include/graphics/ImageReaders.h b/source/shared_lib/include/graphics/ImageReaders.h new file mode 100644 index 00000000..e6773671 --- /dev/null +++ b/source/shared_lib/include/graphics/ImageReaders.h @@ -0,0 +1,39 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2010 Martiño Figueroa and others +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef IMAGE_READERS_H +#define IMAGE_READERS_H + +#include "FileReader.h" +#include "BMPReader.h" +#include "JPGReader.h" +#include "PNGReader.h" +#include "TGAReader.h" + +//Initialize some objects +namespace Shared{ namespace Graphics{ + +// ===================================================== +// namespace ImageRegisterer +// ===================================================== + +namespace ImageRegisterer { + + //This function registers all image-readers, but only once (any further call is unnecessary) + bool registerImageReaders(); + + //Since you can't call void methods here, I have used a method doing nothing except initializing the image Readers + static bool readersRegistered = registerImageReaders(); //should always return true, this should guarantee that the readers are registered <--> ImageReaders is included anywhere +} + +}} //end namespace + +#endif diff --git a/source/shared_lib/include/graphics/JPGReader.h b/source/shared_lib/include/graphics/JPGReader.h new file mode 100644 index 00000000..2d62bdfa --- /dev/null +++ b/source/shared_lib/include/graphics/JPGReader.h @@ -0,0 +1,34 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2010 Martiño Figueroa and others +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef JPGREADER_H +#define JPGREADER_H + +// ===================================== +// class JPGReader +// ===================================== + +#include "FileReader.h" +#include "pixmap.h" + +namespace Shared{ namespace Graphics{ + +class JPGReader: FileReader { +public: + JPGReader(); + + Pixmap2D* read(ifstream& in, const string& path, Pixmap2D* ret) const; +}; + + +}} //end namespace + +#endif diff --git a/source/shared_lib/include/graphics/PNGReader.h b/source/shared_lib/include/graphics/PNGReader.h new file mode 100644 index 00000000..76577191 --- /dev/null +++ b/source/shared_lib/include/graphics/PNGReader.h @@ -0,0 +1,34 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2010 Martiño Figueroa and others +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef PNGREADER_H +#define PNGREADER_H + +// ===================================== +// class PNGReader +// ===================================== + +#include "FileReader.h" +#include "pixmap.h" + +namespace Shared{ namespace Graphics{ + +class PNGReader: FileReader { +public: + PNGReader(); + + Pixmap2D* read(ifstream& in, const string& path, Pixmap2D* ret) const; +}; + + +}} //end namespace + +#endif diff --git a/source/shared_lib/include/graphics/TGAReader.h b/source/shared_lib/include/graphics/TGAReader.h new file mode 100644 index 00000000..b19992d7 --- /dev/null +++ b/source/shared_lib/include/graphics/TGAReader.h @@ -0,0 +1,34 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2010 Martiño Figueroa and others +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef TGAREADER_H +#define TGAREADER_H + +// ===================================== +// class TGAReader +// ===================================== + +#include "FileReader.h" +#include "pixmap.h" + +namespace Shared{ namespace Graphics{ + +class TGAReader: FileReader { +public: + TGAReader(); + + Pixmap2D* read(ifstream& in, const string& path, Pixmap2D* ret) const; +}; + + +}} //end namespace + +#endif diff --git a/source/shared_lib/include/graphics/pixmap.h b/source/shared_lib/include/graphics/pixmap.h new file mode 100644 index 00000000..19703fd4 --- /dev/null +++ b/source/shared_lib/include/graphics/pixmap.h @@ -0,0 +1,269 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2008 Martiño Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef _SHARED_GRAPHICS_PIXMAP_H_ +#define _SHARED_GRAPHICS_PIXMAP_H_ + +#include + +#include "vec.h" +#include "types.h" + +using std::string; +using Shared::Platform::int8; +using Shared::Platform::uint8; +using Shared::Platform::int16; +using Shared::Platform::uint16; +using Shared::Platform::int32; +using Shared::Platform::uint32; +using Shared::Platform::float32; + +namespace Shared{ namespace Graphics{ + +// ===================================================== +// class PixmapIo +// ===================================================== + +class PixmapIo{ +protected: + int w; + int h; + int components; + +public: + virtual ~PixmapIo(){} + + int getW() const {return w;} + int getH() const {return h;} + int getComponents() const {return components;} + + virtual void openRead(const string &path)= 0; + virtual void read(uint8 *pixels)= 0; + virtual void read(uint8 *pixels, int components)= 0; + + virtual void openWrite(const string &path, int w, int h, int components)= 0; + virtual void write(uint8 *pixels)= 0; +}; + +// ===================================================== +// class PixmapIoTga +// ===================================================== + +class PixmapIoTga: public PixmapIo{ +private: + FILE *file; + +public: + PixmapIoTga(); + virtual ~PixmapIoTga(); + + virtual void openRead(const string &path); + virtual void read(uint8 *pixels); + virtual void read(uint8 *pixels, int components); + + virtual void openWrite(const string &path, int w, int h, int components); + virtual void write(uint8 *pixels); +}; + +// ===================================================== +// class PixmapIoBmp +// ===================================================== + +class PixmapIoBmp: public PixmapIo{ +private: + FILE *file; + +public: + PixmapIoBmp(); + virtual ~PixmapIoBmp(); + + virtual void openRead(const string &path); + virtual void read(uint8 *pixels); + virtual void read(uint8 *pixels, int components); + + virtual void openWrite(const string &path, int w, int h, int components); + virtual void write(uint8 *pixels); +}; + +// ===================================================== +// class Pixmap1D +// ===================================================== + +class Pixmap1D{ +protected: + int w; + int components; + uint8 *pixels; + +public: + //constructor & destructor + Pixmap1D(); + Pixmap1D(int components); + Pixmap1D(int w, int components); + void init(int components); + void init(int w, int components); + ~Pixmap1D(); + + //load & save + void load(const string &path); + void loadTga(const string &path); + void loadBmp(const string &path); + + //get + int getW() const {return w;} + int getComponents() const {return components;} + uint8 *getPixels() const {return pixels;} +}; + +// ===================================================== +// class Pixmap2D +// ===================================================== + +class Pixmap2D{ +protected: + int h; + int w; + int components; + uint8 *pixels; + +public: + //constructor & destructor + Pixmap2D(); + Pixmap2D(int components); + Pixmap2D(int w, int h, int components); + void init(int components); + void init(int w, int h, int components); + ~Pixmap2D(); + + //load & save + static Pixmap2D* loadPath(const string& path); + void load(const string &path); + /*void loadTga(const string &path); + void loadBmp(const string &path);*/ + void save(const string &path); + void saveBmp(const string &path); + void saveTga(const string &path); + + + //get + int getW() const {return w;} + int getH() const {return h;} + int getComponents() const {return components;} + uint8 *getPixels() const {return pixels;} + + //get data + void getPixel(int x, int y, uint8 *value) const; + void getPixel(int x, int y, float32 *value) const; + void getComponent(int x, int y, int component, uint8 &value) const; + void getComponent(int x, int y, int component, float32 &value) const; + + //vector get + Vec4f getPixel4f(int x, int y) const; + Vec3f getPixel3f(int x, int y) const; + float getPixelf(int x, int y) const; + float getComponentf(int x, int y, int component) const; + + //set data + void setPixel(int x, int y, const uint8 *value); + void setPixel(int x, int y, const float32 *value); + void setComponent(int x, int y, int component, uint8 value); + void setComponent(int x, int y, int component, float32 value); + + //vector set + void setPixel(int x, int y, const Vec3f &p); + void setPixel(int x, int y, const Vec4f &p); + void setPixel(int x, int y, float p); + + //mass set + void setPixels(const uint8 *value); + void setPixels(const float32 *value); + void setComponents(int component, uint8 value); + void setComponents(int component, float32 value); + + //operations + void splat(const Pixmap2D *leftUp, const Pixmap2D *rightUp, const Pixmap2D *leftDown, const Pixmap2D *rightDown); + void lerp(float t, const Pixmap2D *pixmap1, const Pixmap2D *pixmap2); + void copy(const Pixmap2D *sourcePixmap); + void subCopy(int x, int y, const Pixmap2D *sourcePixmap); + +private: + bool doDimensionsAgree(const Pixmap2D *pixmap); +}; + +// ===================================================== +// class Pixmap3D +// ===================================================== + +class Pixmap3D{ +protected: + int h; + int w; + int d; + int components; + uint8 *pixels; + +public: + //constructor & destructor + Pixmap3D(); + Pixmap3D(int w, int h, int d, int components); + Pixmap3D(int d, int components); + void init(int w, int h, int d, int components); + void init(int d, int components); + ~Pixmap3D(); + + //load & save + void loadSlice(const string &path, int slice); + void loadSliceBmp(const string &path, int slice); + void loadSliceTga(const string &path, int slice); + + //get + int getW() const {return w;} + int getH() const {return h;} + int getD() const {return d;} + int getComponents() const {return components;} + uint8 *getPixels() const {return pixels;} +}; + +// ===================================================== +// class PixmapCube +// ===================================================== + +class PixmapCube{ +public: + enum Face{ + fPositiveX, + fNegativeX, + fPositiveY, + fNegativeY, + fPositiveZ, + fNegativeZ + }; + +protected: + Pixmap2D faces[6]; + +public: + //init + void init(int w, int h, int components); + + //load & save + void loadFace(const string &path, int face); + /*void loadFaceBmp(const string &path, int face); + void loadFaceTga(const string &path, int face);*/ + + //get + Pixmap2D *getFace(int face) {return &faces[face];} + const Pixmap2D *getFace(int face) const {return &faces[face];} +}; + +}}//end namespace + +#endif diff --git a/source/shared_lib/include/platform/sdl/platform_util.h b/source/shared_lib/include/platform/sdl/platform_util.h index 5ceb2687..d85b44c4 100644 --- a/source/shared_lib/include/platform/sdl/platform_util.h +++ b/source/shared_lib/include/platform/sdl/platform_util.h @@ -96,6 +96,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string vector > getFolderTreeContentsCheckSumListRecursively(const string &path, const string &filterFileExt, vector > *recursiveMap); void createDirectoryPaths(string Path); string extractDirectoryPathFromFile(string filename); +string extractExtension(const string& filename); void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight); bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency); diff --git a/source/shared_lib/include/platform/win32/platform_util.h b/source/shared_lib/include/platform/win32/platform_util.h index 12eba47d..a3c00410 100755 --- a/source/shared_lib/include/platform/win32/platform_util.h +++ b/source/shared_lib/include/platform/win32/platform_util.h @@ -105,6 +105,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string vector > getFolderTreeContentsCheckSumListRecursively(const string &path, const string &filterFileExt, vector > *recursiveMap); void createDirectoryPaths(string Path); string extractDirectoryPathFromFile(string filename); +string extractExtension(const string& filename); void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight); bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency); diff --git a/source/shared_lib/sources/graphics/BMPReader.cpp b/source/shared_lib/sources/graphics/BMPReader.cpp new file mode 100644 index 00000000..d799fb60 --- /dev/null +++ b/source/shared_lib/sources/graphics/BMPReader.cpp @@ -0,0 +1,114 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2010 Martiño Figueroa and others +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "BMPReader.h" +#include "types.h" +#include "pixmap.h" +#include + +using std::runtime_error; + +namespace Shared{ namespace Graphics{ + +/**Copied from pixmap.cpp*/ +// ===================================================== +// Structs used for BMP-reading +// ===================================================== +#pragma pack(push, 1) + +struct BitmapFileHeader{ + uint8 type1; + uint8 type2; + uint32 size; + uint16 reserved1; + uint16 reserved2; + uint32 offsetBits; +}; + +struct BitmapInfoHeader{ + uint32 size; + int32 width; + int32 height; + uint16 planes; + uint16 bitCount; + uint32 compression; + uint32 sizeImage; + int32 xPelsPerMeter; + int32 yPelsPerMeter; + uint32 clrUsed; + uint32 clrImportant; +}; + +#pragma pack(pop) + +/**Returns a string containing the extensions we want, intitialisation is guaranteed*/ +static inline const string* getExtensionsBmp() { + static const string extensions[] = {"bmp", ""}; + return extensions; +} + +// ===================================================== +// class BMPReader +// ===================================================== + +BMPReader::BMPReader(): FileReader(getExtensionsBmp()) {} + +/**Reads a Pixmap2D-object + *This function reads a Pixmap2D-object from the given ifstream utilising the already existing Pixmap2D* ret. + *Path is used for printing error messages + *@return NULL if the Pixmap2D could not be read, else the pixmap*/ +Pixmap2D* BMPReader::read(ifstream& in, const string& path, Pixmap2D* ret) const { + //read file header + BitmapFileHeader fileHeader; + in.read((char*)&fileHeader, sizeof(BitmapFileHeader)); + if(fileHeader.type1!='B' || fileHeader.type2!='M'){ + throw runtime_error(path +" is not a bitmap"); + } + //read info header + BitmapInfoHeader infoHeader; + in.read((char*)&infoHeader, sizeof(BitmapInfoHeader)); + if(infoHeader.bitCount!=24){ + throw runtime_error(path+" is not a 24 bit bitmap"); + } + int h= infoHeader.height; + int w= infoHeader.width; + int components= (ret->getComponents() == -1)?3:ret->getComponents(); + ret->init(w,h,components); + uint8* pixels = ret->getPixels(); + for(int i=0; i +#include +#include + +using std::runtime_error; +using std::ios; + +/**Used things from CImageLoaderJPG.cpp from Irrlicht*/ + +namespace Shared{ namespace Graphics{ + +// ===================================================== +// Methods used for JPG-Decompression +// ===================================================== + + +//Methods used by jpeglib +static void init_source(j_decompress_ptr cinfo) { + //It already is initialized +} +static boolean fill_input_buffer (j_decompress_ptr cinfo) { + //it is already filled + return true; +} +static void skip_input_data (j_decompress_ptr cinfo, long num_bytes) { + if (num_bytes > 0) { + jpeg_source_mgr* This = cinfo->src; + This->bytes_in_buffer-= num_bytes; + This->next_input_byte+= num_bytes; + } +} +static void term_source (j_decompress_ptr cinfo) { +} + +// ===================================================== +// class JPGReader +// ===================================================== + +/**Return an array containing the used extensions, + * initialized*/ +static inline const string* getExtensions() { + static const string extensions[] = {"jpg", "jpeg", ""}; + return extensions; +} + +JPGReader::JPGReader(): FileReader(getExtensions()) {} + +Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const { + //Read file + is.seekg(0, ios::end); + size_t length = is.tellg(); + is.seekg(0, ios::beg); + uint8 * buffer = new uint8[length]; + is.read((char*)buffer, length); + + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + + JSAMPROW row_pointer[1]; + row_pointer[0] = NULL; + cinfo.err = jpeg_std_error( &jerr ); //Standard error handler + jpeg_create_decompress( &cinfo ); //Create decompressing structure + struct jpeg_source_mgr source; + + jmp_buf error_buffer; //Used for saving/restoring context + // Set up data pointer + source.bytes_in_buffer = length; + source.next_input_byte = (JOCTET*)buffer; + cinfo.src = &source; + + if (setjmp(error_buffer)) { //Longjump was called --> an exception was thrown + delete[] buffer; + jpeg_destroy_decompress(&cinfo); + if (row_pointer[0] != NULL) { + delete[] row_pointer[0]; + } + return NULL; + } + + source.init_source = init_source; + source.fill_input_buffer = fill_input_buffer; + source.resync_to_restart = jpeg_resync_to_restart; + source.skip_input_data = skip_input_data; + source.term_source = term_source; + + /* reading the image header which contains image information */ + if (jpeg_read_header( &cinfo, TRUE ) != JPEG_HEADER_OK) { + delete[] buffer; + jpeg_destroy_decompress(&cinfo); + return NULL; + } + + + /*std::cout << "JPEG FILE Information: " << std::endl; + std::cout << "Image width and height: " << cinfo.image_width <<" pixels and " << cinfo.image_height <<" pixels." << std::endl; + std::cout << "Color components per fixel: " << cinfo.num_components << std::endl; + std::cout << "Color space: " << cinfo.jpeg_color_space << std::endl;*/ + const int picComponents = (ret->getComponents() == -1)?cinfo.num_components:ret->getComponents(); + ret->init(cinfo.image_width, cinfo.image_height, picComponents); + uint8* pixels = ret->getPixels(); + //TODO: Irrlicht has some special CMYK-handling - maybe needed too? + /* Start decompression jpeg here */ + jpeg_start_decompress( &cinfo ); + + /* now actually read the jpeg into the raw buffer */ + row_pointer[0] = new unsigned char[cinfo.output_width*cinfo.num_components]; + size_t location = 0; //Current pixel + /* read one scan line at a time */ + /* Again you need to invert the lines unfortunately*/ + while( cinfo.output_scanline < cinfo.image_height ) + { + jpeg_read_scanlines( &cinfo, row_pointer, 1 ); + location = (cinfo.image_height - cinfo.output_scanline)*cinfo.image_width*cinfo.num_components; + if (picComponents == cinfo.num_components) { + memcpy(pixels+location,row_pointer[0],cinfo.image_width*cinfo.num_components); + } else { + int r,g,b,a,l; + for (int xPic = 0, xFile = 0; xPic < cinfo.image_width*picComponents; xPic+= picComponents, xFile+= cinfo.num_components) { + switch(cinfo.num_components) { + case 3: + r = row_pointer[0][xFile]; + g = row_pointer[0][xFile+1]; + b = row_pointer[0][xFile+2]; + l = (r+g+b+2)/3; + a = 255; + break; + case 4: + r = row_pointer[0][xFile]; + g = row_pointer[0][xFile+1]; + b = row_pointer[0][xFile+2]; + l = (r+g+b+2)/3; + a = row_pointer[0][xFile+3]; + break; + default: + //TODO: Error + case 1: + r = g = b = l = row_pointer[0][xFile]; + a = 255; + break; + } + switch (picComponents) { + case 1: + pixels[location+xPic] = l; + break; + case 4: + pixels[location+xPic+3] = a; //Next case + case 3: + pixels[location+xPic] = r; + pixels[location+xPic+1] = g; + pixels[location+xPic+2] = b; + break; + default: + //just so at least something works + for (int i = 0; i < picComponents; ++i) { + pixels[location+xPic+i] = l; + } + //TODO: Error + } + } + } + } + /* wrap up decompression, destroy objects, free pointers and close open files */ + jpeg_finish_decompress( &cinfo ); + jpeg_destroy_decompress( &cinfo ); + delete[] row_pointer[0]; + return ret; +} + +}} //end namespace diff --git a/source/shared_lib/sources/graphics/PNGReader.cpp b/source/shared_lib/sources/graphics/PNGReader.cpp new file mode 100644 index 00000000..098bd7ec --- /dev/null +++ b/source/shared_lib/sources/graphics/PNGReader.cpp @@ -0,0 +1,170 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2010 Martiño Figueroa and others +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "PNGReader.h" + +#include "types.h" +#include "pixmap.h" +#include +#include +#include + +using std::runtime_error; +using std::ios; + +/**Used things from CImageLoaderJPG.cpp from Irrlicht*/ + +namespace Shared{ namespace Graphics{ + +// ===================================================== +// Callbacks for PNG-decompression +// ===================================================== + +static void user_read_data(png_structp read_ptr, png_bytep data, png_size_t length) { + ifstream& is = *((ifstream*)png_get_io_ptr(read_ptr)); + is.read((char*)data,length); + if (!is.good()) { + png_error(read_ptr,"Could not read from png-file"); + } +} + +static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { +} + +static void user_flush_data(png_structp png_ptr) {} + +/**Get Extension array, initialised*/ +static inline const string* getExtensionsPng() { + static const string extensions[] = {"png", ""}; + return extensions; +} + +// ===================================================== +// class PNGReader +// ===================================================== + +PNGReader::PNGReader(): FileReader(getExtensionsPng()) {} + +Pixmap2D* PNGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const { + //Read file + is.seekg(0, ios::end); + size_t length = is.tellg(); + is.seekg(0, ios::beg); + uint8 * buffer = new uint8[8]; + is.read((char*)buffer, 8); + + if (png_sig_cmp(buffer, 0, 8) != 0) { + return NULL; //This is not a PNG file - could be used for fast checking whether file is supported or not + } + + png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) { + return NULL; + } + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + return NULL; + } + if (setjmp(png_jmpbuf(png_ptr))) { + return NULL; //Error during init_io + } + png_set_read_fn(png_ptr, &is, user_read_data); + png_set_sig_bytes(png_ptr, 8); + png_read_info(png_ptr, info_ptr); + + int width = info_ptr->width; + int height = info_ptr->height; + int color_type = info_ptr->color_type; + int bit_depth = info_ptr->bit_depth; + + //We want RGB, 24 bit + if (color_type == PNG_COLOR_TYPE_PALETTE || (color_type == PNG_COLOR_TYPE_GRAY && info_ptr->bit_depth < 8) || (info_ptr->valid & PNG_INFO_tRNS)) { + png_set_expand(png_ptr); + } + + if (color_type == PNG_COLOR_TYPE_GRAY) { + png_set_gray_to_rgb(png_ptr); + } + + int number_of_passes = png_set_interlace_handling(png_ptr); + png_read_update_info(png_ptr, info_ptr); + png_bytep* row_pointers = new png_bytep[height]; + + if (setjmp(png_jmpbuf(png_ptr))) { + delete[] row_pointers; + return NULL; //error during read_image + } + for (int y = 0; y < height; ++y) { + row_pointers[y] = new png_byte[info_ptr->rowbytes]; + } + png_read_image(png_ptr, row_pointers); + int fileComponents = info_ptr->rowbytes/info_ptr->width; + int picComponents = (ret->getComponents()==-1)?fileComponents:ret->getComponents(); + //Copy image + ret->init(width,height,picComponents); + uint8* pixels = ret->getPixels(); + const int rowbytes = info_ptr->rowbytes; + int location = 0; + for (int y = height-1; y >= 0; --y) { //you have to somehow invert the lines + if (picComponents == fileComponents) { + memcpy(pixels+location,row_pointers[y],rowbytes); + } else { + int r,g,b,a,l; + for (int xPic = 0, xFile = 0; xFile < rowbytes; xPic+= picComponents, xFile+= fileComponents) { + switch(fileComponents) { + case 3: + r = row_pointers[y][xFile]; + g = row_pointers[y][xFile+1]; + b = row_pointers[y][xFile+2]; + l = (r+g+b+2)/3; + a = 255; + break; + case 4: + r = row_pointers[y][xFile]; + g = row_pointers[y][xFile+1]; + b = row_pointers[y][xFile+2]; + l = (r+g+b+2)/3; + a = row_pointers[y][xFile+3]; + break; + default: + //TODO: Error + case 1: + r = g = b = l = row_pointers[y][xFile]; + a = 255; + break; + } + switch (picComponents) { + case 1: + pixels[location+xPic] = l; + break; + case 4: + pixels[location+xPic+3] = a; //Next case + case 3: + pixels[location+xPic] = r; + pixels[location+xPic+1] = g; + pixels[location+xPic+2] = b; + break; + default: + //just so at least something works + for (int i = 0; i < picComponents; ++i) { + pixels[location+xPic+i] = l; + } + //TODO: Error + } + } + } + location+=picComponents*width; + } + delete[] row_pointers; + return ret; +} + +}} //end namespace diff --git a/source/shared_lib/sources/graphics/TGAReader.cpp b/source/shared_lib/sources/graphics/TGAReader.cpp new file mode 100644 index 00000000..7c74327a --- /dev/null +++ b/source/shared_lib/sources/graphics/TGAReader.cpp @@ -0,0 +1,136 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2010 Martiño Figueroa and others +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "TGAReader.h" +#include "types.h" +#include "pixmap.h" +#include +#include + +using std::runtime_error; + +namespace Shared{ namespace Graphics{ + +#pragma pack(push, 1) + +/**Copied from pixmap.cpp*/ +// ===================================================== +// Information for reading the targa-file +// ===================================================== +struct TargaFileHeader{ + int8 idLength; + int8 colourMapType; + int8 dataTypeCode; + int16 colourMapOrigin; + int16 colourMapLength; + int8 colourMapDepth; + int16 xOrigin; + int16 yOrigin; + int16 width; + int16 height; + int8 bitsPerPixel; + int8 imageDescriptor; +}; + +#pragma pack(pop) + +static const int tgaUncompressedRgb= 2; +static const int tgaUncompressedBw= 3; + +// ===================================================== +// class TGAReader +// ===================================================== + +/**Get Extension array, initialised*/ +static inline const string* getExtensionStrings() { + static string * extensions = new string[2]; + extensions[0] = "tga"; + extensions[1] = ""; + return extensions; +} + +TGAReader::TGAReader(): FileReader(getExtensionStrings()) {} + +Pixmap2D* TGAReader::read(ifstream& in, const string& path, Pixmap2D* ret) const { + //read header + TargaFileHeader fileHeader; + in.read((char*)&fileHeader, sizeof(TargaFileHeader)); + if (!in.good()) { + throw runtime_error(path + " could not be read"); + } + + //check that we can load this tga file + if(fileHeader.idLength!=0){ + throw runtime_error(path + ": id field is not 0"); + } + + if(fileHeader.dataTypeCode!=tgaUncompressedRgb && fileHeader.dataTypeCode!=tgaUncompressedBw){ + throw runtime_error(path + ": only uncompressed BW and RGB targa images are supported"); + } + + //check bits per pixel + if(fileHeader.bitsPerPixel!=8 && fileHeader.bitsPerPixel!=24 && fileHeader.bitsPerPixel!=32){ + throw runtime_error(path + ": only 8, 24 and 32 bit targa images are supported"); + } + + const int h = fileHeader.height; + const int w = fileHeader.width; + const int fileComponents= fileHeader.bitsPerPixel/8; + const int picComponents = (ret->getComponents()==-1)?fileComponents:ret->getComponents(); + ret->init(w,h,picComponents); + uint8* pixels = ret->getPixels(); + //read file + for(int i=0; i::readPath(path); +} + void Pixmap2D::load(const string &path){ - string extension= path.substr(path.find_last_of('.')+1); - if(extension=="bmp"){ - loadBmp(path); - } - else if(extension=="tga"){ - loadTga(path); - } - else{ - throw runtime_error("Unknown pixmap extension: "+extension); - } + FileReader::readPath(path,this); } -void Pixmap2D::loadBmp(const string &path){ - - PixmapIoBmp plb; - plb.openRead(path); - - //init - w= plb.getW(); - h= plb.getH(); - if(components==-1){ - components= 3; - } - if(pixels==NULL){ - pixels= new uint8[w*h*components]; - } - - //data - plb.read(pixels, components); -} - -void Pixmap2D::loadTga(const string &path){ - - PixmapIoTga plt; - plt.openRead(path); - w= plt.getW(); - h= plt.getH(); - - //header - int fileComponents= plt.getComponents(); - - //init - if(components==-1){ - components= fileComponents; - } - if(pixels==NULL){ - pixels= new uint8[w*h*components]; - } - - //read data - plt.read(pixels, components); -} void Pixmap2D::save(const string &path){ string extension= path.substr(path.find_last_of('.')+1); @@ -865,12 +826,5 @@ void PixmapCube::loadFace(const string &path, int face){ faces[face].load(path); } -void PixmapCube::loadFaceBmp(const string &path, int face){ - faces[face].loadBmp(path); -} - -void PixmapCube::loadFaceTga(const string &path, int face){ - faces[face].loadTga(path); -} }}//end namespace diff --git a/source/shared_lib/sources/platform/sdl/platform_util.cpp b/source/shared_lib/sources/platform/sdl/platform_util.cpp index 30d826fa..3eaa8b31 100644 --- a/source/shared_lib/sources/platform/sdl/platform_util.cpp +++ b/source/shared_lib/sources/platform/sdl/platform_util.cpp @@ -414,6 +414,15 @@ string extractDirectoryPathFromFile(string filename) return filename.substr( 0, filename.rfind("/")+1 ); } +string extractExtension(const string& filepath) { + size_t lastPoint = filepath.find_last_of('.'); + size_t lastDirectory = filepath.find_last_of('/'); + if (lastPoint == string::npos || (lastDirectory != string::npos && lastDirectory > lastPoint)) { + return ""; + } + return filepath.substr(lastPoint+1); +} + void createDirectoryPaths(string Path) { char DirName[256]=""; diff --git a/source/shared_lib/sources/platform/win32/platform_util.cpp b/source/shared_lib/sources/platform/win32/platform_util.cpp index 20ada2b9..4ffc15d2 100644 --- a/source/shared_lib/sources/platform/win32/platform_util.cpp +++ b/source/shared_lib/sources/platform/win32/platform_util.cpp @@ -270,13 +270,13 @@ bool isdir(const char *path) bool EndsWith(const string &str, const string& key) { - bool result = false; - if (str.length() > key.length()) { - result = (0 == str.compare (str.length() - key.length(), key.length(), key)); - } - - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] result [%d] str = [%s] key = [%s]\n",__FILE__,__FUNCTION__,result,str.c_str(),key.c_str()); - return result; + bool result = false; + if (str.length() > key.length()) { + result = (0 == str.compare (str.length() - key.length(), key.length(), key)); + } + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] result [%d] str = [%s] key = [%s]\n",__FILE__,__FUNCTION__,result,str.c_str(),key.c_str()); + return result; } //finds all filenames like path and gets their checksum of all files combined @@ -449,6 +449,17 @@ string extractDirectoryPathFromFile(string filename) return filename.substr( 0, filename.rfind("/")+1 ); } +string extractExtension(const string& filepath) { + size_t lastPoint = filepath.find_last_of('.'); + size_t lastDirectory_Win = filepath.find_last_of('\\'); + size_t lastDirectory_Lin = filepath.find_last_of('/'); + size_t lastDirectory = (lastDirectory_Win lastPoint)) { + return ""; + } + return filepath.substr(lastPoint+1); +} + void createDirectoryPaths(string Path) { char DirName[256]=""; @@ -469,30 +480,30 @@ void createDirectoryPaths(string Path) } _mkdir(DirName); } - -void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight) { - // Get the current video hardware information - //const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo(); - //colorBits = vidInfo->vfmt->BitsPerPixel; - //screenWidth = vidInfo->current_w; - -/* - //screenHeight = vidInfo->current_h; + +void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight) { + // Get the current video hardware information + //const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo(); + //colorBits = vidInfo->vfmt->BitsPerPixel; + //screenWidth = vidInfo->current_w; + +/* + //screenHeight = vidInfo->current_h; int cx = GetSystemMetrics(SM_CXVIRTUALSCREEN); // height int cy = GetSystemMetrics(SM_CYVIRTUALSCREEN); - - printf("cx = %d, cy = %d\n",cx,cy); - - if(cx > screenWidth) { - screenWidth = cx; - screenHeight = cy; - } -*/ - int iMaxWidth = -1; - int iMaxHeight = -1; - int iMaxBits = -1; - + + printf("cx = %d, cy = %d\n",cx,cy); + + if(cx > screenWidth) { + screenWidth = cx; + screenHeight = cy; + } +*/ + int iMaxWidth = -1; + int iMaxHeight = -1; + int iMaxBits = -1; + DEVMODE devMode; for (int i=0; EnumDisplaySettings(NULL, i, &devMode) ;i++){ @@ -506,11 +517,11 @@ void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight) { } } if(iMaxWidth > 0) { - colorBits = iMaxBits; - screenWidth = iMaxWidth; - screenHeight = iMaxHeight; - } -} + colorBits = iMaxBits; + screenWidth = iMaxWidth; + screenHeight = iMaxHeight; + } +} bool changeVideoMode(int resW, int resH, int colorBits, int refreshFrequency){ DEVMODE devMode;