HBITMAP TgaLoad (unsigned char *pauchData) { // // Load the image // int nWidth, nHeight; D3DCOLOR *pData = TgaLoad (pauchData, &nWidth, &nHeight); if (pData == NULL) return NULL; // // Initialize a DIB // BITMAPINFOHEADER BMI; BMI .biSize = sizeof (BITMAPINFOHEADER); BMI .biWidth = nWidth; BMI .biHeight = nHeight; BMI .biPlanes = 1; BMI .biBitCount = 32; BMI .biCompression = BI_RGB; BMI .biSizeImage = 0; BMI .biXPelsPerMeter = 0; BMI .biYPelsPerMeter = 0; BMI .biClrUsed = 0; BMI .biClrImportant = 0; // // Create DIB section in shared memory // COLORREF *pDstBits; CClientDC dc (::GetDesktopWindow ()); HBITMAP hbm = ::CreateDIBSection (dc, (BITMAPINFO *)&BMI, DIB_RGB_COLORS, (void **) &pDstBits, 0, 0l); if (hbm == NULL) return NULL; // // Convert // for (int i = 0; i < nWidth * nHeight; i++) { pDstBits [i] = RGB ( RGBA_GETRED (pData [i]), RGBA_GETGREEN (pData [i]), RGBA_GETBLUE (pData [i])); } delete [] pData; return hbm; }
D3DCOLOR *TgaLoad (UINT nID, int *pnWidth, int *pnHeight) { // // Find the template // HRSRC hRsrc = FindResource (_Module .GetResourceInstance (), MAKEINTRESOURCE (nID), _T ("TGA_INCLUDE")); if (hRsrc == NULL) return NULL; // // Write the resource // DWORD dwSize = ::SizeofResource (_Module .GetResourceInstance (), hRsrc); HGLOBAL hSource = ::LoadResource (_Module .GetResourceInstance (), hRsrc); LPVOID pSource = ::LockResource (hSource); D3DCOLOR *pTga = TgaLoad ((unsigned char *) pSource, pnWidth, pnHeight); UnlockResource (hSource); ::FreeResource (hSource); return pTga; }
GLuint LoadCubeTexture(const char* baseName) { TgaImage img; std::string base(baseName); GLuint texture; glVerify(glActiveTexture(GL_TEXTURE0)); glVerify(glEnable(GL_TEXTURE_CUBE_MAP)); glVerify(glGenTextures(1, &texture)); glVerify(glBindTexture(GL_TEXTURE_CUBE_MAP, texture)); glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE)); glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); glVerify(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)); if (TgaLoad((base + "_bk.tga").c_str(), img)) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data); if (TgaLoad((base + "_ft.tga").c_str(), img)) glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data); if (TgaLoad((base + "_lf.tga").c_str(), img)) glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data); if (TgaLoad((base + "_rt.tga").c_str(), img)) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data); if (TgaLoad((base + "_dn.tga").c_str(), img)) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data); if (TgaLoad((base + "_up.tga").c_str(), img)) glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, img.m_width, img.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data); //... glVerify(glDisable(GL_TEXTURE_CUBE_MAP)); return texture; }