Problem with glm (loading Obj files and txtures)

Started by
1 comment, last by _WeirdCat_ 11 years, 6 months ago
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 smile.png)
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 smile.png;
Advertisement
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
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

This topic is closed to new replies.

Advertisement