Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOGL texture not working

I'm trying to fill a torus texture of wood, but leaves only one color:

img http://dl.dropbox.com/u/70996029/Screenshots/Screenshot-2012-04-12_01.28.44.png

The image is 128x128 png. What am I doing wrong?

public void init(GLAutoDrawable drawable) {
        gl = drawable.getGL().getGL2();

        gl.glEnable(GL2.GL_DEPTH_TEST);
        gl.glDepthFunc(GL2.GL_LESS);

        gl.glEnable(GL2.GL_LIGHTING);
        gl.glEnable(GL2.GL_LIGHT0);

        gl.glMatrixMode(GL2.GL_PROJECTION);
        gl.glOrtho(-17.0, 17.0, -17.0, 17.0, -17.0, 17.0);
        gl.glMatrixMode(GL2.GL_MODELVIEW);
    }
public void display(GLAutoDrawable drawable)
    {
        gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
        float mat_diffuse[] = { 0.5f, 0.5f, 0.8f, 1.0f };
        gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_DIFFUSE, mat_diffuse, 0);
        glut.glutSolidTorus(2, 5, 80, 80);

        gl.glRotatef(90, 1, 0, 0);
        gl.glTranslatef(5, 0, 0);

        Texture texture = null;

        try {
            texture = TextureIO.newTexture(new File("D:\\Program Files\\eclipse\\projects\\rotation OGL\\src\\wood.png"), true);
            texture.setTexParameterf(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
            texture.setTexParameterf(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
        } catch (Exception e) {
            e.printStackTrace();
        }
        gl.glEnable(GL2.GL_TEXTURE_2D);

        texture.bind(gl);
        texture.enable(gl);

        glut.glutSolidTorus(2, 5, 80, 80);

        texture.disable(gl);
    }
like image 972
mmatviyiv Avatar asked Sep 04 '26 08:09

mmatviyiv


1 Answers

Try generating some texture coordinates for your geometry.

glutSolidTorus() does not generate any for you.

like image 59
genpfault Avatar answered Sep 06 '26 22:09

genpfault



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!