What is causing these visual artifacts on my OpenGL sprites?
Posted
by
Amplify91
on Game Development
See other posts from Game Development
or by Amplify91
Published on 2011-11-22T07:30:52Z
Indexed on
2011/11/22
10:29 UTC
Read the original article
Hit count: 290
What could be the cause of the defects in my characters sprite? I am using OpenGL ES 2.0. I draw my sprites in a sprite batch that uses UV coordinates from one large texture atlas. If you look around the character' edges, you'll see two noticeable problems:
The invisible alpha background is not invisible, but shows a strange static-like background.
There are unwanted streaks where the character nears the edge of the frame (but only in some frames of the animation, this happened to be one of them).
Any idea what could be causing these? I will provide related code if asked for, but I'll try to avoid just dumping the entire project and expecting someone to look through it all.
EDIT: Here's a bit of code:
This is how I generate my UV coordinates:
private float[] createFrameUV(int frameWidth, int frameHeight, int x, int y){
float[] uv = new float[4];
if(numberOfFrames>1){
float width = (float)frameWidth / (float)mBitmap.getWidth();
float height = (float)frameHeight / (float)mBitmap.getHeight();
float u = (float)x / (float)mBitmap.getWidth();
float v = (float)y / (float)mBitmap.getHeight();
uv[0] = u;
uv[1] = v;
uv[2] = u + width;
uv[3] = v + height;
}else{
uv[0] = 0f;
uv[1] = 0f;
uv[2] = 1f;
uv[3] = 1f;
}
return uv;
}
These are some OpenGL settings:
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
© Game Development or respective owner