I have been using this function to load Bitmaps for Textures in my OpenGL applications, taken from NeHe's tutorial:
I'm now dealing with a resource bitmap though, and I need something to replace Texture[0] = LoadBMP("bitmap.bmp").Code:AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image { FILE *File=NULL; // File Handle if (!Filename) // Make Sure A Filename Was Given { return NULL; // If Not Return NULL } File=fopen(Filename,"r"); // Check To See If The File Exists if (File) // Does The File Exist? { fclose(File); // Close The Handle return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer } return NULL; // If Load Failed Return NULL }
I tried TextureImage[0] = auxDIBImageLoad(MAKEINTRESOURCE(IDB_BITMAP1), which compiles but the App crashes,
and TextureImage[0] = LoadImage(hInstance,MAKEINTRESOURCE(IDB_BITMAP1),I MAGE_BITMAP,0,0,LR_LOADFROMFILE);, where the compiler gives me a conversion error.
What could I use as a replacement?
Many people seen to be using this code to work with resources:
But I'm still new to programming, and I'm having trouble figuring out how that will help me assigning the .bmp to TextureImage[], as in the non-resource code:Code:void LoadGLTextures() { // load bitmap from resource file HBITMAP bitmap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP2)); // setup 24 bits bitmap structure // works on 8 bits bitmaps also! BITMAPINFO info; BITMAPINFOHEADER header; header.biSize = sizeof(BITMAPINFOHEADER); header.biWidth = 256; header.biHeight = 256; header.biPlanes = 1; header.biBitCount = 24; header.biCompression = BI_RGB; header.biSizeImage = 0; header.biClrUsed = 0; header.biClrImportant = 0; info.bmiHeader = header; info.bmiColors->rgbRed = NULL; info.bmiColors->rgbGreen = NULL; info.bmiColors->rgbBlue = NULL; info.bmiColors->rgbReserved = NULL; // store bitmap data in a vector const int size = 256*256*3; unsigned char data[size]; HDC hdc = GetDC(g_hWndRender); GetDIBits(hdc, bitmap, 0, 256, &data, &info, DIB_RGB_COLORS); ReleaseDC(g_hWndRender, hdc); // convert from BGR to RGB unsigned char buff; for(int i=0; i<256*256; i++) { buff = data[i*3]; if(i>=3) { data[i*3] = data[i*3+2]; data[i*3+2] = buff; } } // create one texture glGenTextures(1, &m_texture[0]); // select texture glBindTexture(GL_TEXTURE_2D, m_texture[0]); // SetTextureParameters // generate texture glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data); }
Code:AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture ... TextureImage[0] = LoadBMP("bitmap.bmp)



LinkBack URL
About LinkBacks


