.obj and .mtl problem

Started by
11 comments, last by HelderBorges 12 years, 11 months ago
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 ;)
Advertisement
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


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
Plz. Someone give me a tip??? :S
Try this out.

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

-me

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

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

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?

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion


[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 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.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

This topic is closed to new replies.

Advertisement