PDA

View Full Version : color problem



beet6
01-19-2002, 08:21 PM
my realatd part of code was posted below:

static int R[10];
int i=0;
bool m_bGetdata=false;

GloveData gData;

GLfloat farView=-15.0;
float Roffset[10];

void init(void)
{
R[0]=40;
R[1]=0;
R[2]=0;
R[3]=0;
R[4]=0;
R[5]=0;
R[6]=0;
R[7]=0;
R[8]=0;
R[9]=0;

m_bGetdata=true;
gData.init();
gData.upData();
for(i=0;i<10;i++)
Roffset[i]=gData.fJoint[i];

GLfloat mat_specular[]={1.0,1.0,1.0};
GLfloat mat_shininess[]={100.0};
GLfloat light_position[]={0.0,0.0,4.0,1.0};
GLfloat white_light[]={1.0,1.0,1.0,1.0};

glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glMaterialfv(GL_FRONT,GL_EMISSION,mat_shininess);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glLightfv(GL_LIGHT0,GL_DIFFUSE,white_light);
glLightfv(GL_LIGHT0,GL_SPECULAR,white_light);
glLightfv(GL_LIGHT0,GL_AMBIENT,white_light);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);

glClearColor(0.,0.,0.,0.);
glShadeModel(GL_SMOOTH);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

//

// draw the palm

glPushMatrix();

glShadeModel(GL_FLAT);
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
glColorMaterial(GL_FRONT,GL_DIFFUSE);
glColor3f(1.0,1.0,1.0);
glLoadIdentity();
glTranslatef(0.0,0.0,farView);
glTranslatef(0.0,-1.5,0.0);
glRotatef(Rx0,1.0,0.0,0.0);
glTranslatef(0.0,1.5,0.0);
glPushMatrix();
glScalef(3.0,3.0,0.5);
glutSolidCube(1.0);
glPopMatrix();

//draw the Thumb finger
glPushMatrix();
glTranslatef(-1.2,-1.0,0.0);
glRotatef(R[0],0.0,0.0,1.0);
glTranslatef(0.0,0.55,0.0);
glPushMatrix();
glScalef(0.8,1.1,0.5);
glutSolidCube(1.0);
glPopMatrix();
glTranslatef(0.0,0.55,0.0);
glRotatef(R[5],0.0,0.0,1.0);
glTranslatef(0.0,0.50,0.0); //offset for compact joint 0.55
glScalef(0.8,1.1,0.5);
glutSolidCube(1.0);
glPopMatrix();

//draw the index finger

glPushMatrix();
glTranslatef(-1.15,1.5,0.0);
glRotatef(R[1],1.0,0.0,0.0);
glTranslatef(0.0,0.6,0.0);
glPushMatrix();
glScalef(0.6,1.2,0.5);
glutSolidCube(1.0);
glPopMatrix();
glTranslatef(0.0,0.6,0.0);
glRotatef(R[6],1.0,0.0,0.0);
glTranslatef(0.,0.6,0.0);
glScalef(0.6,1.2,0.5);
glutSolidCube(1.0);
glPopMatrix();

//draw the middle finger

glPushMatrix();
glTranslatef(-0.3,1.5,0.0);
glRotatef(R[2],1.0,0.0,0.0);
glTranslatef(0.0,0.7,0.0);
glPushMatrix();
glScalef(0.7,1.4,0.5);
glutSolidCube(1.0);
glPopMatrix();
glTranslatef(0.0,0.7,0.0);
glRotatef(R[7],1.0,0.,0.0);
glTranslatef(0.0,0.65,0.0); //offset for 0.7
glScalef(0.7,1.4,0.5);
glutSolidCube(1.0);
glPopMatrix();

// ring finger
glPushMatrix();
glTranslatef(0.55,1.5,0.0);
glRotatef(R[3],1.0,0.0,0.0);
glTranslatef(0.0,0.65,0.0);
glPushMatrix();
glScalef(0.6,1.3,0.5);
glutSolidCube(1.0);
glPopMatrix();
glTranslatef(0.0,0.65,0.0);
glRotatef(R[8],1.0,0.0,0.0);
glTranslatef(0.0,0.6,0.0); //offset for joint 0.65
glScalef(0.6,1.3,0.5);
glutSolidCube(1.0);
glPopMatrix();

//pinky finger

glPushMatrix();
glTranslatef(1.3,1.5,0.0);
glRotatef(R[4],1.0,0.0,0.0);
glTranslatef(0.0,0.5,0.0);
glPushMatrix();
glScalef(0.4,1.0,0.5);
glutSolidCube(1.0);
glPopMatrix();
glTranslatef(0.0,0.5,0.0);
glRotatef(R[9],1.0,0.0,0.0);
glTranslatef(0.0,0.45,0.0); //for 0.5 offset
glScalef(0.4,1.0,0.5);
glutSolidCube(1.0);

glPopMatrix();
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);

glPopMatrix();
glShadeModel(GL_SMOOTH);

glutSwapBuffers();
}

void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w,(GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65.0,(GLfloat)w/(GLfloat)h,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0,0.0,farView);
}


you any comments are very appreciated... Thanks
beet

beet6
01-19-2002, 08:41 PM
My problem is the color cannot be changed properly for the object; always remains ars red,,,,,

beet6
01-20-2002, 09:01 AM
help me please

Lyr
01-20-2002, 12:26 PM
Check this line:
glMaterialfv(GL_FRONT,GL_EMISSION,mat_shininess);

GL_EMISSION takes 4 values!