PDA

View Full Version : texture mapping



monson
11-07-2000, 12:00 PM
I'm trying to texture map a sphere, at one point I used a 1440x720 bitmap (got a 16MB TNT2), it worked fine, but after a few tries all I got was a white texture!!
any idea why, later on I rebooted the sys and worked on it some more, and finally got it working again. Any idea why for a while I was getting all white instead of my texture?
I am using the same code as in: http://nehe.gamedev.net/tutorials/lesson18.asp
I suspected memory loss but I am freeing the texture buffer (as in the tutorial), does openGL free the enumerated textures automatically when the window is killed? if not how do I do that?
Thanks http://www.opengl.org/discussion_boards/ubb/smile.gif

Below is the code for loading the texture, the rest of the code is at the URL above.

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/Wall.bmp"))
{
Status=TRUE; // Set The Status To TRUE

glGenTextures(3, &texture[0]); // Create Three Textures

// Create Nearest Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

// Create Linear Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

// Create MipMapped Texture
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
}

if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}

free(TextureImage[0]); // Free The Image Structure
}

return Status; // Return The Status
}

DFrey
11-07-2000, 12:21 PM
The dimensions of the texture given to glTexImage2D must always be powers of 2. That is for a texture of dimensions (x,y), ln(x)/ln(2)=n and ln(y)/ln(2)=m where n and m are nonnegative integers.

monson
11-07-2000, 12:57 PM
how come it worked the 1st few times?
I am using a 512x256 texture now, just because it works faster but I found it weird that it the 1440x720 worked and then stopped working after a couple of times.
does openGL get rid of it's textures automatically when closing the window?

DFrey
11-07-2000, 01:00 PM
Could appeared to have worked with that size at first if you were only seeing the mip-mapped texture, since gluBuild2dMipmaps automatically scales the texture levels to have dimensions of powers of 2.

monson
11-07-2000, 02:52 PM
that must have been it!! Thanks for the help http://www.opengl.org/discussion_boards/ubb/smile.gif