Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Problem with glm (loading Obj files and txtures)


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 UdvPeter   Members   -  Reputation: 101

Like
0Likes
Like

Posted 06 October 2012 - 01:50 AM

Hello!

I am creating an opengl app that loads .obj files but I have some serious problems loading them.

When I'm loading obj files it loads vorrectly but after several redisplays it throws an exception "cannot load texture file" then it stops.

I think It's because I load the .Obj file again and again so I changed the code to load once but now it doesn't draws the texture.

Here's my code:

[source lang="cpp"]GLMmodel* LoadOBJ(int ID){ char* modelIDs[6] = {"ko.obj","bou.obj","bouKez.obj","bouLosz.obj","ellen.obj","ellenLosz.obj"}; char* path = modelIDs[ID]; GLMmodel* pmodel1 = NULL; // Load the model only if it hasn't been loaded before // If it's been loaded then pmodel1 should be a pointer to the model geometry data...otherwise it's null if (!pmodel1) { // this is the call that actualy reads the OBJ and creates the model object pmodel1 = glmReadOBJ((char*)path); if (!pmodel1) exit(0); // This will rescale the object to fit into the unity matrix // Depending on your project you might want to keep the original size and positions you had in 3DS Max or GMAX so you may have to comment this. glmUnitize(pmodel1); // These 2 functions calculate triangle and vertex normals from the geometry data. // To be honest I had some problem with very complex models that didn't look to good because of how vertex normals were calculated // So if you can export these directly from you modeling tool do it and comment these line // 3DS Max can calculate these for you and GLM is perfectly capable of loading them glmFacetNormals(pmodel1); glmVertexNormals(pmodel1, 90.0); } // This is the call that will actualy draw the model // Don't forget to tell it if you want textures or not [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]) return pmodel1;}class m3Dobject{ public: GLMmodel* model1; public: float scale; public: float xpos; public: float ypos; public: float zpos; public: float rotAngle; public: float xrot; public: float yrot; public: float zrot; bool everLoaded;public: m3Dobject(int ModelPath,float scaleh,float xposh,float yposh,float zposh,float rotAngleh,float xroth,float yroth,float zroth) { model1 = LoadOBJ(ModelPath); xpos = xposh; ypos = yposh; zpos = zposh; rotAngle = rotAngleh; xrot = xroth; yrot = yroth; zrot = zroth; scale = scaleh; }};void Render(m3Dobject objo) { glPushMatrix(); glScalef(objo.scale,objo.scale,objo.scale); glTranslatef(objo.xpos,objo.ypos,objo.zpos); glRotatef(objo.rotAngle*RAD,objo.xrot,objo.yrot,objo.zrot); glmDraw(objo.model1,GLM_SMOOTH|GLM_MATERIAL|GLM_TEXTURE); glPopMatrix(); }[/source]


Thanks for your help in advance Posted Image;

Sponsor:

#2 WiredCat   Members   -  Reputation: 353

Like
0Likes
Like

Posted 06 October 2012 - 11:30 AM

i do not know glm but it seems to cant find the files if no textures are loaded. you should tell program the full path, aer you really loading mtl files in order to get textures?; ]
code you have given looks fine (read as no errors seen ;X]

and i found something like this

GLMmodel *pmodel1 = glmReadOBJ("data/world.obj",&call);
typedef struct _GLMmodel {
char* pathname; /* path to this model */
char* mtllibname; /* name of the material library */ do you define these vars? i think no

#3 WiredCat   Members   -  Reputation: 353

Like
0Likes
Like

Posted 09 October 2012 - 06:31 PM

ahh and change loading becasue i do not see any data allocation like GLMmodel* md = new GLMmodel();? then you can call load obj model function that returns GLMmodel* but do not use null var when laoding to glmobj cerate new GLMmodel* too




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.



PARTNERS