views:

224

answers:

3

This is a simple issue that I'm somewhat ashamed to ask for help on.

I'm making a simple call to gluSphere to render a sphere, however, it does not light properly even though I'm pretty sure I added the normals and lighting correctly. If, however, I add a texture, the model lights normally, except it seems to be always SMOOTH, and I cannot change it to flat.

This is the lighting code in my init() function:

gl.glLightfv( GL.GL_LIGHT0, GL.GL_AMBIENT , AMBIENT_LIGHT, 0 );
gl.glLightfv( GL.GL_LIGHT0, GL.GL_DIFFUSE , DIFFUSE_LIGHT, 0 );
gl.glLightfv( GL.GL_LIGHT0, GL.GL_POSITION, light_pos    , 0 );
gl.glEnable ( GL.GL_LIGHT0 );
gl.glEnable ( GL.GL_LIGHTING );

this is my sphere code in my display() function:

gl.glColor3d(1.0, 1.0, 1.0);
glu.gluQuadricDrawStyle  (quad, GLU.GLU_FILL);
glu.gluQuadricNormals    (quad, GLU.GLU_FLAT);
glu.gluQuadricOrientation(quad, GLU.GLU_OUTSIDE);

glu.gluSphere(quad, 1.0, lat, lon);

Please advise.

EDIT: light values:

public final static float[] DIFFUSE_LIGHT  = {  1.0f, 1.0f,  1.0f, 1.0f };
public final static float[] AMBIENT_LIGHT  = {  0.3f, 0.3f,  0.3f, 1.0f };
public              float[] light_pos      = { -2.0f, 2.0f, 10.0f, 0.0f };

added materials, no change:

gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT , new float[]{0.5f, 0.5f, 0.5f, 1.0f}, 0);
gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE , new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0);
gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, new float[]{0.7f, 0.7f, 0.7f, 1.0f}, 0);
gl.glMaterialf (GL.GL_FRONT, GL.GL_SHININESS, 0.5f);
gl.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, new float[]{0.3f, 0.3f, 0.3f, 0.0f}, 0);

EDIT2:

Blah, I figured i had a:

gl.glEnable(GL.GL_TEXTURE_2D);

active somewhere and it was causing my model not to have shading if there was no texture associated with it. -_- carry on good people, carry on.

A: 

may it be because you didn't set material?

Andrey
added materials. no change. At this point i'm just gonna make my own sphere code, can't be that hard right? plus with display list, probably wouldn't have to worry about optimization.
badcodenotreat
A: 

What kind of lighting are you expecting? The third parameter to glLightfv is supposed to be the values of the light you are setting.

FranticPedantic
At this point, any old lighting, all I get is a black ball.the lighting values are as follows, however, I'm not sure if it will help. They work perfectly well for any shape I manually construct with my own normals. Maybe I need to just implement my own sphere code.added to post since comment does not auto format.
badcodenotreat
Sorry, I misread your function call. What's your 4th parameter you are passing?
FranticPedantic
no idea, it's a parameter specific to JOGL. an offset?
badcodenotreat
A: 
  1. Are there any translations/rotations you do that may affect the position of the light?
  2. Is GL_COLOR_MATERIAL enabled or disabled? It may overwrite your material settings if it is.
  3. Even if your code is not enabling GL_TEXTURE_2D, you should try disabling it manually right before the line is reached, just in case.
  4. If you wish to ignore gluSphere completely, there's some code in this thread that you can use.
Andrei Krotkov