.OBJ texture mapping
I am doing a game for a project in school, and we have to load a .obj file onto our application. I am using code that comes with the glut source (the 'smoot' program example) to load the .obj file. I noticed that the code does generate texture coords, it reads the .mtl file correctly but it does not map the textures defined in the mtl file. I also noticed it generates spherical and linear texture coordinates. now the questions:
1. what are spherical and linear texture coordinates? I see it as differente modes or projection of the texture onto the model
2. What is best for me: try to read the .mtl correctly, or create a texture to use on the generated texture coords, or use another approach?
I have made some research and i cannot find a decent .OBJ specification...
thanks in advance
Quote:Original post by avt
I am doing a game for a project in school, and we have to load a .obj file onto our application. I am using code that comes with the glut source (the 'smoot' program example) to load the .obj file. I noticed that the code does generate texture coords, it reads the .mtl file correctly but it does not map the textures defined in the mtl file. I also noticed it generates spherical and linear texture coordinates. now the questions:
1. what are spherical and linear texture coordinates? I see it as differente modes or projection of the texture onto the model
2. What is best for me: try to read the .mtl correctly, or create a texture to use on the generated texture coords, or use another approach?
I have made some research and i cannot find a decent .OBJ specification...
thanks in advance
The texture coordinates are stored in the obj file. They are ascii text, you can open them and have a look. Easy to parse. The vt lines have the texture coords.
wotsit.org has a good obj specification.
Let's suppose I model a spaceship in 3DS (which, btw, i dunno how to work with). I apply a texture on that model and then I export it to a .obj file, My doubt is how do I make a texture that have a cockpit, some turbo engines or so, and so on, and then I import it to my opengl app? I do not fully understand the steps between a textured model in .obj format, and the import of that model in an opengl app.
Quote:Original post by avt
Let's suppose I model a spaceship in 3DS (which, btw, i dunno how to work with). I apply a texture on that model and then I export it to a .obj file, My doubt is how do I make a texture that have a cockpit, some turbo engines or so, and so on, and then I import it to my opengl app? I do not fully understand the steps between a textured model in .obj format, and the import of that model in an opengl app.
I'm not sure which part you don't understand. Do you have the spaceship already textured? Just export to obj and then read it in your program. Store the vertices, faces, normals, and texture coordinates.. then you feed these to the gl**** functions.
You load your texture, bind it and then draw your model. To draw it in immediate mode, it's something like this.
glBegin(GL_TRIANGLES);
glTextCoord2d(s,t);
glNormal3d(x,y,z);
glVertex3f(x,y,z);
glEnd();
Quote:Original post by avt
I have made some research and i cannot find a decent .OBJ specification...
You mean file format specification? If so, you can check wotsit.org.
lets suppose i model a spaceship in max. I create a texture for the canopy, and another texture for the ship. then the obj will contain the texture information, right? So i just have to pick the texture coordinates from the .obj (or mtl) and map it to its correspondent .bmp or whatever?? is this it?
read oneline from obj file and first take number of texture coordinates, use: if oneline == v&&t
{ m_numTexCoords++;}
then make a loop
for(i=0;i<numTexCoords;i++)
{
getStr(fp,oneline,'v');
sscanf(oneline,"vt %f %f",&m_pTexCoords.u,&m_pTexCoords.v);
}
no need to use mtl files for one model and one texture.
there is a tutrorial at gametutorials.
{ m_numTexCoords++;}
then make a loop
for(i=0;i<numTexCoords;i++)
{
getStr(fp,oneline,'v');
sscanf(oneline,"vt %f %f",&m_pTexCoords.u,&m_pTexCoords.v);
}
no need to use mtl files for one model and one texture.
there is a tutrorial at gametutorials.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement