【问题标题】:JOGL procedural textures are blobbed when scaledJOGL 程序纹理在缩放时会出现斑点
【发布时间】:2011-07-18 07:13:13
【问题描述】:

我目前在我的 JOGL 应用程序中遇到问题,我正在创建的纹理在缩放时显示为斑点。 IDE 是 Netbeans 6.9.1。

我将详细解释我的纹理创建过程。

首先我在做:

    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-less”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(根本没有过滤/插值)。我以前遇到过这个问题,实际上因为没有早点记住解决方案而感到非常愚蠢。

【问题讨论】:

标签: java opengl graphics jogl


【解决方案1】:

您是否尝试过 GL_NEAREST 而不是 GL_LINEAR?

【讨论】:

  • 是的,你想通了,就像我一样,哈哈。感谢您的回复!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-28
  • 2013-07-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多