Skip to main content
gamedev.net
🔒 Locked

Loading Textures

Started by NewGuy2003 Jan 27, 2003 at 10:27 AM 1 replies 450+ views
Original Post
NewGuy2003
NewGuy2003
Hi all, I have a question about loading textures. I am unable to use the glaux.lib file posted with the bcb6 tutorial code so I had to find another function for loading the bitmap, I found this function somewhere on the net //======= int LoadBitmap(const char *lpFileSz, unsigned int *lpWidth, unsigned int *lpHeight, unsigned char *lpDataSz) { // validate the args if (!lpFileSz || !lpWidth || !lpHeight) { return 0; } // open the file ifstream fBMapFile(lpFileSz, ios::binary); // validate the file if (!fBMapFile.is_open()) { return 0; } // bitmap structures BITMAPFILEHEADER BmpFile; BITMAPINFOHEADER BmpInfo; // check for eof if (fBMapFile.eof()) { fBMapFile.close(); return 0; } // read the bitmap file header fBMapFile.read((char*)&BmpFile, sizeof(BITMAPFILEHEADER)); // validate file type if (BmpFile.bfType != 0x4d42) { fBMapFile.close(); return 0; } // check for eof if (fBMapFile.eof()) { fBMapFile.close(); return 0; } // read the bitmap info header fBMapFile.read((char*)&BmpInfo, sizeof(BITMAPINFOHEADER)); // allocate memory for the bitmap lpDataSz = new unsigned char[(BmpInfo.biWidth * BmpInfo.biHeight * 4)]; // validate the memory if (!lpDataSz) { fBMapFile.close(); return 0; } // preset the memory memset(lpDataSz, 0, (BmpInfo.biWidth * BmpInfo.biHeight * 4)); // now load the pixel data RGBTRIPLE rgbPixel; for (int i = 0, j = (BmpInfo.biWidth * BmpInfo.biHeight); i < j; i += 4) { // check for eof if (fBMapFile.eof()) { fBMapFile.close(); return 0; } // read in the pixel data fBMapFile.read((char*)&rgbPixel, sizeof(RGBTRIPLE)); // store the pixel and add the alpha color lpDataSz[i + 0] = rgbPixel.rgbtRed; lpDataSz[i + 1] = rgbPixel.rgbtGreen; lpDataSz[i + 2] = rgbPixel.rgbtBlue; lpDataSz[i + 3] = 255; } // close the file fBMapFile.close(); // save the width and height *lpWidth = BmpInfo.biWidth; *lpHeight = BmpInfo.biHeight; // return success return 1; } //======= and I am trying to use it like this (texture[0] is defined elsewhere) unsigned int Width, Height; unsigned char *lpDataSz; LoadBitmap("NeHe.bmp", &Width, &Height, lpDataSz); glGenTextures(1, &texture[0]);glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 4, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, lpDataSz); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); can anyone see the problem here?
New User
Grog
Grog
Why can''t you use the glaux file? Just use the one that comes with vc++.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.