Texture Problem

Hi…I have a box moving in a 3D space…now i want to have a floor and walls for the box in the x-y , x-z, and the y-z planes. I want to load the image which i want have in the wall from a file.

I am trying to use textures for that but its not working. Does anyone have any idea ?


Note:Have you enabled the texture mapping in your program:
glEnable( GL_TEXTURE_2D );

OpenGL Game Programming has written some functions to load the pictures.Here’s a function to load a bitmap picture in RGB mode:

// LoadBitmapFile
// desc: Returns a pointer to the bitmap image of the bitmap specified
// by filename. Also returns the bitmap header information.
// No support for 8-bit bitmaps.
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
FILE *filePtr; // the file pointer
BITMAPFILEHEADER bitmapFileHeader; // bitmap file header
unsigned char *bitmapImage; // bitmap image data
int imageIdx = 0; // image index counter
unsigned char tempRGB; // swap variable

// open filename in "read binary" mode
filePtr = fopen(filename, "rb");
if (filePtr == NULL)
	return NULL;

// read the bitmap file header
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);

// verify that this is a bitmap by checking for the universal bitmap id
if (bitmapFileHeader.bfType != BITMAP_ID)
	return NULL;

// read the bitmap information header
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);

// move file pointer to beginning of bitmap data
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);

// allocate enough memory for the bitmap image data
bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);

// verify memory allocation
if (!bitmapImage)
	return NULL;

ow can you load a bitmap?First of all, you need to create a bmp file that its width and height is a power of 2. then use the following code to load the file:

unsigned char* bitmapData;

bitmapData = LoadBitmapFile( “yourFileName.bmp”, &bitmapInfoHeader );

Then in this example you can use from the bitmapInfoHeader and bitmapData in the function glTexImage2D:

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, bitmapInfoHeader.biWidth, bitmapInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapData );


thanks man…its working now :smiley:

You’r welcome.I’m so happy. Good Luck with your OpenGL projects:)