Login  Register

OpenGL double precision issue

Posted by alicana on Jun 15, 2016; 2:00pm
URL: https://forum.jogamp.org/OpenGL-double-precision-issue-tp4036834.html

Hi all,

I have a problem with double precision when drawing lines.

X axis range is from 99.9999 to 100.001. So, I set ortho as
gl.glOrtho(99.9999d, 100.001d, -5, 200, -10, 10);

Example input data:
- X-axis value is increasing 1.25e-7 for every single point

Display callback:
public void display(GLAutoDrawable drawable) {
	GL2 gl = drawable.getGL().getGL2();
	gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	gl.glBegin(GL2.GL_LINE_STRIP);
	
	int j = -5;
	double offset = (0.001 / 8000);
	for (int i = 0; i < 8000; i++) {
		int y = j++;
		double x = 100 + (offset * i);
			gl.glVertex2d( x, y);
                if (j == 200) {
			j = -5;
		}
	}

	gl.glEnd();

}

Expected output:



But I have following as a result:



Any advice ?