Advertisement

Problem loading bitmaps (Lesson #7)

Started by December 30, 2007 07:16 PM
-1 comments, last by MadsGustaf 16 years, 10 months ago
Hello! Having shamelessly stolen the code for mipmapping from Lesson #7, i seem to have a problem loading certain bitmaps. Most of the bitmaps i can load, but some seem to give me "acces violation". Here is the code i am using:
[source langg = "cpp"]
AUX_RGBImageRec *LoadBMP(char *Filename)					// Loads A Bitmap Image
{
	FILE *File=NULL;
	if (!Filename)								// Make Sure A Filename Was Given
	{
		return NULL;							// If Not Return NULL
	}
	File=fopen(Filename,"r");	
	if (File)								// Does The File Exist?
	{
		fclose(File);							// Close The Handle
		return auxDIBImageLoad(Filename);				// Load The Bitmap And Return A Pointer
	}
		return NULL;								// If Load Failed Return NULL
}
int LoadGLTextures()
{
 int status = FALSE;
 AUX_RGBImageRec* TextureImage[1];
 
 memset(TextureImage,0,sizeof(void *)*1);
 if(TextureImage[0] = LoadBMP("Images/OneBit5.bmp"))
 {
  status = TRUE;
  glGenTextures(1,&texture[0]);
 
  glBindTexture(GL_TEXTURE_2D, texture[0]);

		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,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;
}

Not sure it is important, but this is how i draw:
[source langg = "cpp"]
int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();	
	glTranslatef(0.0f,0.1f,-5.0f);	
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glBegin(GL_QUADS);					
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.5f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.5f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.5f,  1.5f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.5f,  1.5f,  1.0f);	
    glEnd();	
	return TRUE;										
}

Thanks in advance!
•°*”˜˜”*°•.˜”*°•..•°*”˜.•°*”˜˜”*°•..•°*”˜˜”*°•.˜”*°•.˜”*°•. Mads .•°*”˜.•°*”˜.•°*”˜˜”*°•.˜”*°•..•°*”˜.•°*”˜.•°*”˜ ˜”*°•.˜”*°•.˜”*°•..•°*”˜I am going to live forever... or die trying!

This topic is closed to new replies.

Advertisement