如何使用P3D渲染器实现noSmooth()? [英] How can I achieve noSmooth() with the P3D renderer?

查看:226
本文介绍了如何使用P3D渲染器实现noSmooth()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用P3D渲染器使用PGraphics实例渲染基本的3D形状而没有任何混淆/平滑,但是noSmooth()似乎不起作用.

I'd like to render basic 3D shapes without any aliasing/smoothing with a PGraphics instance using the P3D renderer, but noSmooth() doesn't seem to work.

在OF中,我记得在纹理上调用setTextureMinMagFilter(GL_NEAREST,GL_NEAREST);.

In OF I remember calling setTextureMinMagFilter(GL_NEAREST,GL_NEAREST); on a texture.

什么是处理中的等价物?

What would be the equivalent in Processing ?

我尝试使用 PGL :

PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;
PGL.TEXTURE_MAG_FILTER = PGL.NEAREST;

但是我得到一个黑色图像. 如果我评论PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;,我可以看到渲染,但是它是插值的,不是很清晰.

but I get a black image as the result. If I comment PGL.TEXTURE_MIN_FILTER = PGL.NEAREST; I can see the render, but it's interpolated, not sharp.

这是我尝试过的一些基本测试草图:

Here'a basic test sketch with a few things I've tried:

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

(我也发布在处理论坛上,但到目前为止还没有运气)

(I've also posted on the Processing Forum, but no luck so far)

推荐答案

您实际上是在正确的轨道上.您只是将错误的值传递给textureSampling().

You were actually on the right track. You were just passing the wrong value to textureSampling().

至少可以说有点稀缺. 我决定使用反编译器来深入研究它,这导致我 Texture::usingMipmaps() . 在那里,我能够看到这些值及其反映的内容(在反编译的代码中).

Since the documentation on PGraphicsOpenGL::textureSampling() is a bit scarce to say the least. I decided to peak into it using a decompiler, which lead me to Texture::usingMipmaps(). There I was able to see the values and what they reflected (in the decompiled code).

2 = POINT
3 = LINEAR
4 = BILINEAR
5 = TRILINEAR

PGraphicsOpenGL的默认textureSampling5(TRILINEAR).

Where PGraphicsOpenGL's default textureSampling is 5 (TRILINEAR).

我后来也发现了关于问题的旧评论同样确认.

I also later found this old comment on an issue equally confirming it.

因此,要获取点/最近过滤,只需要在应用程序本身上调用noSmooth(),然后在PGraphics上调用textureSampling().

So to get point/nearest filtering you only need to call noSmooth() on the application itself, and call textureSampling() on your PGraphics.

size(320, 240, P3D);
noSmooth();

buffer = createGraphics(width/8, height/8, P3D);
((PGraphicsOpenGL) buffer).textureSampling(2);

因此,请考虑以上内容,并且仅包括用于绘制线条和为应用程序绘制buffer的代码.然后,得出以下预期结果.

So considering the above, and only including the code you used to draw the line and drawing buffer to the application. Then that gives the following desired result.

这篇关于如何使用P3D渲染器实现noSmooth()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆