PDA

View Full Version : Lights, Anti-aliasing



Brunooo
09-08-2010, 05:47 PM
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 :p
http://img6.imageshack.us/img6/1143/screenshotfn.png

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

Thank you!

Dark Photon
09-08-2010, 07:20 PM
I have two questions. The first one is about lights ... 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
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?

Dark Photon
09-08-2010, 07:26 PM
I have another question, with glu functions I can draw a sphere easily, isnt there a half-sphere method?
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.

Brunooo
09-08-2010, 07:56 PM
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?


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 :p

ZbuffeR
09-09-2010, 03:48 AM
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.

Dark Photon
09-09-2010, 05:23 AM
I could not understand what you meant, could you reformulate?
Regarding multisampling, check out this tutorial:

* http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=46

It's very similar on Linux.

* http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=268825#Post2688 25


What about the light? That 2D rect was supposed to be yellow :p
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.

Brunooo
09-09-2010, 07:13 AM
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:

http://img831.imageshack.us/img831/1662/screenshottr.png

Used:

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

ZbuffeR
09-09-2010, 07:58 AM
Your screenshot does look like a 2-sample MSAA.
Try 4 or 8 samples if you want better precision.

Brunooo
09-09-2010, 08:40 AM
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.

HannesH
09-09-2010, 03:04 PM
Your hardware does not support 8 samples.
It defaults to no AA if you try.