Sign in to follow this  
Hand_Of_Destruction

Some error in my model loading lib

Recommended Posts

I guess it is something really stupid. I copy'n'pasted most of code from main program to the new model.h file, and now it doesn't work. Here the code (I use OpenGLUT)
#include <GL/openglut.h> 
#include <iostream.h>
#include <fstream.h>
#include <math.h>

class CVertex {
      public:
            float x,y,z;
};

class CFace {
      public:
            int ind[4];
};

class CModel {
      private:
              int faces, vertices;
              CVertex *Vertices;
              CFace *Faces;
      public:
             void LoadModel(char* path);
             void RenderModel(float x,float y,float z);
             void FreeModel(void);
};

void CModel::LoadModel(char* path)
{
     int size,fcount,vtx,c;
     ifstream fin(path);
     fin >> size;
     vertices = size;
     Vertices = new CVertex[vertices];
     for (vtx=0;vtx<size;vtx++)
     {
          fin >> Vertices[vtx].x;
          fin >> Vertices[vtx].y;
          fin >> Vertices[vtx].z;
     }
     fin >> fcount;
     faces = fcount;
     Faces = new CFace[fcount];
     for (vtx=0;vtx<fcount/4;vtx++)
     {
         for (c=0;c<4;c++)
         {
            fin >> Faces[vtx].ind[c];
         } 
     }   
};                  

void CModel::RenderModel(float x,float y,float z)
{
     int face, vert;
     for (face=0;face<faces;face++)
     {
         glBegin(GL_QUADS);
         for (vert=0;vert<4;vert++)
         {
   
            glVertex3f(x+Vertices[Faces[face].ind[vert]].x,y+Vertices[Faces[face].ind[vert]].y,z+Vertices[Faces[face].ind[vert]].z);
         }
         glEnd();
     }
};

void CModel::FreeModel()
{
     delete [] Vertices;
     delete [] Faces;
};

here's the export.txt (model file) export.txt Please look at it so I can make my own model loading lib ;] Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I can't see what error you are talking about in your post because you are not explaining exactly what is not working or the error given by your compiler. But I think your error is that you forget to create a constructor for your classes.
You have some functions inside your classes but no object being constructed so you can access those member functions. Just take a look on google for c++ classes and how they are implemented.

Share this post


Link to post
Share on other sites
Yup I forgot. Error is that when I execute CModel::RenderModel(0.0f,0.0f,0.0f) nothing appears on the screen (of course I execute LoadModel before.
I'll try with constructors.


EDIT: Nothing... same... black screen and nothing happens.

[Edited by - Hand_Of_Destruction on April 15, 2006 11:41:11 AM]

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