# HG changeset patch # User Ritor1 # Date 1394997615 -21600 # Node ID 6fd03869f65cb5e40a1c0800572117fcab4cb778 # Parent d65414f65bd4eadddce2ef6719445005db19bb9c LoadTexture cleaned and add ConvertPNG function diff -r d65414f65bd4 -r 6fd03869f65c Build/Visual Studio 2012/World of Might and Magic.vcxproj --- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj Sun Mar 16 19:34:51 2014 +0600 +++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj Mon Mar 17 01:20:15 2014 +0600 @@ -117,6 +117,21 @@ + + + + + + + + + + + + + + + @@ -351,6 +366,13 @@ + + + + + + + diff -r d65414f65bd4 -r 6fd03869f65c Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters --- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Sun Mar 16 19:34:51 2014 +0600 +++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Mon Mar 17 01:20:15 2014 +0600 @@ -64,6 +64,9 @@ {293e30b6-9ded-426f-a0be-425b0a877e93} + + {a768f30d-81a0-4858-a264-dd7120e64106} + @@ -336,6 +339,51 @@ + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + @@ -838,6 +886,27 @@ + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + + + lib\libpng + diff -r d65414f65bd4 -r 6fd03869f65c LOD.cpp --- a/LOD.cpp Sun Mar 16 19:34:51 2014 +0600 +++ b/LOD.cpp Mon Mar 17 01:20:15 2014 +0600 @@ -2817,8 +2817,6 @@ //LODFile_IconsBitmaps *v3; // esi@1 //unsigned int v4; // edi@1 //Texture *v5; // ebx@2 - unsigned int v6; // ebx@8 - const char *Sourcea; // [sp+14h] [bp+8h]@9 //v3 = this; //v4 = 0; @@ -2841,20 +2839,11 @@ }*/ if (LoadTextureFromLOD(&pTextures[uNumLoadedFiles], pContainer, uTextureType) == -1) { - v6 = 0; - if (uNumLoadedFiles > 0) + for ( uint i = 0; i < uNumLoadedFiles; ++i ) { - Sourcea = (const char *)pTextures; - while ( _stricmp(Sourcea, "pending") ) - { - Sourcea += 72; - ++v6; - if (v6 >= uNumLoadedFiles) - goto LABEL_15; - } - return v6; + if (!_stricmp(pTextures[i].pName, "pending")) + return i; } -LABEL_15: LoadTextureFromLOD(&pTextures[uNumLoadedFiles], "pending", uTextureType); } areWeLoadingTexture = 0; diff -r d65414f65bd4 -r 6fd03869f65c MMT.cpp --- a/MMT.cpp Sun Mar 16 19:34:51 2014 +0600 +++ b/MMT.cpp Mon Mar 17 01:20:15 2014 +0600 @@ -11,6 +11,7 @@ #include "VideoPlayer.h" #include "CShow.h" #include "GUIFont.h" +#include "lib/libpng/png.h" void ShowLogoVideo() { @@ -61,6 +62,96 @@ bGameoverLoop = 0; } +void abort_(const char * s, ...) +{ + va_list args; + va_start(args, s); + vfprintf(stderr, s, args); + fprintf(stderr, "\n"); + va_end(args); + abort(); +} + +Texture *ConvertPNG(const char *name) +{ + int x, y; + int width, height; + png_byte color_type; + png_byte bit_depth; + png_structp png_ptr; + png_infop info_ptr; + int number_of_passes; + png_bytep * row_pointers; + uint i = 0; + Texture *tex; + + char header[8]; // 8 is the maximum size that can be checked + + /* open file and test for it being a png */ + FILE *fp = fopen(name, "rb"); + if (!fp) + Log::Warning(L"[read_png_file] File %s could not be opened for reading", name); + fread(header, 1, 8, fp); + //if (png_sig_cmp(header, 0, 8)) + //Log::Warning(L"[read_png_file] File %s is not recognized as a PNG file", pContainerName); + /* initialize stuff */ + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + + if (!png_ptr) + abort_("[read_png_file] png_create_read_struct failed"); + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + abort_("[read_png_file] png_create_info_struct failed"); + + if (setjmp(png_jmpbuf(png_ptr))) + abort_("[read_png_file] Error during init_io"); + + png_init_io(png_ptr, fp); + png_set_sig_bytes(png_ptr, 8); + + png_read_info(png_ptr, info_ptr); + + width = png_get_image_width(png_ptr, info_ptr); + height = png_get_image_height(png_ptr, info_ptr); + color_type = png_get_color_type(png_ptr, info_ptr); + bit_depth = png_get_bit_depth(png_ptr, info_ptr); + + number_of_passes = png_set_interlace_handling(png_ptr); + png_read_update_info(png_ptr, info_ptr); + + + /* read file */ + if (setjmp(png_jmpbuf(png_ptr))) + abort_("[read_png_file] Error during read_image"); + + row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height); + for (y=0; yGetTexture(pIcons_LOD->FindTextureByName("Pending"));//не знаю как зачистить + tex->uTextureHeight = height; + tex->uTextureWidth = width; + tex->uSizeOfMaxLevelOfDetail = png_get_rowbytes(png_ptr, info_ptr); + tex->uTextureSize = png_get_rowbytes(png_ptr, info_ptr); + tex->uDecompressedSize = png_get_rowbytes(png_ptr, info_ptr); + + for (y=0; ypPalette16[i] = Color16(LOBYTE(pl), BYTE1(pl), BYTE2(pl)); + i++; + pl++; + } + } + return tex; +} + void MMT_MainMenu_Loop() { GUIButton *pButton; // eax@27 @@ -71,6 +162,9 @@ unsigned int pY; // [sp-18h] [bp-54h]@39 Texture *pTexture; // [sp-14h] [bp-50h]@39 GUIButton *pButton2; // [sp+0h] [bp-3Ch]@27 + char pContainerName[64]; + + pCurrentScreen = SCREEN_GAME; @@ -81,7 +175,12 @@ pIcons_LOD->_inlined_sub2(); pWindow_MMT_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0); - Texture* MMT_MM6 = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE); + //Texture* MMT_MM6 = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE); + + sprintf(pContainerName, "data\\New_Icons/%s", "mm6_button_oval.png"); + Texture* MMT_MM6 = ConvertPNG(pContainerName); + + Texture* MMT_MM7 = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE); Texture* MMT_MM8 = pIcons_LOD->LoadTexturePtr("title_cred", TEXTURE_16BIT_PALETTE); Texture* MMT_Continue = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE); @@ -95,8 +194,6 @@ pTexture_PCX.Release(); - char pContainerName[64]; - sprintf(pContainerName, "data\\New_Icons/%s", "MMTTITLE.pcx"); pTexture_PCX.LoadPCXFile(pContainerName, 0); SetCurrentMenuID(MENU_MMT_MAIN_MENU);