Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 缩放时,JOGL程序纹理会斑点_Java_Opengl_Graphics_Jogl - Fatal编程技术网

Java 缩放时,JOGL程序纹理会斑点

Java 缩放时,JOGL程序纹理会斑点,java,opengl,graphics,jogl,Java,Opengl,Graphics,Jogl,我目前在我的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

我目前在我的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_BuffereImage()”执行以下操作:

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;
就这样。我知道您可以使用javax.media.opengl.gl功能设置一些选项,但我不确定这是否有帮助

以前有没有人见过这种行为或知道其原因?另外,如果有人能根据我的字节数组建议一种纹理创建的替代方法,我也会尝试一下

编辑:

我回去尝试使用“无java”OpenGL创建纹理

这会产生相同的结果(像素是斑点而不是矩形)

编辑:

我的最后一篇帖子让我对正在进行的双线性过滤提出了质疑。这确实是问题所在


如果需要保持精确的像素值,则需要使用
GL_NEAREST
(完全不进行过滤/插值)。我以前遇到过这个问题,实际上因为没能更快地记住解决方案而感到非常愚蠢。

你试过GL_NEAREST而不是GL_LINEAR吗?

你试过GL_NEAREST而不是GL_LINEAR吗?

正确的输出是什么样子的?这里有一个正确输出的链接:正确的输出是什么样子?这里有一个正确输出的链接输出:是的,你和我一样明白了。谢谢你的回复!是的,你和我一样明白了。谢谢你的回复!
    _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();
    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));