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)
Material.ambient[0] = R; Material.ambient[1] = G;
Material.ambient[2] = B; Material.ambient[3] = A;
Material.diffuse[0] = R; Material.diffuse[1] = G;
Material.diffuse[2] = B; Material.diffuse[4] = A;
Material.specular[0] = R; Material.specular[1] = G;
Material.specular[2] = B; Material.specular[3] = A;
Material.shininess[0] = R;

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

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.)


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

I mean Material.diffuse[3] = A

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