开发者

JOGL shimmering / texture flickering problem

i got a problem with my textures in a JOGL program. the textures i draw onto a cube which is taken from a displaylist are flickering. here is a video which shows the problem: http://www.youtube.com/watch?v=nIj3b_Rs7Nw (sorry for the bad video, i don't know what went wrong at the beginning) first i thought it would be an anti-alising problem, but i used smoother textures and the problem remains. then i enabled mipmapping on the textures, but with no luck. the result is always the same.

here is the code i first used to get textures ready. this is without mipmapping.

final int[] tmp = new int[1];
    gl.glGenTextures(1, tmp, 0);
    id = tmp[0];

    BufferedImage bufferedImage = null;

    int width = 0;
    int height = 0;
    try {
        bufferedImage = ImageIO.read(new File(filename));
        width = bufferedImage.getWidth();
        height = bufferedImage.getHeight();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, 4, null);
    ComponentColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] {
            8, 8, 8, 8 }, true, false, ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    BufferedImage dukeImg = new BufferedImage(colorModel, raster, false, null);

    Graphics2D g = dukeImg.createGraphics();
    g.drawImage(bufferedImage, null, null);
    DataBufferByte dukeBuf = (DataBufferByte) raster.getDataBuffer();
    byte[] dukeRGBA = dukeBuf.getData();
    ByteBuffer bb = ByteBuffer.wrap(dukeRGBA);
    bb.position(0);
    bb.mark();

    gl.glBindTexture(GL2.GL_TEXTURE_2D, id);
    gl.glPixelStorei(GL2.GL_UNPACK_ALIGNMENT, 1);
    gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
    gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
    gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
    gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
    gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);

    gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_RGBA, width, height, 0, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, bb);

    ...
    gl.glBindTexture(GL2.GL_TEXTURE_2D, id);

then i decided to use the build in JOGL texture class. the setTexParameteri() calls i took fro开发者_StackOverflowm this post JOGL mipmaps and texture shimmering , but they didn't solved the problem.

try {
        TextureData textureData = TextureIO.newTextureData(drawable.getGLProfile(), new File(
            "data/images/Kachel1.png"), true, TextureIO.PNG);
        Texture tile = TextureIO.newTexture(textureData);

        tile.setTexParameteri(GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
        tile.setTexParameteri(GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
        tile.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
        tile.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_LINEAR);
        gl.glGenerateMipmap(GL2.GL_TEXTURE_2D);
    }
    catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

so now i don't know what to do to get rid of the flickering. any suggestions?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜