Sign in to follow this  
sjmarsha

Messed up Textures

Recommended Posts

sjmarsha    130
Hi All I have this code to read doom 3 material files, but when I tokenize the file, and return a valid texture name, the map loads all wrong with half the textures missing. If I comment out the tokenizing code, and return a static string from this function the textures load correctly. Any help would be welcome. Here is the code: char * Doom_C::findMatTexture(char * string,char * file_name) { FILE *filein; char oneline[1024]; char *ch; bool return_texture; bool valid_tex; //char temp[100]; char temp_two[100]; char * trimed_mat; //Open MAP File filein = fopen(file_name, "rt"); //test that we found the file if (filein == NULL) { MessageBox(NULL,file_name,"Can't Open File",MB_OK); return ""; } while (!feof(filein)) { fgets(oneline, 1024,filein); ch = strtok(oneline," "); if (ch != '\0') { valid_tex = testTextureName(ch); if (valid_tex) { trimed_mat = trimMaterial(ch); //sprintf(temp, "File: %s and Texture: %s and STRING: %s with lengths %d %d",mat_name,trimed_mat,string,strlen(trimed_mat),strlen(string)); //MessageBox(NULL,temp,"+++ Valid Material Detected",MB_OK); if ((strcmp(trimed_mat,string) == 0)) { sprintf(temp_two, "File: %s and Texture: %s",file_name,trimed_mat); //MessageBox(NULL,temp_two,"+++ Material Detected",MB_OK); return_texture = true; } if (return_texture) { if (testTextureEnding(trimed_mat)) { //MessageBox(NULL,trimed_mat,"+++ Returning Material",MB_OK); fclose(filein); return trimed_mat; } } valid_tex = false; } } do { ch = strtok('\0'," "); if (ch != '\0') { valid_tex = testTextureName(ch); if (valid_tex) { trimed_mat = trimMaterial(ch); //sprintf(temp, "File: %s and Texture: %s",mat_name,trimed_mat); //MessageBox(NULL,temp,"*** Valid Material Detected",MB_OK); if ((strcmp(trimed_mat,string) == 0)) { sprintf(temp_two, "File: %s and Texture: %s",file_name,trimed_mat); //MessageBox(NULL,temp,"*** Material Detected",MB_OK); return_texture = true; } if (return_texture) { if (testTextureEnding(trimed_mat)) { //MessageBox(NULL,trimed_mat,"*** Returning Material",MB_OK); fclose(filein); return trimed_mat; } } valid_tex = false; } } } while(ch); } fclose(filein); return ""; } regards Steve

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this