bool Texture::Load() { if(m_FromCache) return LoadFromCache(); else { return LoadFromPNG(); //other formats } }
/** * * CTexture class Initialise * * @author Christopher Howlett * @param _pRenderer OpenGLRenderer * @param _pcFilename texture filename * @param _uiTextureUnit Texture ID * */ bool Texture::Initialise( const char* _pcFilename, unsigned int _uiTextureUnit ) { bool bResult = true; int iFilenameLength = strlen(_pcFilename); //TGA if (_pcFilename[iFilenameLength - 3] == 't' && _pcFilename[iFilenameLength - 2] == 'g' && _pcFilename[iFilenameLength - 1] == 'a') { bResult = LoadFromTarga( _pcFilename, _uiTextureUnit); } //PNG else if (_pcFilename[iFilenameLength - 3] == 'p' && _pcFilename[iFilenameLength - 2] == 'n' && _pcFilename[iFilenameLength - 1] == 'g') { bResult = LoadFromPNG( _pcFilename, _uiTextureUnit); } return bResult; }
Texture::Texture(const char* file_path) { if (!LoadFromPNG(file_path)) { LOGE("Texture initialing error"); } }
// // HBITMAP LoadLSImage(LPCSTR pszImage, LPCSTR pszFile) // // Takes strings of the form: // File.bmp // .extract // .extract=file.exe[,3] HBITMAP LoadLSImage(LPCSTR pszImage, LPCSTR pszFile) { HBITMAP hbmReturn = NULL; if (pszImage != NULL) { if (_stricmp(pszImage, ".none") != 0) { char szImage[MAX_PATH]; StringCchCopy(szImage, MAX_PATH, pszImage); // Bitmap merging by Thedd // Thedd - pic1.bmp|pic2.bmp merges the images. Works recursively, // so pic1.bmp|.extract=whatever.dll,3|pic2.bmp also works etc... // bitmap merging by grd LPSTR pszSecondImage = strchr(szImage, '|'); if (pszSecondImage) { HDC hdcFirst, hdcSecond, hdcResult; HBITMAP hbmFirst, hbmFirstOld; HBITMAP hbmSecond, hbmSecondOld; HBITMAP hbmResult, hbmResultOld; HBRUSH hbrTransparent; RECT rc; int wdtFirst, hgtFirst; int wdtSecond, hgtSecond; int wdtResult, hgtResult; // get the position after the [|] character *pszSecondImage = '\0'; ++pszSecondImage; // load the two bitmaps hbmFirst = LoadLSImage(szImage, pszFile); hbmSecond = LoadLSImage(pszSecondImage, pszFile); // if the second one is NULL, then there's no merging to do and if (hbmSecond != NULL) { // create mem dcs for the bitmaps hdcFirst = CreateCompatibleDC(NULL); hdcSecond = CreateCompatibleDC(NULL); // select the bitmaps hbmFirstOld = (HBITMAP)SelectObject(hdcFirst, hbmFirst); hbmSecondOld = (HBITMAP)SelectObject(hdcSecond, hbmSecond); // get the bitmap sizes.. GetLSBitmapSize(hbmFirst, &wdtFirst, &hgtFirst); GetLSBitmapSize(hbmSecond, &wdtSecond, &hgtSecond); // in earlier version of bitmap merge, those were painted on // to each other now let's paint both images to a new one // and we support different sized images!! therefore: wdtResult = std::max(wdtFirst, wdtSecond); hgtResult = std::max(hgtFirst, hgtSecond); // create another dc, compatible with second dc hdcResult = CreateCompatibleDC(hdcSecond); // create a new bitmap for the new dc and select it hbmResult = CreateCompatibleBitmap(hdcSecond, wdtResult, hgtResult); hbmResultOld = (HBITMAP)SelectObject(hdcResult, hbmResult); rc.top = 0; rc.left = 0; rc.right = wdtResult; rc.bottom = hgtResult; // paint the background in transparent color... hbrTransparent = CreateSolidBrush(RGB(255, 0, 255)); FillRect(hdcResult, &rc, hbrTransparent); DeleteObject(hbrTransparent); // first "standard blit" the second image into the new one: BitBlt(hdcResult, (wdtResult - wdtSecond) / 2, (hgtResult - hgtSecond) / 2, wdtSecond, hgtSecond, hdcSecond, 0, 0, SRCCOPY); // Secondly "tranparent blit" the first image over the // second one Since TransparentBltLS double buffers the // painting to reduce flicker and we are using only memory // DC's in this function, we will just call // TransparentBltLSWorker and shave off a few BitBlt calls TransparentBltLSWorker(hdcResult, wdtFirst, hgtFirst, hdcFirst, 0, 0, RGB(255, 0, 255)); // deselect the bitmap from the dc and delete the dc to get // the image SelectObject(hdcResult, hbmResultOld); DeleteDC(hdcResult); // delete all used objects SelectObject(hdcFirst, hbmFirstOld); DeleteObject(hbmFirst); DeleteDC(hdcFirst); SelectObject(hdcSecond, hbmSecondOld); DeleteObject(hbmSecond); DeleteDC(hdcSecond); hbmReturn = hbmResult; } else { hbmReturn = hbmFirst; } } else { if (!_strnicmp(szImage, ".extract", 8 /*strlen(".extract")*/)) { HICON hIcon = NULL; hIcon = LoadLSIcon(szImage, pszFile); if (hIcon) { hbmReturn = BitmapFromIcon(hIcon); DestroyIcon(hIcon); } } else { // Append the image name to the LiteStep image path and // attempt to load the image. char szExpandedImage[MAX_PATH]; VarExpansionEx(szExpandedImage, szImage, MAX_PATH); LSGetImagePath(szImage, MAX_PATH); PathAppend(szImage, szExpandedImage); if (PathMatchSpec(szImage, "*.png")) { hbmReturn = LoadFromPNG(szImage); } else { hbmReturn = (HBITMAP)LoadImage( NULL, szImage, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE); } // If that fails, treat the image as a fully qualified path // and try loading it if (hbmReturn == NULL) { if (PathMatchSpec(szExpandedImage, "*.png")) { hbmReturn = LoadFromPNG(szExpandedImage); } else { hbmReturn = (HBITMAP)LoadImage( NULL, szExpandedImage, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE); } } } } } } return hbmReturn; }