• Advertisement

Archived

This topic is now archived and is closed to further replies.

Loading masses of bmps

This topic is 5807 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

This question asssumes that I am loading the bitmaps using these two functions:
  
AUX_RGBImageRec *loadbmp(char *filename)
{
  FILE *file = NULL;

  if (!filename)
    return NULL;

  file = fopen(filename, "r");

  if (file)
  {
    fclose(file);
    return auxDIBImageLoad(filename);
  }

  return NULL;
}



int load_gl_textures()
{
  AUX_RGBImageRec *TextureImage[numtextures];

  memset(TextureImage,0,sizeof(void *)*1);

  TextureImage[0] = loadbmp("data\\tile.bmp");
  TextureImage[1] = loadbmp("data\\tile2.bmp");
  TextureImage[2] = loadbmp("data\\bkg.bmp");
  TextureImage[3] = loadbmp("data\\sprite.bmp");
  TextureImage[4] = loadbmp("data\\spritemask.bmp");
  TextureImage[5] = loadbmp("data\\sprite2.bmp");
  TextureImage[6] = loadbmp("data\\spritemask2.bmp");
  TextureImage[7] = loadbmp("data\\sprite3.bmp");
  TextureImage[8] = loadbmp("data\\spritemask3.bmp");
  TextureImage[9] = loadbmp("data\\sprite4.bmp");
  TextureImage[10] = loadbmp("data\\spritemask4.bmp");


  glGenTextures(numtextures, &texture[0]);

  for (int a=0; a<numtextures; a++)
  {
	glBindTexture(GL_TEXTURE_2D, texture[a]);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[a]->sizeX,
               TextureImage[a]->sizeY, 0, GL_RGB,
               GL_UNSIGNED_BYTE, TextureImage[a]->data);

  }

	for (int t = 0; t < numtextures; t++)
	{
		if (TextureImage[t])
		{
		if (TextureImage[t]->data)
		{
			free(TextureImage[t]->data);
		}

		free(TextureImage[t]);
		}
	}

  return(1);
}
  
numtextures is a const int declared as the total number of textures. My question is, if I load masses of bitmaps using these functions, will all the RAM on the computer it is running on be taken up? Well, I mean, ram equivalent to the size of all the bmp''s combined. I guess my main question is should I only load the bmp''s i need each scene, or should I load them all at once when the game is loaded up? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
1) Don''t use GLaux!
2) Load what you can get away with. In other words: if all the bitmaps you''ll need before you get another chance to load more bitmaps fit in memory, load them now. If they don''t, well you''ll have to come up with a more advanced scheme. Don''t load anything that you can delay until another loading session.

Share this post


Link to post
Share on other sites
1) why not use glaux? its a simple way for me to load sprites, as my sprites are 64x64 anyways. I''d rather not mess with pointers.
2) So load it all at once? I mean, I''ll end up loading a heck of a lot of sprites and backgrounds and tiles. When the window closes, will it free up the ram?

Share this post


Link to post
Share on other sites
You''ll be responsible for freeing any RAM you allocate explicitly.

Just to be safe, I like to explicitly destroy the OpenGL textures too. It''s probably not safe to depend on the ending program and the detaching OpenGL instance to do everything.

As far as system RAM goes, if you didn''t allocate it for storage, you don''t have to free it.

Share this post


Link to post
Share on other sites
I didn't say that, I can't speak from experience, yet

But it seems to me it should be.

You could test by running the program over and over and see if it affects available resources, I suppose.

Best of luck!

[edited by - Waverider on May 31, 2002 6:13:22 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by tarun713
1) why not use glaux?


Several reasons...the first that comes to mind is "why use the entire library for one function?" Second, it''s not exactly the best or fastest code (not that I''ve looked at the source, but thats what people say). Last, I personally like to write my own code, etc so I know how exactly how it runs.




"Dammit! What the friggin hell is the problem????"
"Wait a second! I never called [insert function here]/used the variable [insert variable here]/remembered to [insert action here]! Hahaha!"
:: fixes mistake ::
:: presses f7 ::
:: no errors ::
:: presses ctrl+f5 ::
"DOH!"

Share this post


Link to post
Share on other sites
quote:
1) why not use glaux?


If I remember right glaux is a library that no longer is updated and is only shipped with the compilers for backward compatible reasons. Because of that the code is old and may not take advantage of newer opengl functions. Because of that, the code probably ( as Neosmyle pointed out) run a bit slower than newer frequently updated libs.

Share this post


Link to post
Share on other sites

  • Advertisement