JOGL纹理不起作用

时间:2012-04-11 22:43:54

标签: java opengl colors textures jogl

我正在尝试填充木质的圆环纹理,但只留下一种颜色:

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

图像为128x128 png。我做错了什么?

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);
    }

1 个答案:

答案 0 :(得分:1)

尝试使用generating some texture coordinates几何体。

glutSolidTorus()不会为您生成任何内容。