JOGL mipmap和纹理闪烁 [英] JOGL mipmaps and texture shimmering
问题描述
在我的OpenGL 2场景中,我有一堵墙和一块砖纹理,无论设置什么,它都会不断闪烁和闪烁.当我放大近距离(并可以清楚地看到纹理)时,闪烁和闪烁便停止了.但是当我放大并在场景中移动时,闪烁和闪烁非常明显.这是砖墙的纹理代码:
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER,GL2.GL_NEAREST);
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER,GL2.GL_LINEAR);
gl.glGenerateMipmap(GL2.GL_TEXTURE_2D);
brickwall.enable(gl);
brickwall.bind(gl);
//...
brickwall.disable(gl);
根据我搜索过的内容,看来这是mipmapping解决的问题.但是我的问题是,这是怎么做到的?我是否需要为2个大小的图像的所有各种功能创建,加载和设置参数?谁能给我一个使用不会闪烁和微距缩放以及在场景中移动的mipmap加载和显示JOGL2纹理的示例吗?
您正在使用glGenerateMipmap生成mipmap链,但没有设置适当的MIN过滤器:
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER,GL2.GL_LINEAR_MIPMAP_LINEAR);
* MIPMAP *过滤器使用mipmap,其他纹理过滤器则不使用.
I've a wall and a brick texture in my OpenGL 2 scene that keeps shimmering and flashing no matter what I set. When I'm zoomed in close (and can see clearly the texture), then the flashing and shimmering stops. But when I'm zoomed out and moving around the scene, the flashing and shimmering is very pronounced. This is the texture code for the brick wall:
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER,GL2.GL_NEAREST);
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER,GL2.GL_LINEAR);
gl.glGenerateMipmap(GL2.GL_TEXTURE_2D);
brickwall.enable(gl);
brickwall.bind(gl);
//...
brickwall.disable(gl);
From what I've googled, it seems that this is a problem that mipmapping solves. But my question is, how does one do this? Do I have to create, load and set parameters for all the various power of 2 sized images? Can anyone give me an example for loading and displaying a JOGL2 texture using mipmaps that won't flicker and shimmer zooming and moving about a scene?
You are generating the mipmap chain with glGenerateMipmap, but you didn't set an appropiate MIN filter:
brickwall.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER,GL2.GL_LINEAR_MIPMAP_LINEAR);
The *MIPMAP* filters use mipmaps, the other texture filters don't.
这篇关于JOGL mipmap和纹理闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!