Jump to content
  • Advertisement

Archived

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

PmanC

model loading/vector push_back

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

i wasn''t sure wether this should go here or in the general programming, but here it goes. i''m writing a .smd model loader and at the moment, i am using std vectors instead of linked lists. here is my model loader:
void smd::LoadSmd(char path[50]){
	FILE *file;
	char line[LINELENGTH];
	file=fopen(path,"rt");
	vertex v;
	GLuint tx;
	char txPath[50];
	numOVerts=0;
	bool inNode=false,inSkel=false,inTri=false;
	while (!feof(file)){
		fgets(line,LINELENGTH,file);
		if ((line[0]==''e'')&&(line[1]==''n'')&&(line[2]==''d'')){
			inNode=false;
			inSkel=false;
			inTri=false;
		}
		else if (inNode){
			//parse node line
		}
		else if (inSkel){
			//parse skeleton line
		}
		else if (inTri){
			//parse triangle line
			if (line[0]=='' ''){
				numOVerts++;
				sscanf(line,"  %d %f %f %f %f %f %f %f %f",
					&v.parent,
					&v.pos.x,&v.pos.y,&v.pos.z,
					&v.norm.x,&v.norm.y,&v.norm.z,
					&v.texCoord.x,&v.texCoord.y);
				v.tex=tx;
				if (!v.tex){
					MessageBox(NULL,"NULL IN V",NULL,NULL);
				}
				verts.push_back(v);
				if (!verts[numOVerts].tex){
					MessageBox(NULL,"NULL IN VERTS",NULL,NULL);
					MessageBox(NULL,path,NULL,NULL);
				}
			}
			else {
				sscanf(line,"%s\n",&txPath);
				tx=LoadRaw(txPath,512,512,3);
				if (!tx){
					MessageBox(NULL,"NULL ON LOAD",NULL,NULL);
				}
			}
		}
		else {
			//probably at a comment, or a beginning or somthing
			if ((line[0]==''n'')&&(line[1]==''o'')){
				inNode=true;
			}
			else if ((line[0]==''s'')&&(line[1]==''k'')){
				inSkel=true;
			}
			else if ((line[0]==''t'')&&(line[1]==''r'')){
				inTri=true;
			}
			else {
				//forget it...
			}
		}

	}
	fclose(file);
}
it loads verticies perfectly, but the problem comes when i try to load/store the textures. basically, the textures are all null when i go to render the model. i put in message boxes to help pinpoint the problem. when i run the program i get "NULL IN VERTS" errors, which means the texture isn''t being ''pushed_back'' with the rest of the vertex. here is a sample of a smd file:
version 1
nodes
  0 "joint1"  -1
end
skeleton
time 0
  0 0.000000 0.000000 -0.250000 1.570796 0.000000 0.000000
end
triangles
brickTex.raw
  0 -20.0000 -10.0000 -40.0000 -0.6667 -0.6667 -0.3333 0.0000 1.0000
  0 -20.0000 10.0000 -40.0000 -0.4082 0.4082 -0.8165 0.0000 0.0000
  0 20.0000 -10.0000 -40.0000 0.4082 -0.4082 -0.8165 1.0000 1.0000
brickTex.raw
  0 -20.0000 10.0000 -40.0000 -0.4082 0.4082 -0.8165 0.0000 0.0000
  0 20.0000 10.0000 -40.0000 0.6667 0.6667 -0.3333 1.0000 0.0000
  0 20.0000 -10.0000 -40.0000 0.4082 -0.4082 -0.8165 1.0000 1.0000
...
...
...
end
why is the tex in verts[numOVerts].tex null?

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!