OBJ Model Texturing Problems

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

OBJ Model Texturing Problems

Peter
I am trying to add a model loader to my jogl program. I have tried a number of implementations and the only one that seems to work is found here: https://github.com/demoscenepassivist/SocialCoding/blob/master/code_demos_jogamp/src/framework/util/WavefrontObjectLoader_DisplayList.java

However I am having a problem getting textures to map on the loaded models correctly. The code that I'm using to load the texture is posted below, as well as the code that I use to texture.

private Texture loadTexture(String fileName) {
    Texture tex = null;
    try {
        tex = TextureIO.newTexture(new File(fileName), true);
        tex.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
        tex.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
    } catch (Exception e) {
        System.out.println("Error loading texture " + fileName);
    }
    return tex;
}


    palmTex.enable();
    palmTex.bind();
    gl.glPushMatrix();
    gl.glTranslatef(150, 100, 800);
    gl.glScalef(5f, 5f, 5f);
    palm.callDisplayList(gl);
    gl.glPopMatrix();
    palmTex.disable();

And here are is the texture I'm trying to map:

http://imageshack.us/photo/my-images/257/palmt1.png/

Finally, this is the resulting model:

http://imageshack.us/photo/my-images/827/badtex.png/

Any insight on why this is happening would be greatly appreciated!
Reply | Threaded
Open this post in threaded view
|

Re: OBJ Model Texturing Problems

Pixelapp
At a glance I see you only have two of these:

                                tex[count].setTexParameterf(gl, GL2.GL_TEXTURE_MIN_FILTER,
                                                GL2.GL_NEAREST);
                                tex[count].setTexParameterf(gl, GL2.GL_TEXTURE_MAG_FILTER,
                                                GL2.GL_NEAREST);
                                tex[count].setTexParameterf(gl, GL2.GL_TEXTURE_WRAP_S,
                                                GL2.GL_REPEAT);
                                tex[count].setTexParameterf(gl, GL2.GL_TEXTURE_WRAP_T,
                                                GL2.GL_REPEAT);

Add the last to methods. Then check back.
Reply | Threaded
Open this post in threaded view
|

Re: OBJ Model Texturing Problems

Demoscene Passivist
Administrator
In reply to this post by Peter
The source code looks just fine as far as I can tell. For a complete example on how to use the loader take a look here (guess u have already found the example by urself): GL2_UVUnwrap.java


Looking at the trunk of the palm tree its like that every polygon uses the same part/whole texture. So it seems the model ur loading is missing the texure coordinates for the polygons. It don't know what tool ur using to create and export the models, but e.g. if u use Blender u have to explicitly enable texture coordinates when exporting to wavefront file format.

A complete exported model with normals, texture coordinates, vertices and faces should look like this (a simple cube):

v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000

vt 0.000000 0.000000
vt 0.000000 -1.000000
vt -1.000000 -1.000000
vt -1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000
vt 1.000000 0.000000
vt -1.000000 1.000000

vn 0.000000 0.000000 -1.000000
vn -1.000000 -0.000000 -0.000000
vn -0.000000 -0.000000 1.000000
vn -0.000001 0.000000 1.000000
vn 1.000000 -0.000000 0.000000
vn 1.000000 0.000000 0.000001
vn 0.000000 1.000000 -0.000000
vn -0.000000 -1.000000 0.000000

f 5/1/1 1/2/1 4/3/1
f 5/1/1 4/3/1 8/4/1
f 3/1/2 7/5/2 8/6/2
f 3/1/2 8/6/2 4/7/2
f 2/1/3 6/5/3 3/4/3
f 6/5/4 7/8/4 3/4/4
f 1/1/5 5/5/5 2/4/5
f 5/5/6 6/8/6 2/4/6
f 5/5/7 8/8/7 6/1/7
f 8/8/7 7/4/7 6/1/7
f 1/1/8 2/2/8 3/3/8
f 1/1/8 3/3/8 4/4/8

... the "vt" lines are the texture coordinates wich have to be exported from u modeling tool to get correct texturing.