如何从纯资源dll中载入位图,作为opengl的纹理?


auxDIBImageLoad() 只能从硬盘中载入bmp,有什么方法可以从纯资源dll中载入bmp到AUX_RGBImageRec吗?我自己尝试写了一段代码,但是失败了,代码如下

AUX_RGBImageRec *LoadBMP(char *Filename)
{
BITMAPINFO BMInfo;
const HDC gldc = wglGetCurrentDC();


 AUX_RGBImageRec *TextureImage = new AUX_RGBImageRec;
HINSTANCE hDll;
hDll = LoadLibrary("Resource.dll");
HBITMAP hBitmap = LoadBitmap(hDll, Filename);

BMInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
BMInfo.bmiHeader.biBitCount = 0;
GetDIBits(gldc, (HBITMAP)hBitmap, 0,0, NULL, &BMInfo, DIB_RGB_COLORS);
TextureImage->sizeX = BMInfo.bmiHeader.biWidth;
TextureImage->sizeY = BMInfo.bmiHeader.biHeight;
BMInfo.bmiHeader.biBitCount = 24; 
BMInfo.bmiHeader.biCompression = BI_RGB;

const DWORD BitmapLength = TextureImage->sizeX * TextureImage->sizeY * 3;
TextureImage->data = new byte[BitmapLength];

free(hDll);

return TextureImage;

}

opengl

Mr.朋友卡 10 years, 4 months ago

 AUX_RGBImageRec *LoadBMP(char *Filename)                
{
BITMAPINFO BMInfo;
const HDC gldc = wglGetCurrentDC();
int i;

AUX_RGBImageRec *TextureImage = new AUX_RGBImageRec;
HINSTANCE hDll;
hDll = LoadLibrary("Resource.dll");

HBITMAP hBitmap = LoadBitmap(hDll, "#105");

BMInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
BMInfo.bmiHeader.biBitCount = 0;
GetDIBits(gldc, (HBITMAP)hBitmap, 0,0, NULL, &BMInfo, DIB_RGB_COLORS);
TextureImage->sizeX = BMInfo.bmiHeader.biWidth;
TextureImage->sizeY = BMInfo.bmiHeader.biHeight;
BMInfo.bmiHeader.biBitCount = 24; 
BMInfo.bmiHeader.biCompression = BI_RGB;

const DWORD BitmapLength = TextureImage->sizeX * TextureImage->sizeY * 3;
TextureImage->data = new byte[BitmapLength];
memset(TextureImage->data,0,sizeof(byte)*BitmapLength);
if(GetDIBits(gldc, (HBITMAP)hBitmap, 0, TextureImage->sizeY, TextureImage->data, &BMInfo, DIB_RGB_COLORS))
    for(i=0; i<=BitmapLength; i+=3)
    {
        char tmp;
        tmp = TextureImage->data[i];
        TextureImage->data[i] = TextureImage->data[i+2];
        TextureImage->data[i+2] = tmp;
    }
FreeLibrary(hDll);
return TextureImage;

}

int LoadGLTextures()                                    // Load Bitmaps And Convert To Textures
{
int Status=FALSE;                                   // Status Indicator

AUX_RGBImageRec *TextureImage[1];                   // Create Storage Space For The Texture

memset(TextureImage,0,sizeof(void *)*1);            // Set The Pointer To NULL

// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
{

    Status=TRUE;                                    // Set The Status To TRUE

    glGenTextures(1, &texture[0]);                  // Create The Texture

    // Typical Texture Generation Using Data From The Bitmap
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}

return Status;                                      // Return The Status
}

hitoha answered 10 years, 4 months ago

Your Answer