Sign in to follow this  
HelderBorges

.obj and .mtl problem

Recommended Posts

HelderBorges    100
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 this post


Link to post
Share on other sites
FXACE    182
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 this post


Link to post
Share on other sites
HelderBorges    100
[quote name='FXACE' timestamp='1305719356' post='4812474']
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


[/quote]

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 this post


Link to post
Share on other sites
FXACE    182
Try [url="http://www.tutorialized.com/view/tutorial/Write-a-WaveFront-OpenGL-3D-object-loader-in-C/59679"]this[/url] out.

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

-me

Share this post


Link to post
Share on other sites
HelderBorges    100
[quote name='Helder19' timestamp='1305744535' post='4812670']
The problem is that i rely need to use GLM as a loader. :\
[/quote]

[code]
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);
[/code]



[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[/color]

Share this post


Link to post
Share on other sites
NightCreature83    5006
[quote name='FXACE' timestamp='1305741166' post='4812636']
Try [url="http://www.tutorialized.com/view/tutorial/Write-a-WaveFront-OpenGL-3D-object-loader-in-C/59679"]this[/url] out.

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

-me


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

Share this post


Link to post
Share on other sites
HelderBorges    100
[quote name='NightCreature83' timestamp='1305756129' post='4812757']
[quote name='FXACE' timestamp='1305741166' post='4812636']
Try [url="http://www.tutorialized.com/view/tutorial/Write-a-WaveFront-OpenGL-3D-object-loader-in-C/59679"]this[/url] out.

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

-me


[/quote]
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 this post


Link to post
Share on other sites
NightCreature83    5006
[quote name='Helder19' timestamp='1305756606' post='4812760']
[quote name='NightCreature83' timestamp='1305756129' post='4812757']
[quote name='FXACE' timestamp='1305741166' post='4812636']
Try [url="http://www.tutorialized.com/view/tutorial/Write-a-WaveFront-OpenGL-3D-object-loader-in-C/59679"]this[/url] out.

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

-me


[/quote]
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 this post


Link to post
Share on other sites
HelderBorges    100
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 this post


Link to post
Share on other sites
NightCreature83    5006
[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):\
[/quote]
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 this post


Link to post
Share on other sites
HelderBorges    100
[quote name='NightCreature83' timestamp='1305811771' post='4812986']
[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):\
[/quote]
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. :D 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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this