void CBaikuDemoApp::LoadTheme() { CString strPicPath = _T(""); CString strThemePath = GetAppResPath(); CBitmap* pBitmap = NULL; CBitmap* pBgBitmap = NULL; Image* pMinBtnImage = NULL; Image* pMaxBtnImage = NULL; Image* pCloseBtnImage = NULL; Image* pRestoreBtnImage = NULL; m_pTheme = new ThemeDialog(); strPicPath = strThemePath + _T("\\dialog.bmp"); pBitmap = LoadBmpImage(strPicPath); strPicPath = strThemePath + _T("\\background.bmp"); pBgBitmap = LoadBmpImage(strPicPath); strPicPath = strThemePath + _T("\\max_btn_dlg.png"); pMaxBtnImage = LoadPngImage(strPicPath); strPicPath = strThemePath + _T("\\min_btn_dlg.png"); pMinBtnImage = LoadPngImage(strPicPath); strPicPath = strThemePath + _T("\\close_btn_dlg.png"); pCloseBtnImage = LoadPngImage(strPicPath); strPicPath = strThemePath + _T("\\restore_btn_dlg.png"); pRestoreBtnImage = LoadPngImage(strPicPath); m_pTheme->SetBorder(pBitmap, pBitmap); m_pTheme->SetBackground(pBgBitmap); m_pTheme->SetMargins(3, 3, 3, 3, 3, 3, 27, 3); m_pTheme->SetMinButton(1, CPoint(45, 6), pMinBtnImage); m_pTheme->SetMaxButton(1, CPoint(25, 6), pMaxBtnImage, pRestoreBtnImage); m_pTheme->SetCloseButton(1, CPoint(5, 6), pCloseBtnImage); }
BOOL CLoginDlg::OnInitDialog() { QnSkinDialog::OnInitDialog(); CString strPath = theApp.GetAppResPath() + _T("\\login_bg.bmp"); m_pBmpLoginBg = LoadBmpImage(strPath); if (m_pBmpLoginBg) { // 创建绘制的背景的DC CreateQnDC(m_pBmpLoginBg, true); } return TRUE; }
//-------------------------------------------------------------------------- /// \brief This function loads the specified image file and returns the /// openGL texture object for it. Only tga, bmp and pcx images are /// supported. /// \param filename - the image file to use for the texture /// \return compressed - if true DXT compression will be used. /// unsigned int LoadTexture(const char* filename,bool compressed, bool makeMips, int *outWidth, int *outHeight) { #ifndef _WIN32 // #if MACINTOSH // This is a HACK for the Mac version which has some directory trouble. // This hardcoded path should be fixed soon to something more flexible. char buffer[1000]; const char *currentDirectory = getcwd( buffer, 1000); // // printf("Texture Directorily: %s\n",currentDirectory); // // char *strstr = strFind(currentDirectory,"build"); // const char *substring = strstr(currentDirectory, "build"); // printf("substring: %s\n", substring); // chdir(currentDirectory); // chdir("/Users/puck 1/Desktop/trunk/BrainMobile/runtime"); // chdir("/Users/SPL/Desktop/DWDT/dwd/BrainMobile/runtime"); chdir("/Applications/DWD/dwd/BrainMobile/runtime"); #endif // check to see if file is already loaded. std::map<std::string,TexRef>::iterator it = g_Textures.find(filename); if ( it!=g_Textures.end()) { it->second.ref++; return it->second.idx; } // if not, try to load the file. unsigned int w=0,h=0,bpp=0; unsigned char* pixels=0; int len = static_cast<int>(strlen(filename)); // load a bmp if( (filename[len-3] == 'b' || filename[len-3] == 'B') && (filename[len-2] == 'm' || filename[len-2] == 'M') && (filename[len-1] == 'p' || filename[len-1] == 'P') ) { if(!LoadBmpImage(filename,&pixels,&w,&h,&bpp)) return 0; } else // load a pcx if( (filename[len-3] == 'p' || filename[len-3] == 'P') && (filename[len-2] == 'c' || filename[len-2] == 'C') && (filename[len-1] == 'x' || filename[len-1] == 'X') ) { if(!LoadPcxImage(filename,&pixels,&w,&h,&bpp)) return 0; } else // load a tga if( (filename[len-3] == 't' || filename[len-3] == 'T') && (filename[len-2] == 'g' || filename[len-2] == 'G') && (filename[len-1] == 'a' || filename[len-1] == 'A') ) { if(!LoadTgaImage(filename,&pixels,&w,&h,&bpp)) return 0; } else { std::cerr << "Unsupported image format\n"; return 0; } // generat the correct texture type for the image unsigned int tex_object; switch(bpp) { case 1: tex_object = MakeGlTexture(GL_ALPHA,pixels,w,h,compressed, makeMips); break; case 2: break; case 3: tex_object = MakeGlTexture(GL_RGB,pixels,w,h,compressed, makeMips); break; case 4: tex_object = MakeGlTexture(GL_RGBA,pixels,w,h,compressed, makeMips); break; default: break; } int data_size=0; if(compressed) { glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,&data_size); } else { data_size = bpp*w*h; } // delete the pixel data because we no longer need it free(pixels); // insert the texture into a map to keep track of it g_Textures.insert( std::make_pair( std::string(filename), TexRef(tex_object,data_size) ) ); if (outWidth != NULL) *outWidth = w; if (outHeight != NULL) *outHeight = h; // return GL texture object return tex_object; }
//-------------------------------------------------------------------------- /// \brief This function loads the specified image file and returns the /// openGL texture object for it. Only tga, bmp and pcx images are /// supported. /// \param filename - the image file to use for the texture /// \return compressed - if true DXT compression will be used. /// unsigned int LoadTexture(const char* filename,bool compressed) { // check to see if file is already loaded. std::map<std::string,TexRef>::iterator it = g_Textures.find(filename); if ( it!=g_Textures.end()) { it->second.ref++; return it->second.idx; } // if not, try to load the file. unsigned int w=0,h=0,bpp=0; unsigned char* pixels=0; int len = static_cast<int>(strlen(filename)); // load a bmp if( (filename[len-3] == 'b' || filename[len-3] == 'B') && (filename[len-2] == 'm' || filename[len-2] == 'M') && (filename[len-1] == 'p' || filename[len-1] == 'P') ) { if(!LoadBmpImage(filename,&pixels,&w,&h,&bpp)) return 0; } else // load a pcx if( (filename[len-3] == 'p' || filename[len-3] == 'P') && (filename[len-2] == 'c' || filename[len-2] == 'C') && (filename[len-1] == 'x' || filename[len-1] == 'X') ) { if(!LoadPcxImage(filename,&pixels,&w,&h,&bpp)) return 0; } else // load a tga if( (filename[len-3] == 't' || filename[len-3] == 'T') && (filename[len-2] == 'g' || filename[len-2] == 'G') && (filename[len-1] == 'a' || filename[len-1] == 'A') ) { if(!LoadTgaImage(filename,&pixels,&w,&h,&bpp)) return 0; } else { std::cerr << "Unsupported image format\n"; return 0; } // generat the correct texture type for the image unsigned int tex_object; switch(bpp) { case 1: tex_object = MakeGlTexture(GL_ALPHA,pixels,w,h,compressed); break; case 2: break; case 3: tex_object = MakeGlTexture(GL_RGB,pixels,w,h,compressed); break; case 4: tex_object = MakeGlTexture(GL_RGBA,pixels,w,h,compressed); break; default: break; } int data_size=0; if(compressed) { glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,&data_size); } else { data_size = bpp*w*h; } // delete the pixel data because we no longer need it free(pixels); // insert the texture into a map to keep track of it g_Textures.insert( std::make_pair( std::string(filename), TexRef(tex_object,data_size) ) ); // return GL texture object return tex_object; }