diff --git a/src/Makefile.macosx b/src/Makefile.macosx index 38c7b46..a31b423 100644 --- a/src/Makefile.macosx +++ b/src/Makefile.macosx @@ -2,7 +2,6 @@ CPP = g++ -g INCLUDES = LD = g++ -INCLUDEPATH = ../include X11INCLUDEDIR = /usr/X11R6/include X11LIBDIR = /usr/X11R6/lib INCLUDE_DIRS = -I$(X11INCLUDEDIR) @@ -13,10 +12,10 @@ LIBRARIES = SO_LIBS = SO_LIBRARIES = oa_game.so oa_audio.so oa_net.so oa_video.so oa_input.so CPPFLAGS = $(INCLUDE_DIRS) -LDFLAGS = $(LIBS) +LDFLAGS = $(LIBS) -bind_at_load --disable-framework=/Library/Frameworks/OpenGL .Phony: all clean install -all: ../OpenArena/OpenArena +all: ../OpenArena clean: rm -f *.o @@ -25,8 +24,8 @@ clean: install: #Executables -../OpenArena/OpenArena: $(OBJECTS) - $(LD) $(LDFLAGS) $(INCLUDE_DIRS) -o ../OpenArena/OpenArena $(OBJECTS) +../OpenArena: $(OBJECTS) + $(LD) $(LDFLAGS) $(INCLUDE_DIRS) -o ../OpenArena $(OBJECTS) #Dynamic Libraries oa_game.so: @@ -40,50 +39,50 @@ oa_video.so: oa_input.so: #Object Files -screen.o: screen.cpp $(INCLUDEPATH)/screen.h +screen.o: screen.cpp screen.h $(CPP) -c $(INCLUDE_DIRS) -o screen.o screen.cpp -bmp.o: bmp.cpp $(INCLUDEPATH)/bmp.h $(INCLUDEPATH)/mygl.h $(INCLUDEPATH)/datatypes.h $(INCLUDEPATH)/texture.h +bmp.o: bmp.cpp bmp.h mygl.h datatypes.h texture.h $(CPP) -c $(INCLUDE_DIRS) -o bmp.o bmp.cpp -camera.o: camera.cpp $(INCLUDEPATH)/camera.h $(INCLUDEPATH)/vector.h $(INCLUDEPATH)/mygl.h $(INCLUDEPATH)/screen.h +camera.o: camera.cpp camera.h vector.h mygl.h screen.h $(CPP) -c $(INCLUDE_DIRS) -o camera.o camera.cpp -ctrls.o: ctrls.cpp $(INCLUDEPATH)/ctrls.h $(INCLUDEPATH)/keys.h $(INCLUDEPATH)/physics.h $(INCLUDEPATH)/datatypes.h $(INCLUDEPATH)/list.h +ctrls.o: ctrls.cpp ctrls.h keys.h physics.h datatypes.h list.h $(CPP) -c $(INCLUDE_DIRS) -o ctrls.o ctrls.cpp -level.o: level.cpp $(INCLUDEPATH)/level.h $(INCLUDEPATH)/version.h +level.o: level.cpp level.h version.h $(CPP) -c $(INCLUDE_DIRS) -o level.o level.cpp -mygl.o: mygl.cpp $(INCLUDEPATH)/mygl.h +mygl.o: mygl.cpp mygl.h $(CPP) -c $(INCLUDE_DIRS) -o mygl.o mygl.cpp -myglFont.o: myglFont.cpp $(INCLUDEPATH)/myglFont.h +myglFont.o: myglFont.cpp myglFont.h $(CPP) -c $(INCLUDE_DIRS) -o myglFont.o myglFont.cpp -myglTexture.o: myglTexture.cpp $(INCLUDEPATH)/myglTexture.h +myglTexture.o: myglTexture.cpp myglTexture.h $(CPP) -c $(INCLUDE_DIRS) -o myglTexture.o myglTexture.cpp -physics.o: physics.cpp $(INCLUDEPATH)/physics.h +physics.o: physics.cpp physics.h $(CPP) -c $(INCLUDE_DIRS) -o physics.o physics.cpp -player.o: player.cpp $(INCLUDEPATH)/player.h +player.o: player.cpp player.h $(CPP) -c $(INCLUDE_DIRS) -o player.o player.cpp -strmanip.o: strmanip.cpp $(INCLUDEPATH)/strmanip.h +strmanip.o: strmanip.cpp strmanip.h $(CPP) -c $(INCLUDE_DIRS) -o strmanip.o strmanip.cpp -tga.o: tga.cpp $(INCLUDEPATH)/tga.h +tga.o: tga.cpp tga.h $(CPP) -c $(INCLUDE_DIRS) -o tga.o tga.cpp -vector.o: vector.cpp $(INCLUDEPATH)/vector.h +vector.o: vector.cpp vector.h $(CPP) -c $(INCLUDE_DIRS) -o vector.o vector.cpp -window.o: window.cpp $(INCLUDEPATH)/window.h +window.o: window.cpp window.h $(CPP) -c $(INCLUDE_DIRS) -o window.o window.cpp -keys.o: keys.cpp $(INCLUDEPATH)/keys.h +keys.o: keys.cpp keys.h $(CPP) -c $(INCLUDE_DIRS) -o keys.o keys.cpp -main.o: macosx.cpp $(INCLUDEPATH)/main.h +main.o: macosx.cpp main.h $(CPP) -c $(INCLUDE_DIRS) -o main.o macosx.cpp diff --git a/src/bmp.cpp b/src/bmp.cpp index ad8f3b1..75e8bcb 100644 --- a/src/bmp.cpp +++ b/src/bmp.cpp @@ -26,215 +26,58 @@ namespace OpenArena{ - /*! - * \brief - * Write brief comment for BitmapImage here. - * - * Write detailed description for BitmapImage here. - * - * \remarks - * Write remarks for BitmapImage here. - * - * \see - * Separate items with the '|' character. - */ - BitmapImage::BitmapImage() +#pragma pack(push,1) + struct BITMAP_HEADER { - BitmapImage(1, 1); + uint16 type; + uint32 size; + uint16 reserved1; + uint16 reserved2; + uint32 offset; + }; + + struct BITMAP_INFO + { + uint32 size; + uint32 width; + uint32 height; + uint16 planes; + uint16 bitCount; + uint32 compression; + uint32 sizeImage; + uint32 xPelsPerMeter; + uint32 yPelsPerMeter; + uint32 clrUsed; + uint32 clrImportant; + }; + + struct BITMAP_QUAD + { + uint8 blue; + uint8 green; + uint8 red; + uint8 reserved; + }; +#pragma pack(pop) + +#define BITMAP_MAGIC 19778 + + void PrintBMPHeader(BITMAP_HEADER header) + { + printf("Header\n"); + printf("Type: %X\nSize: %X\nReserved1: %X\nReserved2: %X\nOffset:%X\n", header.type, header.size, header.reserved1, header.reserved2, header.offset); } - - BitmapImage::BitmapImage(uint32 width, uint32 height, uint32 bitsPerPixel, Image::Type type) + void PrintBMPInfo(BITMAP_INFO info) { - _width = width; - _height = height; - _bpp = bitsPerPixel; - _type = type; - _data = new uint8[_width * _height * (_bpp >> 3)]; + printf("Info\n"); + printf("Size: %X\nWidth: %X\nHeight:%X\n", info.size, info.width, info.height); + printf("Planes: %X\nBitCount: %X\nCompression: %X\n", info.planes, info.bitCount, info.compression); + printf("SizeImage: %X\nXPelsPerMeter: %X\nYPelsPerMeter: %X\n", info.sizeImage, info.xPelsPerMeter, info.yPelsPerMeter); + printf("ClrUsed: %X\nClrImportant: %X\n", info.clrUsed, info.clrImportant); } - BitmapImage::~BitmapImage() - { - delete [] _data; - } - - uint8 * BitmapImage::GetImageData() const - { - return _data; - } - - uint32 BitmapImage::GetBitsPerPixel() const - { - return _bpp; - } - - uint32 BitmapImage::GetBytesPerPixel() const - { - return _bpp >> 3; - } - - uint32 BitmapImage::GetWidth() const - { - return _width; - } - - uint32 BitmapImage::GetHeight() const - { - return _height; - } - - Image::Type BitmapImage::GetType() const - { - return _type; - } - - BitmapImage* BitmapImage::CreateFromFile(const char* filename) - { - FILE* file = NULL; //A file from cstdlib? - - //If our filename is null return an empty 1x1 image - if(filename == NULL) - { - return new BitmapImage(1,1); - } - - //Try to open the file - file = fopen(filename, "rb"); - - //If the open failed return an empry 1x1 image - if(file == NULL) - { - return new BitmapImage(1,1); - } - - BITMAP_HEADER bmpHeader; - BITMAP_INFO bmpInfo; - BITMAP_QUAD* pallette = NULL; - uint32 numPalletteEntries = 0; - uint32 numPixels; - - //Read the header from the file - fread(&bmpHeader, sizeof(bmpHeader), 1, file); - fread(&bmpInfo, sizeof(bmpInfo), 1, file); - - //Check for an invalid header - if(bmpInfo.width < 0) //See if the width is negative - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Image width is negative", "ERROR", MB_OK); -#endif - fclose(file); - return NULL; - } - if(bmpInfo.width % 4 != 0) //If the width is not a multiple of 4 - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Image width must be a multiple of 8", "ERROR", MB_OK); -#endif - fclose(file); - return NULL; - } - - if(bmpInfo.height < 0) //If the height is negative - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Image height is negative", "ERROR", MB_OK); -#endif - fclose(file); - return NULL; - } - if(bmpInfo.height % 4 != 0) //If the height is not a multiple of 4 - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Image height must be a multiple of 8", "ERROR", MB_OK); -#endif - fclose(file); - return NULL; - } - - if((bmpInfo.bitCount != 8 && bmpInfo.bitCount != 24) || bmpInfo.compression != 0) //Make sure the file is 8 or 24 bit and uncompressed - { //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Only 8 and 24 bit uncompressed windows bmp files are currently supported", "ERROR", MB_OK); -#endif - fclose(file); - return NULL; - } - - BitmapImage* image = new BitmapImage(bmpInfo.width, bmpInfo.height, bmpInfo.bitCount, (Type)GL_RGB); - - numPixels = image->GetWidth() * image->GetHeight(); - - //If 8-bit load the pallette - if(image->GetBitsPerPixel() == 8) - { - //TODO finish this - numPalletteEntries = image->GetBytesPerPixel(); - pallette = new BITMAP_QUAD[numPalletteEntries]; -// fread(pallette, sizeof(OpenArena::Bitmap::BITMAP_QUAD), pallette, file); - } - - //Seek to the start of data - fseek(file, bmpHeader.offset, SEEK_SET); - - //Read the image data - fread(image->_data, numPixels * image->GetBytesPerPixel(), 1, file); - - //If 8-bit apply the pallette - if(image->GetBitsPerPixel() == 8) - { - //TODO finish this - uint32 i1, i2; - for(i1=0; i1_data[i1] < numPalletteEntries) - { - image->_data[i2] = pallette[image->_data[i1]].red; - image->_data[i2+1] = pallette[image->_data[i1]].blue; - image->_data[i2+2] = pallette[image->_data[i1]].green; - } - } - //uint8* image = tex->data; - //tex->bpp = 24; - //bytes = pixels * tex->bpp; - //tex->data = new uint8[bytes]; - - //uint32 i; - //uint32 i2; - //for(i=0; idata[i2] = bmpPallette[image[i]].red; - // tex->data[i2 + 1] = bmpPallette[image[i]].blue; - // tex->data[i2 + 2] = bmpPallette[image[i]].green; - //} - //delete [] image; - //image = NULL; - } - else if(image->GetBitsPerPixel() == 24) - { - //Convert to rgb - uint32 i; - uint8 swap; - - for(i=0; iGetBytesPerPixel(); i+=3) - { - swap = image->_data[i]; - image->_data[i] = image->_data[i+2]; - image->_data[i+2] = swap; - } - } - - return image; - } - - TextureImage* BitmapImage::LoadBMP(const char* fn) + TextureImage* LoadBMP(const char* fn) { //If anything is not perfect return NULL after cleaning up our mess @@ -242,20 +85,86 @@ namespace OpenArena{ //If our filename is null if(!fn) + { return NULL; + } //Try to open our file and if successfull... f=fopen(fn, "rb"); if(f) { - BitmapImage::BITMAP_HEADER bmpHeader; - BitmapImage::BITMAP_INFO bmpInfo; - BitmapImage::BITMAP_QUAD* bmpPallette = NULL; + BITMAP_HEADER bmpHeader; + BITMAP_INFO bmpInfo; + BITMAP_QUAD* bmpPallette = NULL; uint32 palletteEntries = 0; fread(&bmpHeader, sizeof(bmpHeader), 1, f); + #if __BYTE_ORDER == __BIG_ENDIAN + //If big endian reorder bytes + bmpHeader.type = ((bmpHeader.type & 0xff00) >> 8) | + ((bmpHeader.type & 0x00ff) << 8); + bmpHeader.size = (bmpHeader.size & 0xff000000) >> 24 | + (bmpHeader.size & 0x00ff0000) >> 8 | + (bmpHeader.size & 0x0000ff00) << 8 | + (bmpHeader.size & 0x000000ff) << 24; + bmpHeader.reserved1 = ((bmpHeader.reserved1 & 0xff00) >> 8) | + ((bmpHeader.reserved1 & 0x00ff) << 8); + bmpHeader.reserved2 = ((bmpHeader.reserved2 & 0xff00) >> 8) | + ((bmpHeader.reserved2 & 0x00ff) << 8); + bmpHeader.offset = (bmpHeader.offset & 0xff000000) >> 24 | + (bmpHeader.offset & 0x00ff0000) >> 8 | + (bmpHeader.offset & 0x0000ff00) << 8 | + (bmpHeader.offset & 0x000000ff) << 24; + #endif + PrintBMPHeader(bmpHeader); + fread(&bmpInfo, sizeof(bmpInfo), 1, f); + #if __BYTE_ORDER == __BIG_ENDIAN + //If big endian reorder bytes + bmpInfo.size = (bmpInfo.size & 0xff000000) >> 24 | + (bmpInfo.size & 0x00ff0000) >> 8 | + (bmpInfo.size & 0x0000ff00) << 8 | + (bmpInfo.size & 0x000000ff) << 24; + bmpInfo.width = (bmpInfo.width & 0xff000000) >> 24 | + (bmpInfo.width & 0x00ff0000) >> 8 | + (bmpInfo.width & 0x0000ff00) << 8 | + (bmpInfo.width & 0x000000ff) << 24; + bmpInfo.height = (bmpInfo.height & 0xff000000) >> 24 | + (bmpInfo.height & 0x00ff0000) >> 8 | + (bmpInfo.height & 0x0000ff00) << 8 | + (bmpInfo.height & 0x000000ff) << 24; + bmpInfo.planes = ((bmpInfo.planes & 0xff00) >> 8) | + ((bmpInfo.planes & 0x00ff) << 8); + bmpInfo.bitCount = ((bmpInfo.bitCount & 0xff00) >> 8) | + ((bmpInfo.bitCount & 0x00ff) << 8); + bmpInfo.compression = (bmpInfo.compression & 0xff000000) >> 24 | + (bmpInfo.compression & 0x00ff0000) >> 8 | + (bmpInfo.compression & 0x0000ff00) << 8 | + (bmpInfo.compression & 0x000000ff) << 24; + bmpInfo.sizeImage = (bmpInfo.sizeImage & 0xff000000) >> 24 | + (bmpInfo.sizeImage & 0x00ff0000) >> 8 | + (bmpInfo.sizeImage & 0x0000ff00) << 8 | + (bmpInfo.sizeImage & 0x000000ff) << 24; + bmpInfo.xPelsPerMeter = (bmpInfo.xPelsPerMeter & 0xff000000) >> 24 | + (bmpInfo.xPelsPerMeter & 0x00ff0000) >> 8 | + (bmpInfo.xPelsPerMeter & 0x0000ff00) << 8 | + (bmpInfo.xPelsPerMeter & 0x000000ff) << 24; + bmpInfo.yPelsPerMeter = (bmpInfo.yPelsPerMeter & 0xff000000) >> 24 | + (bmpInfo.yPelsPerMeter & 0x00ff0000) >> 8 | + (bmpInfo.yPelsPerMeter & 0x0000ff00) << 8 | + (bmpInfo.yPelsPerMeter & 0x000000ff) << 24; + bmpInfo.clrUsed = (bmpInfo.clrUsed & 0xff000000) >> 24 | + (bmpInfo.clrUsed & 0x00ff0000) >> 8 | + (bmpInfo.clrUsed & 0x0000ff00) << 8 | + (bmpInfo.clrUsed & 0x000000ff) << 24; + bmpInfo.clrImportant = (bmpInfo.clrImportant & 0xff000000) >> 24 | + (bmpInfo.clrImportant & 0x00ff0000) >> 8 | + (bmpInfo.clrImportant & 0x0000ff00) << 8 | + (bmpInfo.clrImportant & 0x000000ff) << 24; + #endif + PrintBMPInfo(bmpInfo); + if(bmpInfo.width < 0) { @@ -324,8 +233,8 @@ namespace OpenArena{ { //Load the pallette palletteEntries = bmpInfo.bitCount << 8; - bmpPallette = new BitmapImage::BITMAP_QUAD[palletteEntries]; - fread(bmpPallette, sizeof(BitmapImage::BITMAP_QUAD), palletteEntries, f); + bmpPallette = new BITMAP_QUAD[palletteEntries]; + fread(bmpPallette, sizeof(BITMAP_QUAD), palletteEntries, f); } fseek(f, bmpHeader.offset, SEEK_SET); @@ -369,4 +278,4 @@ namespace OpenArena{ } return NULL; } -}; \ No newline at end of file +}; diff --git a/src/camera.cpp b/src/camera.cpp index f0fe71d..cf36d71 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -71,7 +71,7 @@ namespace OpenArena m_vUpVector = up; } - void Camera::SetViewByMouse(const Window* window) + void Camera::SetViewByMouse(Window window) { //Remove the ifdef and use the linux section for both linux and windows #ifdef __linux @@ -112,8 +112,8 @@ namespace OpenArena POINT mpos; POINT middle; double angleZ; - middle.x = window->GetWidth() / 2; - middle.y = window->GetHeight() / 2; + middle.x = window.GetWidth() / 2; + middle.y = window.GetHeight() / 2; GetCursorPos(&mpos); SetCursorPos(middle.x, middle.y); if(mpos.x != middle.x || mpos.y != middle.y) diff --git a/src/ctrls.cpp b/src/ctrls.cpp index ff368c0..6352443 100644 --- a/src/ctrls.cpp +++ b/src/ctrls.cpp @@ -271,4 +271,4 @@ namespace OpenArena{ return false; } } -}; \ No newline at end of file +}; diff --git a/src/level.cpp b/src/level.cpp index dca5b6a..99e866b 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -40,6 +40,7 @@ namespace OpenArena _window = NULL; textureNames = NULL; numTextures = 0; + textures = NULL; screen.SetName(OPENARENA_VERSION); @@ -416,15 +417,12 @@ namespace OpenArena } //Free all map textures - textures.Clear(); -/* if(textures) { delete [] textures; textures = NULL; } -*/ - + //Free the array of texture names if (textureNames) { @@ -435,22 +433,23 @@ namespace OpenArena void Level::LoadGLTextures() { + printf("In LoadGLTextures: _window = %d\n", _window); if(_window != NULL) { - /*GLfloat light[4] = {1.0f,1.0f,1.0f,0.5f}; - glLightfv(GL_LIGHT1, GL_AMBIENT, light); + /* + GLfloat light[4] = {1.0f,1.0f,1.0f,0.5f}; + glLightfv(GL_LIGHT1, GL_AMBIENT, light); glEnable(GL_LIGHT1); - glEnable(GL_LIGHTING);*/ - - textures.Clear(); -/* if(textures != NULL) + glEnable(GL_LIGHTING); + */ + + if(textures != NULL) { delete [] textures; } - + textures = new Texture[numTextures]; -*/ for(uint32 i=0; i=(const Texture& rtOp) { - return id>=rtOp.id; + return id>= rtOp.id; } bool Texture::operator>(const Texture& rtOp) { - return id>rtOp.id; + return id> rtOp.id; } }; diff --git a/src/screen.cpp b/src/screen.cpp index d40db0c..88854b2 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -11,27 +11,27 @@ namespace OpenArena _name = ""; } - int Screen::GetWidth() const + int Screen::GetWidth() { return _width; } - int Screen::GetHeight() const + int Screen::GetHeight() { return _height; } - int Screen::GetColorDepth() const + int Screen::GetColorDepth() { return _colorDepth; } - bool Screen::GetFullscreen() const + bool Screen::GetFullscreen() { return _fullscreen; } - const char* Screen::GetName() const + const char* Screen::GetName() { return _name.c_str(); } diff --git a/src/tga.cpp b/src/tga.cpp index 8d4d462..6514ecd 100644 --- a/src/tga.cpp +++ b/src/tga.cpp @@ -1,355 +1,257 @@ + #include "tga.h" +#include "datatypes.h" #ifdef WIN32 #pragma warning(disable:4996) #endif namespace OpenArena{ +TextureImage* LoadTGA(const char * filename) +{ + TGAHeader tgaheader; + TextureImage* image; + std::string errmsg; + FILE* file = fopen(filename, "rb"); - uint8 * TargaImage::GetImageData() const + if(file == NULL) { - return _data; + errmsg = "Could not open texture file "; + errmsg = errmsg + filename; + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, errmsg.c_str(), "ERROR", MB_OK); + #endif + return NULL; } - uint32 TargaImage::GetBitsPerPixel() const + if(fread(&tgaheader, sizeof(TGAHeader), 1, file) == 0) { - return _bpp; - } - - uint32 TargaImage::GetBytesPerPixel() const - { - return _bpp >> 8; - } - - uint32 TargaImage::GetWidth() const - { - return _width; - } - - uint32 TargaImage::GetHeight() const - { - return _height; - } - - Image::Type TargaImage::GetType() const - { - return _type; - } - - TargaImage::~TargaImage(void) - { - delete [] _data; - } - - TargaImage* TargaImage::CreateFromFile(const char* filename) - { - TextureImage* texImage = LoadTGA(filename); - TargaImage* image = new TargaImage(texImage->sizeX, texImage->sizeY, texImage->bpp); - image->_data = texImage->data; - image->_type = (Image::Type)texImage->type; - - return image; - } - - TargaImage::TargaImage(uint32 width, uint32 height, uint32 bpp, Image::Type type) - { - _width = width; - _height = height; - _bpp = bpp; - _type = type; - _data = new uint8[_width*_height* (_bpp >> 8)]; - } - - TargaImage::TargaImage() - { - TargaImage(1,1); - } - - TextureImage* TargaImage::LoadTGA(const char * filename) - { - TargaImage::TGAHeader tgaheader; - TextureImage* image; - std::string errmsg; - FILE* file = fopen(filename, "rb"); - - if(file == NULL) - { - errmsg = "Could not open texture file "; - errmsg = errmsg + filename; - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, errmsg.c_str(), "ERROR", MB_OK); -#endif - return NULL; - } - - if(fread(&tgaheader, sizeof(TargaImage::TGAHeader), 1, file) == 0) - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Could not read file header", "ERROR", MB_OK); -#endif - if(file != NULL) - fclose(file); - return NULL; - } - - if(memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)) == 0) - image = LoadUncompressedTGA(file); - else if(memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader)) == 0) - image = LoadCompressedTGA(file); - else - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "TGA file must be type 2 or type 10 ", "Invalid Image", MB_OK); -#endif + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, "Could not read file header", "ERROR", MB_OK); + #endif + if(file != NULL) fclose(file); - return NULL; + return NULL; + } + #if __BYTE_ORDER == __BIG_ENDIAN + /* This doesnt need to be done for this structure as it is just a collection of bytes + //If big endian reorder bytes + uint32 i; + + printf("\n%:X|", ((uint8*)&tgaheader)[1]); + for(i=1; isizeY = tga.header[1] * 256 + tga.header[0]; + image->sizeX = tga.header[3] * 256 + tga.header[2]; + image->bpp = tga.header[4]; + tga.Width = image->sizeX; + tga.Height = image->sizeY; + tga.Bpp = image->bpp; + + if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32))) + { + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK); + #endif + if(fTGA != NULL) + { + fclose(fTGA); + } + return NULL; } - TextureImage* TargaImage::LoadUncompressedTGA(FILE * fTGA) + if(image->bpp == 24) { - TargaImage::TGA tga; - TextureImage* image = new TextureImage; + image->type = GL_RGB; + } + else + { + image->type = GL_RGBA; + } - if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0) - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Could not read info header", "ERROR", MB_OK); -#endif - if(fTGA != NULL) - { - fclose(fTGA); - } - return NULL; - } + tga.bytesPerPixel = (tga.Bpp / 8); + tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height); + image->data = (GLubyte *)malloc(tga.imageSize); - image->sizeY = tga.header[1] * 256 + tga.header[0]; - image->sizeX = tga.header[3] * 256 + tga.header[2]; - image->bpp = tga.header[4]; - tga.Width = image->sizeX; - tga.Height = image->sizeY; - tga.Bpp = image->bpp; + if(image->data == NULL) + { + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK); + #endif + fclose(fTGA); + return NULL; + } - if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32))) + if(fread(image->data, 1, tga.imageSize, fTGA) != tga.imageSize) + { + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, "Could not read image data", "ERROR", MB_OK); + #endif + if(image->data != NULL) { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK); -#endif - if(fTGA != NULL) - { - fclose(fTGA); - } - return NULL; + free(image->data); } + fclose(fTGA); + return NULL; + } - if(image->bpp == 24) - { - image->type = GL_RGB; - } - else - { - image->type = GL_RGBA; - } + + for(GLuint cswap = 0; cswap < (int)tga.imageSize; cswap += tga.bytesPerPixel) + { + image->data[cswap] ^= image->data[cswap+2] ^= + image->data[cswap] ^= image->data[cswap+2]; + } - tga.bytesPerPixel = (tga.Bpp / 8); - tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height); - image->data = (GLubyte *)malloc(tga.imageSize); + fclose(fTGA); + return image; +} - if(image->data == NULL) +TextureImage* LoadCompressedTGA(FILE * fTGA) +{ + TextureImage* image = new TextureImage; + TGA tga; + + if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0) + { + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, "Could not read info header", "ERROR", MB_OK); + #endif + if(fTGA != NULL) { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK); -#endif fclose(fTGA); - return NULL; } + return NULL; + } - if(fread(image->data, 1, tga.imageSize, fTGA) != tga.imageSize) + image->sizeX = tga.header[1] * 256 + tga.header[0]; + image->sizeY = tga.header[3] * 256 + tga.header[2]; + image->bpp = tga.header[4]; + tga.Width = image->sizeX; + tga.Height = image->sizeY; + tga.Bpp = image->bpp; + + if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32))) + { + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK); + #endif + if(fTGA != NULL) + { + fclose(fTGA); + } + return NULL; + } + + tga.bytesPerPixel = (tga.Bpp / 8); + tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height); + image->data = (GLubyte *)malloc(tga.imageSize); + + if(image->data == NULL) + { + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK); + #endif + fclose(fTGA); + return NULL; + } + + GLuint pixelcount = tga.Height * tga.Width; + GLuint currentpixel = 0; + GLuint currentbyte = 0; + GLubyte * colorbuffer = (GLubyte *)malloc(tga.bytesPerPixel); + + do + { + GLubyte chunkheader = 0; + + if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0) { //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Could not read image data", "ERROR", MB_OK); -#endif + #ifdef WIN32 + MessageBox(NULL, "Could not read RLE header", "ERROR", MB_OK); + #endif + if(fTGA != NULL) + { + fclose(fTGA); + } if(image->data != NULL) { free(image->data); } - fclose(fTGA); return NULL; } - - for(GLuint cswap = 0; cswap < (int)tga.imageSize; cswap += tga.bytesPerPixel) + if(chunkheader < 128) { - image->data[cswap] ^= image->data[cswap+2] ^= - image->data[cswap] ^= image->data[cswap+2]; - } - - fclose(fTGA); - return image; - } - - TextureImage* TargaImage::LoadCompressedTGA(FILE * fTGA) - { - TextureImage* image = new TextureImage; - TargaImage::TGA tga; - - if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0) - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Could not read info header", "ERROR", MB_OK); -#endif - if(fTGA != NULL) + chunkheader++; + for(short counter = 0; counter < chunkheader; counter++) { - fclose(fTGA); - } - return NULL; - } - - image->sizeX = tga.header[1] * 256 + tga.header[0]; - image->sizeY = tga.header[3] * 256 + tga.header[2]; - image->bpp = tga.header[4]; - tga.Width = image->sizeX; - tga.Height = image->sizeY; - tga.Bpp = image->bpp; - - if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32))) - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK); -#endif - if(fTGA != NULL) - { - fclose(fTGA); - } - return NULL; - } - - tga.bytesPerPixel = (tga.Bpp / 8); - tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height); - image->data = (GLubyte *)malloc(tga.imageSize); - - if(image->data == NULL) - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK); -#endif - fclose(fTGA); - return NULL; - } - - GLuint pixelcount = tga.Height * tga.Width; - GLuint currentpixel = 0; - GLuint currentbyte = 0; - GLubyte * colorbuffer = (GLubyte *)malloc(tga.bytesPerPixel); - - do - { - GLubyte chunkheader = 0; - - if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0) - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Could not read RLE header", "ERROR", MB_OK); -#endif - if(fTGA != NULL) - { - fclose(fTGA); - } - if(image->data != NULL) - { - free(image->data); - } - return NULL; - } - - if(chunkheader < 128) - { - chunkheader++; - for(short counter = 0; counter < chunkheader; counter++) - { - if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Could not read image data", "ERROR", MB_OK); -#endif - - if(fTGA != NULL) - { - fclose(fTGA); - } - - if(colorbuffer != NULL) - { - free(colorbuffer); - } - - if(image->data != NULL) - { - free(image->data); - } - - return NULL; - } - - image->data[currentbyte ] = colorbuffer[2]; - image->data[currentbyte + 1 ] = colorbuffer[1]; - image->data[currentbyte + 2 ] = colorbuffer[0]; - - if(tga.bytesPerPixel == 4) - { - image->data[currentbyte + 3] = colorbuffer[3]; - } - - currentbyte += tga.bytesPerPixel; - currentpixel++; - - if(currentpixel > pixelcount) - { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Too many pixels read", "ERROR", NULL); -#endif - - if(fTGA != NULL) - { - fclose(fTGA); - } - - if(colorbuffer != NULL) - { - free(colorbuffer); - } - - if(image->data != NULL) - { - free(image->data); - } - - return NULL; - } - } - } - else - { - chunkheader -= 127; if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) - { + { //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Could not read from file", "ERROR", MB_OK); -#endif + #ifdef WIN32 + MessageBox(NULL, "Could not read image data", "ERROR", MB_OK); + #endif if(fTGA != NULL) { @@ -368,58 +270,124 @@ namespace OpenArena{ return NULL; } + + image->data[currentbyte ] = colorbuffer[2]; + image->data[currentbyte + 1 ] = colorbuffer[1]; + image->data[currentbyte + 2 ] = colorbuffer[0]; - for(short counter = 0; counter < chunkheader; counter++) + if(tga.bytesPerPixel == 4) { - image->data[currentbyte ] = colorbuffer[2]; - image->data[currentbyte + 1 ] = colorbuffer[1]; - image->data[currentbyte + 2 ] = colorbuffer[0]; + image->data[currentbyte + 3] = colorbuffer[3]; + } - if(tga.bytesPerPixel == 4) + currentbyte += tga.bytesPerPixel; + currentpixel++; + + if(currentpixel > pixelcount) + { + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, "Too many pixels read", "ERROR", NULL); + #endif + + if(fTGA != NULL) { - image->data[currentbyte + 3] = colorbuffer[3]; + fclose(fTGA); + } + + if(colorbuffer != NULL) + { + free(colorbuffer); } - currentbyte += tga.bytesPerPixel; - currentpixel++; - - if(currentpixel > pixelcount) + if(image->data != NULL) { - //This needs to be abstracted somehow -#ifdef WIN32 - MessageBox(NULL, "Too many pixels read", "ERROR", NULL); -#endif - - if(fTGA != NULL) - { - fclose(fTGA); - } - - if(colorbuffer != NULL) - { - free(colorbuffer); - } - - if(image->data != NULL) - { - free(image->data); - } - - return NULL; + free(image->data); } + + return NULL; } } } + else + { + chunkheader -= 127; + if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) + { + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, "Could not read from file", "ERROR", MB_OK); + #endif + + if(fTGA != NULL) + { + fclose(fTGA); + } - while(currentpixel < pixelcount); - fclose(fTGA); - return image; + if(colorbuffer != NULL) + { + free(colorbuffer); + } + + if(image->data != NULL) + { + free(image->data); + } + + return NULL; + } + + for(short counter = 0; counter < chunkheader; counter++) + { + image->data[currentbyte ] = colorbuffer[2]; + image->data[currentbyte + 1 ] = colorbuffer[1]; + image->data[currentbyte + 2 ] = colorbuffer[0]; + + if(tga.bytesPerPixel == 4) + { + image->data[currentbyte + 3] = colorbuffer[3]; + } + + currentbyte += tga.bytesPerPixel; + currentpixel++; + + if(currentpixel > pixelcount) + { + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL, "Too many pixels read", "ERROR", NULL); + #endif + + if(fTGA != NULL) + { + fclose(fTGA); + } + + if(colorbuffer != NULL) + { + free(colorbuffer); + } + + if(image->data != NULL) + { + free(image->data); + } + + return NULL; + } + } + } } + while(currentpixel < pixelcount); + fclose(fTGA); + return image; +} - /* - TextureImage* LoadTGA(const char * filename) - { + +/* +TextureImage* LoadTGA(const char * filename) +{ TGAHeader tgaheader; TextureImage* image; std::string errmsg; @@ -427,46 +395,46 @@ namespace OpenArena{ if(file == NULL) { - errmsg = "Could not open texture file "; - errmsg = errmsg + filename; - MessageBox(NULL, errmsg.c_str(), "ERROR", MB_OK); - return NULL; + errmsg = "Could not open texture file "; + errmsg = errmsg + filename; + MessageBox(NULL, errmsg.c_str(), "ERROR", MB_OK); + return NULL; } if(fread(&tgaheader, sizeof(TGAHeader), 1, file) == 0) { - MessageBox(NULL, "Could not read file header", "ERROR", MB_OK); - if(file != NULL) - fclose(file); - return NULL; + MessageBox(NULL, "Could not read file header", "ERROR", MB_OK); + if(file != NULL) + fclose(file); + return NULL; } if(memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)) == 0) - image = LoadUncompressedTGA(file); + image = LoadUncompressedTGA(file); else if(memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader)) == 0) - image = LoadCompressedTGA(file); + image = LoadCompressedTGA(file); else { - MessageBox(NULL, "TGA file must be type 2 or type 10 ", "Invalid Image", MB_OK); - fclose(file); - return NULL; + MessageBox(NULL, "TGA file must be type 2 or type 10 ", "Invalid Image", MB_OK); + fclose(file); + return NULL; } return image; - } +} - TextureImage* LoadUncompressedTGA(FILE * fTGA) - { +TextureImage* LoadUncompressedTGA(FILE * fTGA) +{ TGA tga; TextureImage* image = new TextureImage; - + if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0) { - MessageBox(NULL, "Could not read info header", "ERROR", MB_OK); - if(fTGA != NULL) - { - fclose(fTGA); - } - return NULL; + MessageBox(NULL, "Could not read info header", "ERROR", MB_OK); + if(fTGA != NULL) + { + fclose(fTGA); + } + return NULL; } image->sizeY = tga.header[1] * 256 + tga.header[0]; @@ -478,21 +446,21 @@ namespace OpenArena{ if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32))) { - MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK); - if(fTGA != NULL) - { - fclose(fTGA); - } - return NULL; + MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK); + if(fTGA != NULL) + { + fclose(fTGA); + } + return NULL; } if(image->bpp == 24) { - image->type = GL_RGB; + image->type = GL_RGB; } else { - image->type = GL_RGBA; + image->type = GL_RGBA; } tga.bytesPerPixel = (tga.Bpp / 8); @@ -501,46 +469,46 @@ namespace OpenArena{ if(image->data == NULL) { - MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK); - fclose(fTGA); - return NULL; + MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK); + fclose(fTGA); + return NULL; } if(fread(image->data, 1, tga.imageSize, fTGA) != tga.imageSize) { - MessageBox(NULL, "Could not read image data", "ERROR", MB_OK); - if(image->data != NULL) - { - free(image->data); - } - fclose(fTGA); - return NULL; + MessageBox(NULL, "Could not read image data", "ERROR", MB_OK); + if(image->data != NULL) + { + free(image->data); + } + fclose(fTGA); + return NULL; } - + for(GLuint cswap = 0; cswap < (int)tga.imageSize; cswap += tga.bytesPerPixel) { - image->data[cswap] ^= image->data[cswap+2] ^= - image->data[cswap] ^= image->data[cswap+2]; + image->data[cswap] ^= image->data[cswap+2] ^= + image->data[cswap] ^= image->data[cswap+2]; } fclose(fTGA); return image; - } +} - TextureImage* LoadCompressedTGA(FILE * fTGA) - { +TextureImage* LoadCompressedTGA(FILE * fTGA) +{ TextureImage* image = new TextureImage; TGA tga; if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0) { - MessageBox(NULL, "Could not read info header", "ERROR", MB_OK); - if(fTGA != NULL) - { - fclose(fTGA); - } - return NULL; + MessageBox(NULL, "Could not read info header", "ERROR", MB_OK); + if(fTGA != NULL) + { + fclose(fTGA); + } + return NULL; } image->sizeX = tga.header[1] * 256 + tga.header[0]; @@ -552,12 +520,12 @@ namespace OpenArena{ if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32))) { - MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK); - if(fTGA != NULL) - { - fclose(fTGA); - } - return NULL; + MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK); + if(fTGA != NULL) + { + fclose(fTGA); + } + return NULL; } tga.bytesPerPixel = (tga.Bpp / 8); @@ -566,9 +534,9 @@ namespace OpenArena{ if(image->data == NULL) { - MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK); - fclose(fTGA); - return NULL; + MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK); + fclose(fTGA); + return NULL; } GLuint pixelcount = tga.Height * tga.Width; @@ -578,151 +546,151 @@ namespace OpenArena{ do { - GLubyte chunkheader = 0; + GLubyte chunkheader = 0; - if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0) - { - MessageBox(NULL, "Could not read RLE header", "ERROR", MB_OK); - if(fTGA != NULL) - { - fclose(fTGA); - } - if(image->data != NULL) - { - free(image->data); - } - return NULL; - } + if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0) + { + MessageBox(NULL, "Could not read RLE header", "ERROR", MB_OK); + if(fTGA != NULL) + { + fclose(fTGA); + } + if(image->data != NULL) + { + free(image->data); + } + return NULL; + } - if(chunkheader < 128) - { - chunkheader++; - for(short counter = 0; counter < chunkheader; counter++) - { - if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) - { - MessageBox(NULL, "Could not read image data", "ERROR", MB_OK); + if(chunkheader < 128) + { + chunkheader++; + for(short counter = 0; counter < chunkheader; counter++) + { + if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) + { + MessageBox(NULL, "Could not read image data", "ERROR", MB_OK); - if(fTGA != NULL) - { - fclose(fTGA); - } + if(fTGA != NULL) + { + fclose(fTGA); + } - if(colorbuffer != NULL) - { - free(colorbuffer); - } + if(colorbuffer != NULL) + { + free(colorbuffer); + } - if(image->data != NULL) - { - free(image->data); - } + if(image->data != NULL) + { + free(image->data); + } - return NULL; - } + return NULL; + } + + image->data[currentbyte ] = colorbuffer[2]; + image->data[currentbyte + 1 ] = colorbuffer[1]; + image->data[currentbyte + 2 ] = colorbuffer[0]; - image->data[currentbyte ] = colorbuffer[2]; - image->data[currentbyte + 1 ] = colorbuffer[1]; - image->data[currentbyte + 2 ] = colorbuffer[0]; + if(tga.bytesPerPixel == 4) + { + image->data[currentbyte + 3] = colorbuffer[3]; + } - if(tga.bytesPerPixel == 4) - { - image->data[currentbyte + 3] = colorbuffer[3]; - } + currentbyte += tga.bytesPerPixel; + currentpixel++; - currentbyte += tga.bytesPerPixel; - currentpixel++; + if(currentpixel > pixelcount) + { + MessageBox(NULL, "Too many pixels read", "ERROR", NULL); - if(currentpixel > pixelcount) - { - MessageBox(NULL, "Too many pixels read", "ERROR", NULL); + if(fTGA != NULL) + { + fclose(fTGA); + } - if(fTGA != NULL) - { - fclose(fTGA); - } + if(colorbuffer != NULL) + { + free(colorbuffer); + } - if(colorbuffer != NULL) - { - free(colorbuffer); - } + if(image->data != NULL) + { + free(image->data); + } - if(image->data != NULL) - { - free(image->data); - } + return NULL; + } + } + } + else + { + chunkheader -= 127; + if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) + { + MessageBox(NULL, "Could not read from file", "ERROR", MB_OK); - return NULL; - } - } - } - else - { - chunkheader -= 127; - if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) - { - MessageBox(NULL, "Could not read from file", "ERROR", MB_OK); + if(fTGA != NULL) + { + fclose(fTGA); + } - if(fTGA != NULL) - { - fclose(fTGA); - } + if(colorbuffer != NULL) + { + free(colorbuffer); + } - if(colorbuffer != NULL) - { - free(colorbuffer); - } + if(image->data != NULL) + { + free(image->data); + } - if(image->data != NULL) - { - free(image->data); - } + return NULL; + } - return NULL; - } + for(short counter = 0; counter < chunkheader; counter++) + { + image->data[currentbyte ] = colorbuffer[2]; + image->data[currentbyte + 1 ] = colorbuffer[1]; + image->data[currentbyte + 2 ] = colorbuffer[0]; - for(short counter = 0; counter < chunkheader; counter++) - { - image->data[currentbyte ] = colorbuffer[2]; - image->data[currentbyte + 1 ] = colorbuffer[1]; - image->data[currentbyte + 2 ] = colorbuffer[0]; + if(tga.bytesPerPixel == 4) + { + image->data[currentbyte + 3] = colorbuffer[3]; + } - if(tga.bytesPerPixel == 4) - { - image->data[currentbyte + 3] = colorbuffer[3]; - } + currentbyte += tga.bytesPerPixel; + currentpixel++; - currentbyte += tga.bytesPerPixel; - currentpixel++; + if(currentpixel > pixelcount) + { + MessageBox(NULL, "Too many pixels read", "ERROR", NULL); - if(currentpixel > pixelcount) - { - MessageBox(NULL, "Too many pixels read", "ERROR", NULL); + if(fTGA != NULL) + { + fclose(fTGA); + } - if(fTGA != NULL) - { - fclose(fTGA); - } + if(colorbuffer != NULL) + { + free(colorbuffer); + } - if(colorbuffer != NULL) - { - free(colorbuffer); - } + if(image->data != NULL) + { + free(image->data); + } - if(image->data != NULL) - { - free(image->data); - } - - return NULL; - } - } - } + return NULL; + } + } + } } while(currentpixel < pixelcount); fclose(fTGA); return image; - } - */ -}; \ No newline at end of file +} +*/ +}; diff --git a/src/vector.cpp b/src/vector.cpp index 766c864..4081a8b 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -248,4 +248,4 @@ namespace OpenArena{ { return !(x == rtOp.x && y == rtOp.y); } -}; \ No newline at end of file +}; diff --git a/src/window.cpp b/src/window.cpp index ef8d600..731d7ca 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -143,7 +143,6 @@ bool OpenArena::Window::Open() vi = glXChooseVisual(display, screen, attrListDbl); if(vi == NULL) - { vi = glXChooseVisual(display, screen, attrListSgl); doubleBuffered = false; printf("Only Singlebuffered Visual!\n"); @@ -434,7 +433,7 @@ bool OpenArena::Window::Open() ShowWindow(window,SW_SHOW); SetForegroundWindow(window); SetFocus(window); - _resizer->Resize(_width, _height); + OnResize(_width, _height); if (!_initializer->Initialize()) { diff --git a/src/windows.cpp b/src/windows.cpp index 8656605..a107b03 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -250,10 +250,9 @@ int WINAPI WinMain( HINSTANCE hInstance, level.LoadMap(); } - g_Screen = g_PluginManager.GetDefaultVideoPlugin()->CreateNewWindow(level.screen.GetWidth(), level.screen.GetHeight()); - g_Screen->SetInitializer(new OpenArena::Window::Initializer()); - g_Screen->SetResizer(new OpenArena::Window::Resizer()); - if (!g_Screen->Open(string(OPENARENA_VERSION), level.screen.GetWidth(), level.screen.GetHeight(), level.screen.GetColorDepth(), level.screen.GetFullscreen())) + g_Screen.SetOnInit(InitGL); + g_Screen.SetOnResize(ReSizeGLScene); + if (!g_Screen.Open(string(OPENARENA_VERSION), level.screen.GetWidth(), level.screen.GetHeight(), level.screen.GetColorDepth(), level.screen.GetFullscreen())) { return 0; } @@ -293,7 +292,7 @@ int WINAPI WinMain( HINSTANCE hInstance, } else { - SetCursorPos(g_Screen->GetWidth()/2, g_Screen->GetHeight()/2); + SetCursorPos(g_Screen.GetWidth()/2, g_Screen.GetHeight()/2); } ////////// @@ -580,14 +579,14 @@ int WINAPI WinMain( HINSTANCE hInstance, } } - g_Screen->SwapBuffers(); + g_Screen.SwapBuffers(); if (keys[OpenArena::KEY_F1]) { keys[OpenArena::KEY_F1]=false; - g_Screen->Close(); - g_Screen->ToggleFullscreen(); - if (!g_Screen->Open("OpenArena",g_Screen->GetWidth(),g_Screen->GetHeight(),g_Screen->GetColorDepth(),g_Screen->GetFullscreen())) + g_Screen.Close(); + g_Screen.ToggleFullscreen(); + if (!g_Screen.Open("OpenArena",g_Screen.GetWidth(),g_Screen.GetHeight(),g_Screen.GetColorDepth(),g_Screen.GetFullscreen())) { return 0; } @@ -595,7 +594,7 @@ int WINAPI WinMain( HINSTANCE hInstance, } level.UnloadMap(); - g_Screen->Close(); + g_Screen.Close(); return (msg.wParam); } @@ -853,4 +852,4 @@ void HandleConsoleKeyPress(OpenArena::Keys key) } -#endif \ No newline at end of file +#endif