# .obj and .mtl problem

This topic is 2440 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys.
I'm trying to load an object with GLM.
I can easily load the image into the project and i turn the lights on and off so i can get some effects. But the problem is that, the object is always white and i don't know what to do so it have the right color, because with GLM they are white, but wen i use Wing3D they have the right color.
Can someone help me?
And thanks for the spent time

##### Share on other sites
Do you mean GLM (OpenGL Mathematics)?

If yes, put glEnable(GL_COLOR_MATERIAL) in your code. This gives access to change a diffuse color of object by calling glColor(...) in OpenGL.

-me

##### Share on other sites

Do you mean GLM (OpenGL Mathematics)?

If yes, put glEnable(GL_COLOR_MATERIAL) in your code. This gives access to change a diffuse color of object by calling glColor(...) in OpenGL.

-me

Ty but is not working either. :\. And y,is what i mean. GLM is a loader for .obj files. And some objects can load properly the information from the -mtl file, but other objects cant. :S

##### Share on other sites
Plz. Someone give me a tip??? :S

##### Share on other sites
Try this out.

There are many references to load Wavefront object on the Internet. It's not a big problem.

-me

##### Share on other sites
The problem is that i rely need to use GLM as a loader. :\

##### Share on other sites

The problem is that i rely need to use GLM as a loader. :\

 GLMmodel *obj; obj = glmReadOBJ("porsche.obj"); glmUnitize(obj); glmFacetNormals(obj); glmVertexNormals(obj,90); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); glLightfv(GL_LIGHT0,GL_POSITION,posl); glLightfv(GL_LIGHT1,GL_POSITION,posl); glLightfv(GL_LIGHT2,GL_POSITION,posl); glLightfv(GL_LIGHT0,GL_AMBIENT, amb); glLightfv(GL_LIGHT1,GL_AMBIENT, amb); glLightfv(GL_LIGHT2,GL_AMBIENT_AND_DIFFUSE, amb); glLightfv(GL_LIGHT0,GL_DIFFUSE, diff); glLightfv(GL_LIGHT1,GL_DIFFUSE, diff); glLightfv(GL_LIGHT2,GL_AMBIENT_AND_DIFFUSE, diff); glTranslatef(-(wt/2)+50,h(-(wt/2)+50,-(ht/2)+50)+1,-(ht/2)+50); glRotatef(-90,1,0,0); glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,cor); glmDraw(obj,GLM_SMOOTH|GLM_MATERIAL); glDisable(GL_LIGHT0); glDisable(GL_LIGHT1); glDisable(GL_LIGHT2); glDisable(GL_LIGHTING); 

[color="#333333"]I use this in deferent parts of the project, but it is all the code i need to use. The translates is to place the object in the right position. I already loaded the object in Wings 3D. And it load properly. I only get problems wen i load with GLM. And all the color or texture should be at the mtl file :S

##### Share on other sites

Try this out.

There are many references to load Wavefront object on the Internet. It's not a big problem.

-me

You do realise that that particular piece of code isn't the most efficient in displaying an OBJ model right?

##### Share on other sites

[quote name='FXACE' timestamp='1305741166' post='4812636']
Try this out.

There are many references to load Wavefront object on the Internet. It's not a big problem.

-me

You do realise that that particular piece of code isn't the most efficient in displaying an OBJ model right?
[/quote]

Not really :S Can you point me to the right direction? I opened the mtl file and saw "ilu 2" So i turned on all lights till light 2.

##### Share on other sites

[quote name='NightCreature83' timestamp='1305756129' post='4812757']
[quote name='FXACE' timestamp='1305741166' post='4812636']
Try this out.

There are many references to load Wavefront object on the Internet. It's not a big problem.

-me

You do realise that that particular piece of code isn't the most efficient in displaying an OBJ model right?
[/quote]

Not really :S Can you point me to the right direction? I opened the mtl file and saw "ilu 2" So i turned on all lights till light 2.
[/quote]

Sorry I was responding to the tutorial he gave you, it assumes some things for the obj file which arent true for all obj files. An obj can contain a list of faces that are stored as quads, triangles or a mixture of both depending on export settings.
On top of that the example code is showing draw code that extensively uses glVertex3x functions which are slow if you are using them a lot, VBO's are the way to go in that case.

On topic:
The lights turning on should be ok but the obj file doesn't specify if the object it contains is lit or not, it just contains parameter settings for the materials of the object which might be used in the lighting calculations.

Try disabling light and render the object flatly and see if that works properly, if it does there is most likely something wrong in your lighting setup.

##### Share on other sites
without light, the object dont render properly. Thats why i turned the lights on and off. I will use VBO in the project... But only for the ground, since i´m facing some difficulties puting the VBO to work because the ground have 4000square meters (2000x2000) and he have a high map (so we can have mountains):\

##### Share on other sites

without light, the object dont render properly. Thats why i turned the lights on and off. I will use VBO in the project... But only for the ground, since i´m facing some difficulties puting the VBO to work because the ground have 4000square meters (2000x2000) and he have a high map (so we can have mountains):\

Disabeling lighting shouldnt matter for the display of a mesh, it will just not have any highlights or light colors applied to it, the geometry should still be visible it will look flat though. If it doesn't display correctly then something is seriously wrong in the OBJ file and/or the loading of the file.

##### Share on other sites

[quote name='Helder19' timestamp='1305803008' post='4812949']
without light, the object dont render properly. Thats why i turned the lights on and off. I will use VBO in the project... But only for the ground, since i´m facing some difficulties puting the VBO to work because the ground have 4000square meters (2000x2000) and he have a high map (so we can have mountains):\

Disabeling lighting shouldnt matter for the display of a mesh, it will just not have any highlights or light colors applied to it, the geometry should still be visible it will look flat though. If it doesn't display correctly then something is seriously wrong in the OBJ file and/or the loading of the file.
[/quote]

Found the solution GML dont load texture. My teacher told me to go to glm.c and change it so he can read the line of the .mtl file where it show the texture (the map_Kd line from the .mtl) and make the gml.c read that line and store it,so i can use Devil Later to load the texture in the .Obj. Was i clear? sry for English, but it is a mess even for me xD