Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

OpenGL OBJ model loader, problem with quads (c++)

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 david92n   Members   

106
Like
0Likes
Like

Posted 05 May 2012 - 08:46 AM

Hi, I am making a simple model-loader för .OBJ files being rendered with OpenGL and using SFML for handling windows. It works fine with models that only uses polygons with 3 verticies but quads are broken. When polygonmode "GL_LINE" is used everything looks fine but with "GL_FILL" there are big holes. (see screenshots)


else if(line[0] == 'f' && line[1] == ' '){
	 int v1 = 1, t1 = 1, n1 = 1, v2 = 1, t2 = 1, n2 = 1, v3 = 1, t3 = 1, n3 = 1, v4 = 1, t4 = 1, n4 = 1;
	 if(std::count(line.begin(), line.end(), ' ') == 3){//Triangle
	  if(line.find("/") == std::string::npos)
	   sscanf(line.c_str(), "f %d %d %d", &v1, &v2, &v3);
	  else if(line.find("//") != std::string::npos)
	   sscanf(line.c_str(), "f %d//%d %d//%d %d//%d", &v1, &n1, &v2, &n2, &v3, &n3);
	  else
	   sscanf(line.c_str(), "f %d/%d/%d %d/%d/%d %d/%d/%d", &v1, &t1, &n1, &v2, &t2, &n2, &v3, &t3, &n3);
	  int vertInd[] = {v1, v2, v3, 0};
	  int normInd[] = {n1, n2, n3, 0};
	  int texInd[] = {t1, t2, t3, 0};
	  mFaces.push_back(ModelFace(vertInd, normInd, texInd, false));
	 }else{//Quad
	  if(line.find("/") == std::string::npos)
	   sscanf(line.c_str(), "f %d %d %d %d", &v1, &v2, &v3, &v4);
	  else if(line.find("//") != std::string::npos)
	   sscanf(line.c_str(), "f %d//%d %d//%d %d//%d %d//%d", &v1, &n1, &v2, &n2, &v3, &n3, &v4, &n4);
	  else
	   sscanf(line.c_str(), "f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d", &v1, &t1, &n1, &v2, &t2, &n2, &v3, &t3, &n3, &v4, &t4, &n4);
	
	  int vertInd[] = {v1, v2, v3, v4};
	  int normInd[] = {n1, n2, n3, n4};
	  int texInd[] = {t1, t2, t3, t4};
	  mFaces.push_back(ModelFace(vertInd, normInd, texInd, true));
	 }
	}
This code is for loading the indicies for the faces.



glNewList(mIndex, GL_COMPILE);
  for(size_t i = 0; i < mFaces.size(); ++i){
   int verts = 0;
   if(mFaces[i].isQuad()){
	verts = 4;
	glBegin(GL_QUADS);
   }else{
	verts = 3;
	glBegin(GL_TRIANGLES);
   }
  
   int* vertId = mFaces[i].getVertInd();
   int* normId = mFaces[i].getNormInd();
   int* texId = mFaces[i].getTexInd();
   for(int n = 0; n < verts; ++n){
	if(mHasNormals){
	 sf::Vector3f norm = mVertexNormals[normId[n] - 1];
	 glNormal3f(norm.x, norm.y, norm.z);
	}
	if(mHasTexture){
	 sf::Vector2f tex = mTexCoords[texId[n] - 1];
	 glTexCoord2f(tex.x, tex.y);
	}
	sf::Vector3f vert = mVerticies[vertId[n] - 1];
	glVertex3f(vert.x, vert.y, vert.z);
   }
   glEnd();
  }

glEndList();
This is for compiling the model




Thanks!

Attached Files



#2 david92n   Members   

106
Like
0Likes
Like

Posted 05 May 2012 - 09:22 AM

Also if someone have a tips on how to improve how I see if it is a QUAD or not, that would be appreciated Posted Image

if(std::count(line.begin(), line.end(), ' ') == 3)

Edited by david92n, 05 May 2012 - 09:23 AM.


#3 david92n   Members   

106
Like
0Likes
Like

Posted 05 May 2012 - 10:59 AM

Problem solved...didn't expect polygons with 25 vertices. Now it can take any number of vertices on a polygon and the holes are fixed!




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.