bool AUX_RGBImageRec::loadFile(const char* Filename)
        BITMAPINFO BMInfo;                                                              // need the current OpenGL device contexts in order to make use of windows DIB utilities  
        const HDC gldc = wglGetCurrentDC();                     // a handle for the current OpenGL Device Contexts
                                                                                                        // assume there are errors until file is loaded successfully into memory  
        NoErrors = false;                                                               // release old data since this object could be used to load multiple Textures  
        if(data != NULL) delete data;                                   // windows needs this info to determine what header info we are looking for  
        BMInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);  // Get windows to determine color bit depth in the file for us  
        BMInfo.bmiHeader.biBitCount = 0;                                // Get windows to open and load the BMP file and handle the messy decompression if the file is compressed  
                                                                                                        // assume perfect world and no errors in reading file, Ha Ha  
        HANDLE DIBHandle = LoadImage(0,Filename, IMAGE_BITMAP, 0, 0,LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE);  // use windows to get header info of bitmap - assume no errors in header format

        GetDIBits(gldc, (HBITMAP)DIBHandle, 0,0, NULL, &BMInfo, DIB_RGB_COLORS);
        sizeX = BMInfo.bmiHeader.biWidth;
        sizeY = BMInfo.bmiHeader.biHeight;                              // change color depth to 24 bits (3 bytes (BGR) / pixel)  
        BMInfo.bmiHeader.biBitCount = 24;                               // don't want the data compressed  
        BMInfo.bmiHeader.biCompression = BI_RGB;  
        const DWORD BitmapLength = sizeX * sizeY * 3;   // 3 bytes (BGR) per pixel (24bp)  
                                                                                                        // allocate enough memory to hold the pixel data in client memory  
        data = new byte[BitmapLength];                                  // Get windows to do the dirty work of converting the BMP into the format needed by OpenGL  
                                                                                                        // if file is already 24 bit color then this is a waste of time but makes for short code  
                                                                                                        // Get the actual Texel data from the BMP object  
        if (GetDIBits(gldc, (HBITMAP)DIBHandle, 0, sizeY, data, &BMInfo, DIB_RGB_COLORS))
                NoErrors = true;
                convertBGRtoRGB();                                                      // NOTE: BMP is in BGR format but OpenGL needs RGB unless you use GL_BGR_EXT

        DeleteObject(DIBHandle);                                                // don't need the BMP Object anymore  
        return NoErrors;
auxDIBImageLoad(const char *FileName)函数调用了windows的系统函数LoadImage来看
    HANDLE WINAPI LoadImage(
      _In_opt_  HINSTANCE hinst,
      _In_      LPCTSTR lpszName,
          _In_      UINT uType,
      _In_      int cxDesired,
      _In_      int cyDesired,
      _In_      UINT fuLoad
      lpszName [in]
    Type: LPCTSTR
    The image to be loaded. If the hinst parameter is non-NULL and the fuLoad parameter omits LR_LOADFROMFILE, lpszName specifies the image resource in the hinst module. If the image resource is to be loaded by name from the module, the lpszName parameter is a pointer to a null-terminated string that contains the name of the image resource. If the image resource is to be loaded by ordinal from the module, use the MAKEINTRESOURCE macro to convert the image ordinal into a form that can be passed to the LoadImage function. For more information, see the Remarks section below.

    If the hinst parameter is NULL and the fuLoad parameter omits the LR_LOADFROMFILE value, the lpszName specifies the OEM image to load. The OEM image identifiers are defined in Winuser.h and have the following prefixes.
文章标签: OpenGL bmp
个人分类: 图形图像
想对作者说点什么? 我来说一句