Binding a texture in a class

Im trying to bind a texture to a Quadrilateral in a class Quad

ive used a fair chunk of code from Nehe’s Tutorial 7, but i cant get it to apply the texture.

The vertice drawing code works and allows textured polygons, however this code makes the quad white all over, as if i hadnt enabled GL_TEXTURE_2D.

I cant figure out why it isnt working, all the correct lines execute, ive stepped through it with a debugger, the file exists and the line ive used to call the function is

CQuad Q;
Q.ApplyTexture(“crate.bmp”);

then later

Q.Draw(Offset);

//Apply A Bitmap File Texture to a polygon
void CQuad::ApplyTexture(const char *cpInput)
{
//If so, calculate Texture Doodads. ( i dont understand how it works)
//Do We Have a texture?
if(cpInput) //yes we have a texture
{
//Check that it exists.
fstream TexFile(cpInput, ios::in | ios:: binary);
ASSERT(TexFile);
TexFile.close();

  cpTextureFile = new char[strlen(cpInput)+1];
  //copy strings (to <- from)
  strcpy(cpTextureFile, cpInput);

}
else //We Dont have a texture
{
cpTextureFile = 0;
bIsTextured = false;
return;
}

if (strlen(cpInput)) //Is a non null string
{
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
//Yes We Are Texxing
bIsTextured = true;
//GL Texture Info
AUX_RGBImageRec *TextureImage;

  // Load The Bitmap
  TextureImage=auxDIBImageLoad(cpInput);
  glGenTextures(1, &texture);					// Create Texture

  // Create Nearest mipmapped 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_MIPMAP_LINEAR);
  gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage->sizeX, TextureImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data);

  delete TextureImage->data;				// Free The Texture Image Memory
  delete TextureImage;						// Free The Image Structure

}
}

//Draws the Quad using OpenGL
//if a texture is specified, enable texturing
void CQuad: raw(CPosition CDrawOrigin)
{

if (bIsTextured)
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
else
glDisable(GL_TEXTURE_2D); //No Texture for you.

glBegin(GL_QUADS);
//Vertex 1 of 4
if(bIsTextured)
glTexCoord2f(0.0f, 0.0f); // Bottom Left Of The Texture
CVertice[0].Draw(CDrawOrigin, bIsTextured);

  //Vertex 2 of 4
  	if(bIsTextured)
		glTexCoord2f(1.0f, 0.0f); // Bottom Right Of The Texture
  CVertice[1].Draw(CDrawOrigin, bIsTextured);
  
  	//Vertex 3 of 4        
	if(bIsTextured)
      glTexCoord2f(1.0f, 1.0f);	// Top Right Of The Texture
  	CVertice[2].Draw(CDrawOrigin, bIsTextured);
    
    //Vertex 4 of 4        
  if(bIsTextured)
      	glTexCoord2f(0.0f, 1.0f);	// Top Left Of The Texture 
  	CVertice[3].Draw(CDrawOrigin, bIsTextured);

glEnd();
}

Hi!
Make sure auxDIBImageLoad(…) doesn’t return 0.
One more thing is you probably wanted to have:
delete[] TextureImage->data;
in your code, rather than:
delete TextureImage->data;
…but it’s not white texture related

What causes auxDIBImageLoad to return 0?

Usually loaders return 0 in case loading failed, auxDIBImageLoad is probably the same about returned values.

[This message has been edited by MickeyMouse (edited 12-12-2002).]

I just noticed that it is not always solid white

it is solid whatever i put in the call to glColour4f(…)

Figured it out, i was calling ApplyTexture before i had properly initialised the window. stupid me

In other words, you didn’t have an active render context. Without one of those, most OpenGL functions will simply fail quietly.