Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Colors changing problem

  1. #1
    Intern Newbie
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    32

    Colors changing problem

    Hi, this is a problem which has been plaguing me for quite some time now.. Hope someone can help me?

    I have a code that draws 2 objects based on condition 'a'.If 'a' is 1, it draws the first object, if 'a' is 2, it draws the second object. 'a' toggles every now and then from 1 to 2.

    These are 4 observations I made.

    1)If object 1 is drawn alone, there is no problem.

    2)If object 2 is drawn alone, the color of object 2 is different from what I expected. (it seems more brown than orange)

    3)If object 1 is drawn first, followed by object 2, there is no problem.

    4)If object 2 is drawn first followed by object 1, the color of object 2 is the same as condition (2), meaning it is more brown than orange.

    Below is my code in this area, pls help!!

    /////////////////////////////////////////////
    static GLfloat color[8][3]=
    { //red,orange,yellow,green,blue,indigo,
    //light blue, black
    {1.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{1.0f,1.0f,0.0f} ,{0.0f,1.0f,0.0f},{0.0f,0.0f,1.0f},{0.97f,0.61f,0. 96f}, {0.65f,0.8f,0.95f},{0.0f,0.0f,0.0f}
    };

    .....

    void DrawObject(void)
    {
    glColor3fv(color[colorloop]);
    glCallList(object);
    }
    ......

    ////in my renderscene function/////
    ......
    if (a==1)
    {
    glPushMatrix();
    glTranslatef(x1,0.0f,z1};
    glRotatef(rot,0.0f,1.0f,0.0f);
    colorloop=0;
    DrawObject();
    glPushMatrix();
    }
    ......
    ......
    if (a==2)
    {
    glPushMatrix();
    glTranslatef(x2,0.0f,z2};
    glRotatef(rot,0.0f,1.0f,0.0f);
    colorloop=1;
    DrawObject();
    glPushMatrix();
    }

    ///////////////////////////////////////////////

    Pls help me if you know anything. Thanks!
    Cheers!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,651

    Re: Colors changing problem

    Hi !

    First of all, replace the last glPushMatrix() at the end of each "if" clause to a glPopMatrix(), you are filling up the matrix stack very fast and then you will get weird transformation problems.

    Not sure about problem with the colors though, I assume you have all,lighting disabled as you are using glColor... (glDisable( GL_LIGHTING)

    In that case the color should be what you set with glColor...

    Mikael

  3. #3
    Intern Newbie
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    32

    Re: Colors changing problem

    Hi, Thanks alot!!
    Anyway, the PopMatrix was a typo error..heh..Thanks for pointing it out!

    Can I check with you, I am using Lighting enabled, and I did not disable Lighting, so do I need to disable Lighting for this problem? (I hope not cause I need the Lighting for certain effects).

    Thanks alot!!
    Cheers!

  4. #4
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,651

    Re: Colors changing problem

    Hi !

    glColor...() normally only works when lighting is disabled, to set the color when lighting is enabled you could use for example glMaterialfv().

    Mikael

  5. #5
    Intern Newbie
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    32

    Re: Colors changing problem

    Hi, first of all, Thanks alot for replying!!
    but i could not really understand what you meant, do you mind explaining it with more details? Or maybe an example?

    I am still not sure about the use of gl Materialfv, can you please enlighten me? thanks!!
    Cheers!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •