Results 1 to 4 of 4

Thread: strange color

  1. #1
    Member Newbie
    Join Date
    Jan 2002
    Location
    Rolla , MO USA
    Posts
    36

    strange color

    I wrote some code to draw a virtual hand in space; but after I used a light, the hand always shown as red, even after I deleted and disabled lighting. Some part of code pasted below. Thanks million.


    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 ambientLight[]={1.0,1.0,1.0,1.0};
    glEnable(GL_LIGHTING);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientLight );

    GLfloat gray[]={1.0,1.0,1.0,1.0};
    glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFF USE,gray);

    GLfloat Light_ambient[]={0.3,0.3,0.3,1.0};
    GLfloat Light_diffuse[]={0.7,0.7,0.7,1.0};
    glLightfv(GL_LIGHT0,GL_AMBIENT,Light_ambient);
    glLightfv(GL_LIGHT0,GL_DIFFUSE,Light_diffuse);
    GLfloat position[]={5.0,0.0,0.0,1.0};
    glLightfv(GL_LIGHT0,GL_POSITION,position);
    glEnable(GL_LIGHT0);

    glEnable(GL_DEPTH_TEST);

    glClearColor(0.0,1.0,1.0,1.0);
    glShadeModel(GL_SMOOTH);

    }

    void display()
    {
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    // draw the palm

    glPushMatrix();

    glEnable(GL_COLOR_MATERIAL);
    glDisable(GL_LIGHTING);
    glColorMaterial(GL_FRONT,GL_AMBIENT_AND_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);
    }

    void keyboard(unsigned char key, int x, int y)
    {
    switch(key){
    case 'Q':
    case 'q':
    Rx0=(Rx0+5)%360;
    glutPostRedisplay();
    break;
    case 'S':
    case 's':
    m_bGetdata=false;
    break;
    case 'R':
    case 'r':
    m_bGetdata=true;
    gData.upData();
    for(i=0;i<10;i++)
    Roffset[i]=gData.fJoint[i];
    break;
    case 'E':
    case 'e':
    m_bGetdata=false;
    exit(0);
    break;
    case 'f':
    farView=(farView-5.0);
    glutPostRedisplay();
    break;
    case 'g':
    farView=(farView+5.0);
    glutPostRedisplay();
    break;
    default:
    break;
    }
    }


    int main(int argc, char** argv)
    {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GL_DEPTH) ;
    glutInitWindowSize(500,500);
    glutInitWindowPosition(100,100);
    glutCreateWindow(argv[0]);
    init();
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(keyboard);
    glutTimerFunc(30,update,0);
    glutMainLoop();
    return 0;
    }
    Beet

  2. #2
    Member Newbie
    Join Date
    Jan 2002
    Location
    Rolla , MO USA
    Posts
    36

    Re: strange color

    really strange...
    helppppppppp
    Beet

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    6

    Re: strange color

    You're right, it shouldn't be red. I compiled it and got a white hand.

  4. #4
    Junior Member Newbie
    Join Date
    May 2000
    Location
    Austria
    Posts
    21

    Re: strange color

    Try to disable everything you don't realy need.

    GL_TEXTURE2D/1D
    GL_LIGHTING
    GL_FOG
    ...

Similar Threads

  1. Strange Color Swizzle needed
    By henniman in forum OpenGL: macOS
    Replies: 3
    Last Post: 03-09-2011, 02:54 AM
  2. Strange change of color
    By zweifel in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 06-13-2010, 07:37 PM
  3. High color/true color troubles on Win2000
    By Lelik in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-22-2004, 04:39 AM
  4. strange behaviour of ambient color with fragment program
    By Orcinus in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 06-16-2004, 08:02 AM
  5. strange color
    By beet6 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-20-2002, 07:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean