Jump to content
  • Advertisement
Sign in to follow this  
JasonVoorhees

OpenGL [c++] class to load *.obj model file

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

Hello. I've read Forum FAQ, but I would rather use the class. I have downloaded code from wosit ( http://www.wotsit.org/list.asp?al=O - C++ Code for reading OBJ file by VenTure ), but there is a class only for load the model. All I need is to render the loaded model, using OpenGL. I tried to write my own rendering function, but when the function is working, the program turns off. Thanks for answers.
void COBJFile::Render()
{
  int i;
  int nf=GetNumFaces();
glRotatef(-90,1,0,0);
glBindTexture(GL_TEXTURE_2D,texture);
glBegin (GL_TRIANGLE_STRIP);
  for (i = 0; i < nf-1; i++)
    {
int vti=GetFaceTextureVertexIndex(i,0);
	      glTexCoord3f (_vertexTextures[vti].u,_vertexTextures[vti].v,_vertexTextures[vti].w);
int vni=GetFaceNormalVertexIndex(i,0);
	      glNormal3f (_vertexNormals[vni].i,_vertexNormals[vni].j,_vertexNormals[vni].k);
int vi=GetFaceNormalVertexIndex(i,0);
	    glVertex3f (_vertices[vi].x,_vertices[vi].y,_vertices[vi].z);
    }
	glEnd();
glRotatef(90,1,0,0);
}

BTW. the model I wish to load hasn't any vertex groups. [Edited by - JasonVoorhees on June 26, 2007 6:21:58 PM]

Share this post


Link to post
Share on other sites
Advertisement

Quote:

int vni=GetFaceNormalVertexIndex(i,0);
glNormal3f (_vertexNormals[vni].i,_vertexNormals[vni].j,_vertexNormals[vni].k);
int vi=GetFaceNormalVertexIndex(i,0);
glVertex3f (_vertices[vi].x,_vertices[vi].y,_vertices[vi].z);


You have used the same function 'GetFaceNormalVertexIndex' for getting the indices. Is this deliberate?

Share this post


Link to post
Share on other sites
Does changing the 2nd index help?
ex:

int vi=GetFaceNormalVertexIndex(i,0);
...
int vi=GetFaceNormalVertexIndex(i,1);
...
int vi=GetFaceNormalVertexIndex(i,2);
...

Or try 0, 2, 1 for index order if normals appear inside-out.

Share this post


Link to post
Share on other sites
Quote:
Original post by KumGame07

Quote:

int vni=GetFaceNormalVertexIndex(i,0);
glNormal3f (_vertexNormals[vni].i,_vertexNormals[vni].j,_vertexNormals[vni].k);
int vi=GetFaceNormalVertexIndex(i,0);
glVertex3f (_vertices[vi].x,_vertices[vi].y,_vertices[vi].z);

You have used the same function 'GetFaceNormalVertexIndex' for getting the indices. Is this deliberate?

Thanks for a small correction but it doesn't work anyway.
Quote:
Original post by taby
Does changing the 2nd index help?
ex:

int vi=GetFaceNormalVertexIndex(i,0);
...
int vi=GetFaceNormalVertexIndex(i,1);
...
int vi=GetFaceNormalVertexIndex(i,2);
...

Or try 0, 2, 1 for index order if normals appear inside-out.

That doesn't work too...

//edit
I made arrays larger (from 1024 to 2048) and the program stars, but it doesn't render my model.
When I used obj loader made in C in the same program, which rendering funcion looked like that:

void
RenderOBJModel (obj_model_t *mdl, GLuint mdltex)
{
int i, j;
glRotatef(-90,1,0,0);
glBindTexture(GL_TEXTURE_2D,mdltex);
for (i = 0; i < mdl->num_faces; ++i)
{
glBegin (mdl->faces.type);
for (j = 0; j < mdl->faces.num_elems; ++j)
{
if (mdl->has_texCoords)
glTexCoord3fv (mdl->texCoords[mdl->faces.uvw_indices[j]].uvw);

if (mdl->has_normals)
glNormal3fv (mdl->normals[mdl->faces.norm_indices[j]].ijk);

glVertex4fv (mdl->vertices [mdl->faces.vert_indices[j]].xyzw);
}
glEnd();
}
glRotatef(90,1,0,0);
}



Then everything worked fine.

//edit
I made that work, but that works only in debug version... where might be the problem ??

[Edited by - JasonVoorhees on June 27, 2007 5:24:04 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!