///////////////////////////////////////////////////////////////////////////////////////////////
//CreateTexture()
///////////////////////////////////////////////////////////////////////////////////////////////
int CreateTexture(char *Filename)
{
BITMAPFILEHEADER FileHeader;
BITMAPINFOHEADER InfoHeader;
HANDLE hFile;
unsigned char *ImageBuffer;
unsigned char tempRGB;
unsigned int texture;
unsigned long BytesRead;
int width;
int height;
int bpp;
hFile = CreateFile(Filename,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,0);
if(hFile == INVALID_HANDLE_VALUE) MessageBox(NULL,"Could not open file","error",MB_OK);
ReadFile(hFile,&FileHeader,sizeof(BITMAPFILEHEADER),&BytesRead,NULL);
ReadFile(hFile,&InfoHeader,sizeof(BITMAPINFOHEADER),&BytesRead,NULL);
width = InfoHeader.biWidth;
height = InfoHeader.biHeight;
bpp = InfoHeader.biBitCount;
ImageBuffer = new unsigned char[width*height*bpp/8];
ReadFile(hFile,ImageBuffer,sizeof(ImageBuffer),&BytesRead,NULL);
for (int loop = 0; loop < sizeof(ImageBuffer); loop+=3)
{
tempRGB = ImageBuffer[loop];
ImageBuffer[loop] = ImageBuffer[loop + 2];
ImageBuffer[loop + 2] = tempRGB;
}
CloseHandle(hFile);
glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_2D,texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,ImageBuffer);
delete [] ImageBuffer;
return texture;
}
this code may be dead wrong,if so i hope you guys tell me
thanks in advance
Edited by - Lode Runner on January 28, 2002 11:28:55 PM
Edited by - Lode Runner on January 28, 2002 11:31:23 PM
BMP Texture problem
Hi.
Im trying to Load a BMP file and turn it into a texture,
i dont realy know what im doing
anyway when i map the texture to a polygon all that shows up are 1 pixel in the lowerleft corner.
heres some code:
1 - You can''t use sizeof to determine the size of an array. You will need to store the size in a int and use that number. The current code probably only reads 4 bytes, hence the single pixel.
2 - Bitmaps come in several different flavors. You need to make sure you are only using one kind or check for the correct version. I assume you are only using 24bpp, but make sure.
The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran
Opere Citato
2 - Bitmaps come in several different flavors. You need to make sure you are only using one kind or check for the correct version. I assume you are only using 24bpp, but make sure.
The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran
Opere Citato
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement