PDA

View Full Version : GL_SHININESS does not work. Can't find a mistake..



yesint
07-22-2009, 04:18 AM
Dear All,
I'm trying to make shiny highlights on my objects. After reading tutorials I do the following:


-- Initialiation --
glShadeModel(GL_SMOOTH);
glClearDepth(1.0);
glClearColor(bg_color[0], bg_color[1], bg_color[2], 0.0);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);

// Light
GLfloat LightAmbient[]= { 0.2f, 0.2f, 0.2f, 1.0f }; //Ambient light
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values
GLfloat LightSpecular[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values
GLfloat LightPosition[]= { 100.0f, 100.0f, 130.0f, 1.0f }; // Light Position

glEnable( GL_LIGHT0 );
glEnable( GL_LIGHTING ) ;
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular); // Specular light

glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); // Position The Light

glEnable ( GL_COLOR_MATERIAL ) ;
glColorMaterial ( GL_FRONT, GL_AMBIENT_AND_DIFFUSE ) ;

-- Rendering code ---
glPushMatrix();
glColor4f(R,G,B,1.0);
glMaterialf(GL_FRONT, GL_SHININESS, 128);
gluSphere(quadric,sz,16,16);
glPopMatrix();

I can't see any shiny spots. Changing the shininess value makes no effect. I can't find an error :mad:
Any help is very appreciated!

dorbie
07-22-2009, 04:37 AM
It expects a float but I think the compiler should handle that.

When you say it doesn't work, what are you expecting?

Shininess is the specular exponent, so it controls the size of the specular highlight. For high exponents the highlight is very small and crisp. For something lower it is spread out and gradually attenuated.

With per vertex lighting you will only see a specular highlight with a large exponent if there are sufficient vertices to represent it. It is likely that you just don't have enough vertices to represent the small specular region.

yesint
07-22-2009, 05:54 AM
Ok, I understand what's wrong after your phrase about specularity! I forgot to set the specular component of the material. Stupid. Thanks a lot!