2017-03-28 53 views
1

我想使用P3D渲染器渲染基本的3D形狀而沒有任何別名/平滑的PGraphics實例,但noSmooth()似乎不起作用。如何使用P3D渲染器實現noSmooth()?

在OF我記得在紋理上叫setTextureMinMagFilter(GL_NEAREST,GL_NEAREST);

什麼是處理等效?

我試圖用PGL

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

但我得到一個黑色的圖像作爲結果。 如果我評論PGL.TEXTURE_MIN_FILTER = PGL.NEAREST;我可以看到渲染,但是它是內插的,而不是尖銳的。

Here'a基本的測試草圖有幾件事我已經試過:

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,但至今沒有運氣)

+1

如果我沒有記錯,然後'buffer.noSmooth()'不會如預期。但是調用'image()'完全忽略'noSmooth()'。 – Vallentin

+0

@Vallentin感謝您的提示。我的直覺是我可能需要獲得對PGL紋理的引用,綁定它,然後調用像'''pgl.getTexParameteriv(PGL.TEXTURE_2D,PGL.TEXTURE_MIN_FILTER ...'''或者類似的東西? –

回答

2

你實際上是在正確的軌道上。你只是將錯誤的值傳遞給textureSampling()

由於有關PGraphicsOpenGL::textureSampling() 的文檔至少有點不足。 我決定使用一個反編譯器進入它的頂點,這導致我到 Texture::usingMipmaps()。 在那裏我能夠看到值和它們反映的內容(在反編譯的代碼中)。

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

哪裏PGraphicsOpenGL的默認textureSampling5(三線性)。

我後來也發現this old comment on an issue同樣證實了它。

因此,要獲得點/最近你過濾只需要調用noSmooth()於應用本身,並在您PGraphicstextureSampling()

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

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

因此,考慮上述情況,並且只包括你用來畫線的代碼和繪圖buffer應用程序。然後,給出以下所需的結果。

+1

真棒!我還注意到''''''beginDraw()''''後面調用了textureSampling,它沒有任何效果。 –