如何使用 P3D 渲染器实现 noSmooth()?
How can I achieve noSmooth() with the P3D renderer?
我想在没有任何 aliasing/smoothing 的情况下使用 P3D 渲染器使用 PGraphics 实例渲染基本 3D 形状,但 noSmooth() 似乎不起作用。
在 OF 中,我记得在纹理上调用 setTextureMinMagFilter(GL_NEAREST,GL_NEAREST);
。
Processing 中的等价物是什么?
我尝试使用 PGL:
PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;
PGL.TEXTURE_MAG_FILTER = PGL.NEAREST;
但我得到的是黑色图像。
如果我评论 PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;
我可以看到渲染,但它是插值的,不清晰。
这是我尝试过的一些基本测试草图:
PGraphics buffer;
PGraphicsOpenGL pgl;
void setup() {
size(320, 240, P3D);
noSmooth();
//hint(DISABLE_TEXTURE_MIPMAPS);
//((PGraphicsOpenGL)g).textureSampling(0);
//PGL pgl = beginPGL();
//PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;
//PGL.TEXTURE_MAG_FILTER = PGL.NEAREST;
//endPGL();
buffer=createGraphics(width/8, height/8, P3D);
buffer.noSmooth();
buffer.beginDraw();
//buffer.hint(DISABLE_TEXTURE_MIPMAPS);
//((PGraphicsOpenGL)buffer).textureSampling(0);
PGL bpgl = buffer.beginPGL();
//PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;//commenting this back in results in a blank buffer
PGL.TEXTURE_MAG_FILTER = PGL.NEAREST;
buffer.endPGL();
buffer.background(0);
buffer.stroke(255);
buffer.line(0, 0, buffer.width, buffer.height);
buffer.endDraw();
}
void draw() {
image(buffer, 0, 0, width, height);
}
(我也posted on the Processing Forum,但到目前为止运气不好)
您实际上走在了正确的轨道上。您只是将错误的值传递给 textureSampling()
.
自 PGraphicsOpenGL::textureSampling()
上的文档以来
至少可以说有点稀缺。
我决定使用反编译器深入研究它,这导致我
Texture::usingMipmaps()
。
在那里我能够看到这些值及其反映的内容(在反编译代码中)。
2 = POINT
3 = LINEAR
4 = BILINEAR
5 = TRILINEAR
其中 PGraphicsOpenGL
的默认值 textureSampling
是 5
(三线性)。
我后来也发现this old comment on an issue同样证实了。
因此,要获得 point/nearest 过滤功能,您只需在应用程序本身上调用 noSmooth()
,然后在您的 PGraphics
.
上调用 textureSampling()
size(320, 240, P3D);
noSmooth();
buffer = createGraphics(width/8, height/8, P3D);
((PGraphicsOpenGL) buffer).textureSampling(2);
因此考虑到上述情况,并且仅将您用来绘制线条和绘图的代码包含在应用程序中 buffer
。然后给出以下期望的结果。
我需要将 GL_LINEAR 和 GL_NEAREST 与一个着色器组合在一起,所以 ((PGraphicsOpenGL) buffer).textureSampling(2);
是别无选择。
这是一些挖掘,但这对我有用:
PGL pgl = beginPGL();
Texture ascii_map_tex = ((PGraphicsOpenGL)g).getTexture(ascii_map);
pgl.bindTexture(PGL.TEXTURE_2D, ascii_map_tex.glName);
pgl.texParameteri(PGL.TEXTURE_2D, PGL.TEXTURE_MIN_FILTER, PGL.NEAREST);
pgl.texParameteri(PGL.TEXTURE_2D, PGL.TEXTURE_MAG_FILTER, PGL.NEAREST);
pgl.bindTexture(PGL.TEXTURE_2D, 0);
endPGL();
我想在没有任何 aliasing/smoothing 的情况下使用 P3D 渲染器使用 PGraphics 实例渲染基本 3D 形状,但 noSmooth() 似乎不起作用。
在 OF 中,我记得在纹理上调用 setTextureMinMagFilter(GL_NEAREST,GL_NEAREST);
。
Processing 中的等价物是什么?
我尝试使用 PGL:
PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;
PGL.TEXTURE_MAG_FILTER = PGL.NEAREST;
但我得到的是黑色图像。
如果我评论 PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;
我可以看到渲染,但它是插值的,不清晰。
这是我尝试过的一些基本测试草图:
PGraphics buffer;
PGraphicsOpenGL pgl;
void setup() {
size(320, 240, P3D);
noSmooth();
//hint(DISABLE_TEXTURE_MIPMAPS);
//((PGraphicsOpenGL)g).textureSampling(0);
//PGL pgl = beginPGL();
//PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;
//PGL.TEXTURE_MAG_FILTER = PGL.NEAREST;
//endPGL();
buffer=createGraphics(width/8, height/8, P3D);
buffer.noSmooth();
buffer.beginDraw();
//buffer.hint(DISABLE_TEXTURE_MIPMAPS);
//((PGraphicsOpenGL)buffer).textureSampling(0);
PGL bpgl = buffer.beginPGL();
//PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;//commenting this back in results in a blank buffer
PGL.TEXTURE_MAG_FILTER = PGL.NEAREST;
buffer.endPGL();
buffer.background(0);
buffer.stroke(255);
buffer.line(0, 0, buffer.width, buffer.height);
buffer.endDraw();
}
void draw() {
image(buffer, 0, 0, width, height);
}
(我也posted on the Processing Forum,但到目前为止运气不好)
您实际上走在了正确的轨道上。您只是将错误的值传递给 textureSampling()
.
自 PGraphicsOpenGL::textureSampling()
上的文档以来
至少可以说有点稀缺。
我决定使用反编译器深入研究它,这导致我
Texture::usingMipmaps()
。
在那里我能够看到这些值及其反映的内容(在反编译代码中)。
2 = POINT
3 = LINEAR
4 = BILINEAR
5 = TRILINEAR
其中 PGraphicsOpenGL
的默认值 textureSampling
是 5
(三线性)。
我后来也发现this old comment on an issue同样证实了。
因此,要获得 point/nearest 过滤功能,您只需在应用程序本身上调用 noSmooth()
,然后在您的 PGraphics
.
textureSampling()
size(320, 240, P3D);
noSmooth();
buffer = createGraphics(width/8, height/8, P3D);
((PGraphicsOpenGL) buffer).textureSampling(2);
因此考虑到上述情况,并且仅将您用来绘制线条和绘图的代码包含在应用程序中 buffer
。然后给出以下期望的结果。
我需要将 GL_LINEAR 和 GL_NEAREST 与一个着色器组合在一起,所以 ((PGraphicsOpenGL) buffer).textureSampling(2);
是别无选择。
这是一些挖掘,但这对我有用:
PGL pgl = beginPGL();
Texture ascii_map_tex = ((PGraphicsOpenGL)g).getTexture(ascii_map);
pgl.bindTexture(PGL.TEXTURE_2D, ascii_map_tex.glName);
pgl.texParameteri(PGL.TEXTURE_2D, PGL.TEXTURE_MIN_FILTER, PGL.NEAREST);
pgl.texParameteri(PGL.TEXTURE_2D, PGL.TEXTURE_MAG_FILTER, PGL.NEAREST);
pgl.bindTexture(PGL.TEXTURE_2D, 0);
endPGL();