2011-07-18 17 views
1

我目前在JOGL應用程序中遇到問題,其中創建的紋理在縮放時顯示爲斑點。 IDE是Netbeans 6.9.1。JOGL過程紋理在縮放時會發生斑點

我會詳細解釋我的紋理創建過程。

首先我做:

gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1); 
    gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1); 
    gl.glPixelStorei(gl.GL_UNPACK_SKIP_PIXELS, 0); 
    gl.glPixelStorei(gl.GL_UNPACK_SKIP_ROWS, 0); 

    BufferedImage buff = ByteBuffer_To_BufferedImage(ByteBuffer.wrap(data)); 
    _list_of_textures[count] = TextureIO.newTexture(buff, true); 

...其中, 「數據」 是一個字節數組。

我的方法 「ByteBuffer_To_BufferedImage()」 執行以下操作:

int p = _width* _height* 4; 
    int q; // Index into ByteBuffer 
    int i = 0; // Index into target int[] 
    int w3 = _width* 4; // Number of bytes in each row 
    for (int row = 0; row < _width; row++) { 
p -= w3; 
q = p; 
for (int col = 0; col < _width; col++) { 
    int iR = data.get(q++)*2;  //127*2 ~ 256. 
    int iG = data.get(q++)*2;  
    int iB = data.get(q++)*2;  
    int iA = data.get(q++)*2; 
    pixelInts[i++] = 
    ((iA & 0x000000FF) << 24) | 
     ((iR & 0x000000FF) << 16) | 
    ((iG & 0x000000FF) << 8) | 
     (iB & 0x000000FF); 
} 
    } 

    // Create a new BufferedImage from the pixeldata. 
    BufferedImage bufferedImage = 
new BufferedImage(_width, _height, 
      BufferedImage.TYPE_INT_ARGB); 
    bufferedImage.setRGB(0, 0, _width, _height, 
      pixelInts, 0, _width); 
    return bufferedImage; 

...基本上訂單的RGBA顏色方案的字節數。

當我畫畫,我這樣做是這樣的...

_textures[c].enable(); 
    _textures[c].bind(); 
    gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE); 
    TextureCoords coords = _textures[c].getImageTexCoords(); 

    gl.glBegin(GL.GL_QUADS); 

    gl.glTexCoord2f(coords.left(), coords.top()); 
    gl.glVertex3f(...); // Top Left 

    gl.glTexCoord2f(coords.right(), coords.top()); 
    gl.glVertex3f(...); // Top Right 

    gl.glTexCoord2f(coords.right(), coords.bottom()); 
    gl.glVertex3f(...); // Bottom Right 

    gl.glTexCoord2f(coords.left(), coords.bottom()); 
    gl.glVertex3f(...); // Bottom Left 

    gl.glEnd(); 
    _textures[c].disable(); 

而且僅此而已。我知道你可以用javax.media.opengl.GLCapabilities設置一些選項,但我不確定它是否有幫助。

有沒有人見過這種行爲或知道它的原因?另外,如果任何人都可以建議給我的字節數組創建紋理的替代方法,我也會嘗試。

編輯:

我回去,並試圖用 「Java的少」 的OpenGL創建的紋理。

gl.glGenTextures(1, _textures,layer); 
    gl.glBindTexture(gl.GL_TEXTURE_2D, _textures[count]); 
    gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR); 
    gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR); 
    gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, 
      _width, _height, 0, 
      GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap(data)); 

這產生相同的結果(像素是斑點而不是矩形)。

編輯:

最後的後我做使我質疑雙線性過濾正在做。這確實成了問題。

如果您需要保持精確的像素值,您需要使用GL_NEAREST(根本不需要濾波/插值)。之前我遇到過這個問題,並且實際上很快就沒有記住這個解決方案,所以覺得很愚蠢。

+0

正確的輸出是什麼樣的? – genpfault

+0

下面是一個正確輸出的鏈接:http://imageshack.us/photo/my-images/832/specklefix.png/ – viperld002

回答

1

您是否嘗試過GL_NEAREST而不是GL_LINEAR?

+0

是的,你發現就像我那樣做了。感謝您的答覆! – viperld002