Lights, Anti-aliasing

Hello!

I have two questions. The first one is about lights, I do the following to enable lighting:


        // Setting light
        float[] lightPos = {(float)cameraFromX, (float)cameraFromY, (float)cameraFromZ, 1};
        float[] lightAmbient = {0.1f, 0.1f, 0.1f, 1.0f};
        float[] lightDiffuse = {1.0f, 1.0f, 1.0f, 1.0f};
        // Set light parameters.
        gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, lightAmbient, 0);
        gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, lightDiffuse, 0);
        gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightPos, 0);
        gl.glEnable(GL.GL_LIGHT1);
        gl.glEnable(GL.GL_LIGHTING);

Now when I draw something, I cant change the color using glColor3f, everything turns into white color! I am using GL_LINES and GL_QUADS.

About the anti-aliasing, I draw a 2D rectangle:


        gl.glBegin(GL.GL_QUADS);
        gl.glNormal3f( 0.0f, 0.0f, 1.0f);
        gl.glVertex3d(-data.width / 2, -data.height / 2, 0);
        gl.glVertex3d(data.width / 2, -data.height / 2, 0);
        gl.glVertex3d(data.width / 2, data.height / 2, 0);
        gl.glVertex3d(-data.width / 2, data.height / 2, 0);
        gl.glEnd();

And I use for anti-aliasing, on the init method:


        gl.glEnable(GL.GL_LINE_SMOOTH);
        gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);

I change the camera angle, using gluLookAt and this is the result, I dont think it is much anti-aliased :stuck_out_tongue:

I have another question, with glu functions I can draw a sphere easily, isnt there a half-sphere method?

Thank you!

Totally puzzled after your post. First, how you generated that pic with a quad isn’t clear. Are the aliased edges the edge of a quad, and you drew 2 quads? If so then (as usual) for edge AA, you need something like MSAA. Allocate your window in a multisample visual, glEnable( GL_MULTISAMPLE ), and draw!

Second I’m not sure why you’d expect LINE_SMOOTH to affect filled QUAD drawing.

Also, what hardware are you on where perspective-correct interpolation isn’t the default?

Google “GLU half sphere” and you’ll be pointed directly to a tutorial that does just that. Essentially it uses the GLU sphere function and a clipping plane.

If you want to cap it you can use a gluDisk.

Sorry, I am starting at OpenGL and pretty much Ive done so far is copy and paste code, then run, then try to understand the code. I could not understand what you meant, could you reformulate?
I will search about the clipping thing, thank you.
What about the light? That 2D rect was supposed to be yellow :stuck_out_tongue:

He meant that GL_LINE_SMOOTH is only for … line.
For anything else, use this :

gl.glEnable(GL.GL_POLYGON_SMOOTH);

Then GL_PERSPECTIVE_CORRECTION_HINT has nothing to do with any king of antialiasing.

The *_SMOOTH is not really the same as “real antialiasing” methods such as multi sample anti aliasing (MSAA) or full scene anti aliasing (FSAA).
But SMOOTH is easy to enable. The main downside is it does not work well with overlapping geometry and/or translucency.

Regarding multisampling, check out this tutorial:

It’s very similar on Linux:

What about the light? That 2D rect was supposed to be yellow :stuck_out_tongue:

You haven’t actually shown us all the relevant code (e.g. how you’re setting the material properties for your vertices, LIGHT0’s properties, etc.) but your LIGHT1 diffuse is bright white and your LIGHT1 ambient is dim grey. There’s no evidence I can see why yellow should be the result.

I forgot to call gl.glEnable(GL.GL_COLOR_MATERIAL); :p, not the colors are ok.

About the anti-aliasing, I tried the multi-sampling, but it didnt do much progress:

Used:

caps = new GLCapabilities();
caps.setSampleBuffers(true); // Enable multisampling
caps.setNumSamples(2);
canvas = new GLCanvas(caps);

Your screenshot does look like a 2-sample MSAA.
Try 4 or 8 samples if you want better precision.

With 4, thinks looks better, with 8 it does nothing. If you open the screenshoot in the real size you will notice that they are a little different.

Your hardware does not support 8 samples.
It defaults to no AA if you try.