0

I'm trying to set some line loops to 1 pixel width, but I always get some antialiasing effect when the width number is an odd number

Here some example code:

                    gl2.glLineWidth(1.0f); 
                    gl2.glBegin(GL2.GL_LINES); 
                        gl2.glVertex2i(-10, 0); 
                        gl2.glVertex2i(-10, 10); 
                    gl2.glEnd(); 

                    gl2.glLineWidth(2.0f); 
                    gl2.glBegin(GL2.GL_LINES); 
                        gl2.glVertex2i(-10, -10); 
                        gl2.glVertex2i(-10, 0); 
                    gl2.glEnd(); 

                    gl2.glLineWidth(3.0f); 
                    gl2.glBegin(GL2.GL_LINES); 
                        gl2.glVertex2i(-10, -20); 
                        gl2.glVertex2i(-10, -10); 
                    gl2.glEnd(); 

                    gl2.glLineWidth(4.0f); 
                    gl2.glBegin(GL2.GL_LINES); 
                        gl2.glVertex2i(-10, -30); 
                        gl2.glVertex2i(-10, -20); 
                    gl2.glEnd(); 

                    gl2.glLineWidth(5.0f); 
                    gl2.glBegin(GL2.GL_LINES); 
                        gl2.glVertex2i(-10, -40); 
                        gl2.glVertex2i(-10, -30); 
                    gl2.glEnd(); 

produces this (in order from up to down):

http://dl.dropbox.com/u/1401029/LineWidth.png

gl2.glIsEnabled(GL2.GL_LINE_SMOOTH) returns false and gl2.glhint doesnt seem to affect it at all

any ideas?

elect
  • 6,765
  • 10
  • 53
  • 119
  • What is your projection matrix? – Luca May 21 '12 at 09:50
  • Ciao Luca :) It's the identity one gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); // map a 2D bild width*height on OpenGL glu.gluOrtho2D(-width/2, (width+1)/2, -(height+1)/2, height/2); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); – elect May 23 '12 at 07:30

2 Answers2

1

According to the documentation, JOGL defaults to MSAAx2.

setNumSamples(1) at init time should do the trick, but you'll loose antialiasing completely. What about calling glLineWidth with NumSamples times the desired value ?

Calvin1602
  • 9,413
  • 2
  • 44
  • 55
1

Before it need to be clarified that OpenGL specification is not pixel-exact. Indeed you cannot pretend to have the very same result on every OpenGL implementation.

However, on mostly controllable input values the polygon rasterization give stable results on different implementations.

From you comment, this is how you setup the modelview/projection matrix:

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity(); // map a 2D bild width*height on OpenGL
glu.gluOrtho2D(-width/2, (width+1)/2, -(height+1)/2, height/2);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();

I don't know width or height types and values, not even the viewport... but to give you this answer, I assume that you have a viewport width x height, where width and height are the variables that you use in your code, and their values are set to 100.

Indeed you will suggest you to setup your projection matrix in this way:

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity(); // map a 2D bild width*height on OpenGL
glu.gluOrtho2D(-width/2, +width/2, -height/2, height/2);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();

To get most scalability I suggest you to append the following modelview matrix translation:

gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslate(0.376, 0.376, 0.0);

I don't know the particoulars of the java OpenGL bindings, but follow also what Calvin1602 have said (disable multisampling).

Community
  • 1
  • 1
Luca
  • 11,646
  • 11
  • 70
  • 125