glMaterialfv( )

#include <stdlib.h>

#include <GL/glut.h>

int B = 800;
//using namespace std;

const float RADIUS = 4.0f; //The radius of the sphere

float _angle = -60;

//bool _highShininess = false; //Whether the shininess parameter is high
//bool _lowSpecularity = false; //Whether the specularity parameter is high
//bool _emission = false; //Whether the emission parameter is turned on
/*
void handleKeypress(unsigned char key, int x, int y) {
switch (key) {
case 27: //Escape key
exit(0);
break;
case ‘s’:
_highShininess = !_highShininess;
break;
case ‘p’:
_lowSpecularity = !_lowSpecularity;
break;
case ‘e’:
_emission = !_emission;
break;
}
}
*/
void initRendering() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glShadeModel(GL_SMOOTH);
//Disable color materials, so that glMaterial calls work
glDisable(GL_COLOR_MATERIAL);
}

void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-B/2,B/2,-B/2, B/2,-50,50);
}

void drawScene() {

GLfloat ambientLight[] = {0.2f, 0.2f, 0.2f, 1.0f};
GLfloat lightColor[] = {0.6f, 0.6f, 0.6f, 1.0f};
GLfloat lightPos[] ={10,0,-15,1};

  //The color of the sphere
GLfloat materialColor[] = {1.0f, 1.0f, 0.0f, 1.0f};
//The specular (shiny) component of the material
GLfloat materialSpecular[] = {0,0,1,1};
//The color emitted by the material
GLfloat materialEmission[] = {1.0f,1.0f,0, 1.0f};

GLfloat shininess = 20;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef(0.0f, 0.0f, -10.0f);
glRotatef(_angle, 0, 1, 0);
glScalef(2,2,2);

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);


//Diffuse (non-shiny) light component
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
//Specular (shiny) light component
glLightfv(GL_LIGHT0, GL_SPECULAR, lightColor);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);




glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, materialColor);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, materialEmission);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); //The shininess parameter

//Draw the sphere
//glutSolidSphere(RADIUS, 150, 80);

glBegin(GL_TRIANGLE_FAN); /* draw a filled TRIANGLE /
glColor3f ( 1.0, 0.0, 0.0);
glNormal3f(1,0,0); /
draw in red /
glVertex3f(0,0,-10);
glNormal3f(0,1,0); /
(x,y) /
glVertex3f(50,100,0); /
(x,y) /
glNormal3f(0,0,1);
glVertex3f(100,0,-10);
glNormal3f(0,0,1); /
(x,y) */
glVertex3f(50,-100,0);

  glEnd();
glutSwapBuffers();

}

//Called every 25 milliseconds
void update(int value) {
_angle += 1.5f;
if (_angle > 360) {
_angle -= 360;
}

glutPostRedisplay();
glutTimerFunc(25, update, 0);

}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);

glutCreateWindow("Materials - videotutorialsrock.com");
initRendering();

glutDisplayFunc(drawScene);

glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0);

glutMainLoop();
return 0;

}
This is code whci renders a rotating yellow rhombus…But the specularity color that i have specified is blue. But I could see the highlight/shine in blue color. What could be the problem in the code. Is it something wrong in lighting or so Kindly help…:slight_smile: