I've rendered a plain white circle on on my device, but it proportionately stretches it across my device based on the screen dimensions. Scouring around 2D examples & possible answers, I have not been able scale it correctly.
My Renderer class:
@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
float scaleX = (float) width / Screen.getScreenWidthPx();
float scaleY = (float) height / Screen.getScreenHeightPx();
final int vpWidth = (int)(Screen.getScreenWidthPx() * scaleX);
final int vpHeight = (int)(Screen.getScreenHeightPx() * scaleY);
GLES20.glViewport(0, 0, vpWidth, vpHeight);
mCam.setProjection(Screen.getScreenWidthPx(), Screen.getScreenHeightPx());
}
My Camera class:
public void setProjection(float width, float height)
{
final float ratio = width / height;
Matrix.orthoM(mProjection, 0, 0, width, height, 0, -1, 1);
}
Vertex Shader:
private String mVSCode =
"attribute vec4 vPosition;" +
"uniform float sWidth;" +
"uniform float sHeight;" +
"void main() {" +
"gl_Position = vPosition;" +
"}";
Result: