Results 1 to 5 of 5

Thread: my color is wrong ! help me !

  1. #1
    Senior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Årsunda,gästrikland,Sweden
    Posts
    113

    my color is wrong ! help me !

    this is the problem! if you look into the code I have made myself a nice object class. it works fine but when I use my new implemented material structure the color of my object is screwed up! the code in part 1 is my new fine object class when I use it the color of my cube is pink! why ?? if I goes back to the old ( code part 2 ) the object is blue as it should be ! I can´t see anything wrong ! and the light settings isn´t changed!

    =-=-=-=-=-= Code Part 1 =-=-=-=-=-=
    the main structor for the material setup! I have removed the other parts.

    struct OGL_Material // the structure for storing the material color
    {
    GLfloat shininess[1];
    GLfloat specular[4];
    GLfloat diffuse[4];
    GLfloat ambient[4];
    };

    class OGL_Object
    {
    // some other stuff like vertex tables and normal tabels
    int colorchange;
    OGL_Material Material;

    // Other functions who adds vertexis and stuff
    void SetMaterial(int pname, GLfloat R, GLfloat G, GLfloat B, GLfloat A);
    };

    void OGL_Object::SetMaterial(int pname, GLfloat R, GLfloat G, GLfloat B, GLfloat A)
    {
    switch(pname)
    {
    case GL_AMBIENT:
    Material.ambient[0] = R; Material.ambient[1] = G;
    Material.ambient[2] = B; Material.ambient[3] = A;
    break;
    case GL_DIFFUSE:
    Material.diffuse[0] = R; Material.diffuse[1] = G;
    Material.diffuse[2] = B; Material.diffuse[4] = A;
    break;
    case GL_SPECULAR:
    Material.specular[0] = R; Material.specular[1] = G;
    Material.specular[2] = B; Material.specular[3] = A;
    break;
    case GL_SHININESS:
    Material.shininess[0] = R;
    break;
    default:
    break;
    }
    }


    I do this when I render the object:
    if (colorchange == 1) //Check If the color would change I have tried without this too
    {
    glMaterialfv(GL_FRONT, GL_AMBIENT, Material.ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, Material.diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, Material.specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, Material.shininess);
    colorchange == 0; // Set this to 0 so it don´t change the color next frame
    }


    this is what I do when I initialize the object
    MyCube.SetMaterial(GL_AMBIENT, 0.0f, 0.0f, 0.2f, 1.0f);
    MyCube.SetMaterial(GL_DIFFUSE, 0.0f, 0.0f, 0.6f, 1.0f);
    MyCube.SetMaterial(GL_SPECULAR, 0.3f, 0.3f, 0.8f, 1.0f);
    MyCube.SetMaterial(GL_SHININESS, 10.0f, 0.0f, 0.0f, 0.0f);

    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    =-=-=-=-=-= Code Part 2 =-=-=-=-=-=

    //this is set before the render proc
    GLfloat Material_shininess[] = {10.0};
    GLfloat Material_specular[] = {0.3f, 0.3f, 0.8f, 1.0f};
    GLfloat Material_diffuse[] = {0.0f, 0.0f, 0.6f, 1.0f};
    GLfloat Material_ambient[] = {0.0f, 0.0f, 0.2f, 1.0f};

    //Here is the material settings in the render loop
    glMaterialfv(GL_FRONT, GL_AMBIENT, Material_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, Material_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, Material_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, Material_shininess);
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    Thanks for your help

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: my color is wrong ! help me !

    I'm getting crazy with these code postings.
    Couldn't one expand the code style to that it acts like the visual c one (I mean highlighting keywords, tabs etc.)

  3. #3
    Guest

    Re: my color is wrong ! help me !

    Hi,

    One thing I noticed is that you wrote
    Material.diffuse[4]= A when it should have
    been Material.diffuse[4] = A.

  4. #4
    Guest

    Re: my color is wrong ! help me !

    Oops
    I mean Material.diffuse[3] = A

  5. #5
    Senior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Årsunda,gästrikland,Sweden
    Posts
    113

    Re: my color is wrong ! help me !

    o thanks i missed that one! hehe.. allways some little thing that makes one look blind or something

Similar Threads

  1. Wrong Color for 2D quad
    By Krimsom King in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-06-2012, 11:07 AM
  2. 1D Textrue Color is Wrong ?
    By LLM in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-12-2006, 01:01 AM
  3. Texture color depth is wrong
    By Darke in forum OpenGL: Windows
    Replies: 1
    Last Post: 04-16-2006, 09:10 AM
  4. If color of objects is wrong from which it should be
    By Money in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-15-2005, 09:04 PM
  5. color buffer color as source for register combiners
    By Kosta in forum OpenGL: General
    Replies: 1
    Last Post: 07-11-2000, 09:47 AM

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