Jump to content
  • Advertisement
Sign in to follow this  
Hand_Of_Destruction

Some error in my model loading lib

This topic is 4480 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 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
Advertisement
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
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!