Advertisement

02.26.2008 at 12:30PM PST, ID: 23194972
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

How do I manage a list of texture objects with instantaneous lookup when I need it

Tags: C++, OpenGL
I have a function that loads a bitmap from a filename, generates a unique texture ID, and returns it.  In an application where I could possibly need hundreds of textures my current setup simply will not do, or it may, and that is my question.

We are to assume that the game logic or game engine itself will demand a list of objects for whatever game we're playing.
Then we can assume that each object initialized in the engine will need to acquire various resources, textures perhaps.

Should the objects call the loadtexture function?
Should the engine call loadtexture for each object loaded?
Should the engine wait for a list of objects to be initialized, use that information, and load everything in one foul swoop with a modified loadtexture function.

I think that the engine could better manage this responsibility because it is aware of which objects and resources are currently loaded.

I have a resource manager, that is essentially a map wrapper that ties Data<T_> with a string or integer.
The engine would register each object and as it would do that it would make calls to the resource manager to check if the filename has been loaded into the manager.  If the filename has been loaded it will return a reference to a texture id, if the filename has not been loaded it will run loadtexture on the file name and return the id.

I guess there are multiple ways to achieve what I'm trying and I'm just wondering what you all think is the best way.

Lets assume we want to precache some of the objects.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
int LoadTextures( const char *filename )			// Load Bitmaps And Convert To Textures
{
	Bitmap image;									// Create Storage Space For The Textures
	image.Load(filename);
	GLuint texture = 0;								// Texture ID's
 
	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if ( image.GetImg() != NULL )		// If Texture Image Exists
	{
		glGenTextures(1, &texture);						// Create The Texture
 
		// Typical Texture Generation Using Data From The Bitmap
		glBindTexture(GL_TEXTURE_2D, texture);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, image.GetWidth(), image.GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.GetImg());
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	}
 
	return texture;							
}
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Pauli311
Solution Provided By: ikework
Participating Experts: 1
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
02.27.2008 at 03:43AM PST, ID: 20993128

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.27.2008 at 06:25AM PST, ID: 20994153

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628