I am very new to Open GL. My motto is to create freehand drawing using open GL.
This I am trying to achieve through connecting vertices on Drag. My problem is as soon I tap anywhere on screen a line is drawn from center os screen to that point. I am not able to figure out why? Please help.
This is what I am doing to draw :
@Override
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
glUniform4f(uColorLocation, 1.0f, 0.0f, 0.0f, 1.0f);
vertexData.put(toFloatarray(points));
vertexData.clear();
for (int i = last_size; i < points.size(); i++) {
glDrawArrays(GL_LINES, i , 2);
last_size = points.size();
}
}
I know for loop is not the best way and this is the issue but I am not able to get over it.
EDIT:
This is how I am adding points to array
public void handleTouchDrag(float normalizedX, float normalizedY) {
points.add(normalizedX);
points.add(normalizedY);
}
where :
final float normalizedX = (event.getX() / (float) v.getWidth()) * 2 - 1;
final float normalizedY = -((event.getY() / (float) v.getHeight()) * 2 - 1);