I have been coding a tile-based engine to help me learn OpenGL and I am pleased with what I have come up with so far. I have a program that can load tileset images and build a tiled layer from an index array.
My question is how are the coordinates set up? I assume this is with the LookAt matrix? I have a variable called quadSize, which at the moment is set to 0.3f which seems really tiny.
Also I am trying to get my sprite system to work. I loaded in a image, and have all pixels I don’t want drawn set to R=0,G=255,B=255. The fragment shader looks like this:
precision mediump float;
varying vec2 vTexCoord;
uniform sampler2D sSampler;
void main() {
vec4 fragment = texture2D(sSampler, vTexCoord)
if (fragment.r == 0.0 && fragment.g >= 1.0 && fragment.b >= 1.0)
discard;
gl_FragColor = fragment;
}
90% of the unwanted data is removed, but it seems OpenGL is anti-aliasing or blurring the texture, causing the pixels at the edge to not by exactly 0,255,255.
Here is the texture loading part:
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture);
GLES20.glTexParameterf( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameterf( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
GLES20.GL_CLAMP_TO_EDGE);
Bitmap testTexture = BitmapFactory.decodeResource(context.getResources(), R.drawable.sprite1);
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, testTexture, 0);