我目前在我的JOGL应用程序中遇到问题,我正在创建的纹理在缩放时显示为blob。 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);
...其中“data”是一个字节数组。
我的方法“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
(根本不进行过滤/插值)。我以前遇到过这个问题,并且因为没有及早记住解决方案而感到非常愚蠢。
答案 0 :(得分:1)
您是否尝试过GL_NEAREST而不是GL_LINEAR?