• Advertisement

Archived

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

Object class and texture managing

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

Ok Ive begun to create my object class for my oop (simple) 3d engine. I plan on using this ''object'' for nearly all the graphical things appearing on the screen (buttons, background images, lions, trees, zebras) The only thing i will probably not have as an object in my overhead 3d world is the actual terain (ugg cant wait to start learning about terrain generation). Anyways I want add texture loading to my program and im not sure how i want to implement it. With oop i think I may want the object class to have a texture loading member. Would this be proper as opposed to having a seperate file with all functions dealing with bmps and texture loading and include it in my class? What else should i consider allowing my object to do. Right now my base object stores position and rotation info and has members to manipulate them. I then created a button class which inherits from object and adds some button-ish members. So should i add texture loading to the base class or inherited. If i add it to the base i will have to consider objects with multiple textures as well. Please anyone with experience creating their own graphical object to inherit class give me some tips

Share this post


Link to post
Share on other sites
Advertisement
Well, though I can''t say I''m _that_ experienced I still think it would be a good idea to seperate these things.

The base object should only hold a handle to the assigned texture and loading/managing should be done in seperate classes.

Thinking OOP - is your base object a texture or is it using textures? The latter fits better, doesn''t it?
BTW the same goes for other attributes that may be assigned to your objects, like physics, render states a.s.o.

I also have to admit that in some cases it isn''t that simple.
Take a "render()" method for example. Should any visual object implement its own "render()" ability or should there be a Renderer class that handles different objects and does the screen output? Both methodologies make sense in a way - good advice anyone?

Cheers,
Pat

Share this post


Link to post
Share on other sites
Ok so your suggesting that i have a seperate manager object that stores ALL game textures. It does seem to make sense. How would this be implimented. A dynamic array possibly. I currently have my game broken down into states. I have a game state, a main menu state, and an option state. Each has an init, draw, update, and shutdown member. I suppose i could have the texture manager object load all the textures needed for each state in its init member and clear them out in the shutdown member. Am i missing anything?? suggestions anyone??

edit:
Also how should i go about passing handles to my objects from the list??

[edited by - IllMind on December 1, 2002 9:55:09 PM]

Share this post


Link to post
Share on other sites
i am working on my first 3D game right now, and i have a texture manager class which loads the necessary textures into a dynamic array... this way if there are multiple game objects that use the same textures, the textures are not duplicated (wasting memory). each game object calls the texture manager''s "loadTexture()" function, which loads the texture (unless it has already been loaded). then, it returns the index of the texture in the dynamic array, which the game object stores. this works great for me (it would suck if the textures had to be dynamically un-loaded, because this might change all of the array indices, but that doesn''t happen in my game).

Share this post


Link to post
Share on other sites
Ok I am going to go the temxture manager object route. When I create an object i will have its Init() member load a texture into the manager classes texture list and store the position. I am using opengl for graphics and just read in the opengl SuperBible that opengl keeps the most recently used textures in memory and that you can use glPrioritize textures to raise a textures priority (keep it in memory as often as possible). So does this mean that when i have my game world up and running that I will load ALL the textures for everything in the game world at once, and let opengl manage them in memory?? Or do i need to worry about only keeping the textures that are used THAT moment in memory??

edit: Krez, when you load and add new textures, do you resize the array evey time? ie. Copy array, delete old array, create new array a bit bigger and copy info back + the new texture, delete copy...

[edited by - IllMind on December 1, 2002 10:33:24 PM]

Share this post


Link to post
Share on other sites
My current project i use quite a similar approach to krez''s.

The class stores the dynamic array of textures (one texture each to an instance of another class, also containing size, filename, and other stuff that may be useful later) in a vector .(could be optimized, but i like random access just in case). You call it with a textures file name, and (optionally) width and height. The class will check if the request has been made previously, and if so return the texture handle. Otherwise, it proceeds to load the texture, and file the request away in the vector.

It seems to be effective thus far, and relatively straight forward. Any q''s I can try to answer if you have ''em...

Share this post


Link to post
Share on other sites
quote:
Original post by IllMind
Krez, when you load and add new textures, do you resize the array evey time? ie. Copy array, delete old array, create new array a bit bigger and copy info back + the new texture, delete copy...

yah, but the loading part occurs once before the fight (i am making a fighting game of sorts) so i don''t mind it being slower than if i already knew the array size. also, i am just storing GLuint s (unsigned int as far as i can tell) so it''s isn''t really slow on the copying and stuff... if i run into problems i will speed this up later, but it seems ok for now.
sorry, but i can''t help you much; i''m only just beginning the 3D thing myself, and i''m also not going to have enough textures to have to worry about having too many for memory at once.

Share this post


Link to post
Share on other sites

  • Advertisement