Sign in to follow this  
Xetheriel

Hello! I'm new here! (MS3D Texture loading help)

Recommended Posts

Hello! I'm new here, I decided I'd sign up for a resource in learning game development, just dropping in to introduce myself. I have about 2 years of experience in C++ programming, now I want to venture into games. I have one question, regarding NeHe's lesson 31 (milkshape model loading)
void MS3DModel::ReloadTextures()
{
	for ( int i = 0; i < NumMaterials; i++ )
		if ( strlen(Materials[i].TextureFilename) > 0 )
		{
			std::string TextureFilename = Materials[i].TextureFilename;

			Materials[i].Texture = LoadGLTexture( Materials[i].TextureFilename );
		}
		else
			Materials[i].Texture = 0;
}



This is the texture loading function called in every load function, there is a single problem with this, the automated loading nature of the texture is fudged up by the fact that the texture filepath stored in the ms3d file is relative upon the saving of the origional ms3d file! Got that? Good, moving on. :D I've decided to set up an std::string TextureFilename in the texture loading function in which I can manipulate and delete everything out of the string that isn't the final file name, problem is, how in the world am I supposed to do this? Thank! EDIT: I figure that the operations I need to accomplish include the following steps: 1. Find the last "/" character 2. Erase everything before that last "/" character 3. Add my own filepath to the beginning of that new string I know the functions I need are find_last_of, and erase, but I'm not sure how to erase everything before the last /... [Edited by - Xetheriel on April 3, 2006 7:44:43 PM]

Share this post


Link to post
Share on other sites
So, you're asking how to grab the last part of the filepath (i.e. the file minus the directory) ?

Well, after you grab the texture filename, you could do something like, int cutoff = TextureFilename.find_last_of('\\'); and then do FileName = TextureFilename.substr(cutoff + 1); and then FileName will contain just the file minus the directory stuff. There's also some MFC functions that can pull the name a lot easier, but not sure if you're using MFC...

Share this post


Link to post
Share on other sites
Hey it works!

It sets the final name given to the load function = to the actual filename, minus the filepath!

Now all I gotta do is path ALL files to a certain path, by inserting a filepath string at the beginning of each texture!

Rate++

Can you imagine the sense of accomplishment?!

Picture!!

[Edited by - Xetheriel on April 3, 2006 8:51:49 PM]

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this