Jump to content
  • Advertisement
Sign in to follow this  
MadsGustaf

Problem loading bitmaps (Lesson #7)

This topic is 3944 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!