【发布时间】:2011-04-27 02:49:31
【问题描述】:
我正在编写一个小应用程序,目前它会生成一个随机的纹理贴图。
我将此地图绘制为一组 10 x 15 的“四边形”,它们实际上都是三角形条带。我使用“地图”来获取一个 int,然后将其作为该正方形在 textureAtlas 中的纹理位置。所以例如 0 是左下角的“瓷砖”。该图集为 128 x 128,分为 32 个像素的图块。
但是,我似乎得到了一些奇怪的伪影,其中一个瓷砖的纹理正在蔓延到下一个瓷砖。我想知道它是否是图像本身,但据我所知,像素正是它们应该在的位置。然后我查看了我指定的纹理坐标,但它们看起来都很精确(0.0、0.25、0.5、0.75、1.0 - 将其分成我期望的 4 行和列)。
奇怪的是,如果我在模拟器上运行它,我没有得到任何工件。
我是否缺少会导致 1 个像素出血的设置?它似乎也只是垂直的 - 这可能与我在手机上“拉伸”该方向的图像有关,因为手机的屏幕在该方向上比正常大。
我像这样加载纹理:
//Get a new ID
int id = newTextureID(gl);
//We will need to flip the texture vertically
Matrix flip = new Matrix();
flip.postScale(1f, -1f);
//Load up and flip the texture
Bitmap temp = BitmapFactory.decodeResource(context.getResources(), resource);
//Store the widths for the texturemap
int width = temp.getWidth();
int height = temp.getHeight();
Bitmap bmp = Bitmap.createBitmap(temp, 0, 0, width, height, flip, true);
temp.recycle();
//Bind
gl.glBindTexture(GL10.GL_TEXTURE_2D, id);
//Set params
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR);
//Push onto the GPU
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
TextureAtlas atlas = new TextureAtlas(id, width, height, tileSize);
return atlas;
然后我像这样渲染它:
gl.glBindTexture(GL10.GL_TEXTURE_2D, currentAtlas.textureID);
//Enable the vertices buffer for writing and to be used during our rendering
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
//Specify the location and data format of an array of vertex coordinates to use
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
//Enable the texture buffer
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);
我会拍照,但我不确定如何从手机中获取屏幕截图...
如果有人知道我如何捕获当前帧并将其放入文件中,如果它有助于解释发生了什么,我会这样做!
期待您的回复。
编辑:这是一个屏幕截图 - 请注意,我以横向运行应用程序,但上限是纵向的。还请原谅可怕的纹理:D 它们只是一个占位符/乱七八糟的东西。
【问题讨论】:
-
虽然我无法帮助您解决这个问题,但您可以使用 SDK 工具目录中的程序
ddms对设备进行截图(ctrl-s)。 -
谢谢!我知道人们必须有一种方式来做到这一点。看起来也是一个普遍有用的工具。
标签: android opengl-es render textures