I'm attempting to make a chromed cube in GLUT / OpenGL and I'm not sure exactly how to do it.
I looked up a "Materials Table" in a textbook which showed "Chrome" as being: Ambient: (0.25, 0.25, 0.25), Diffuse: (0.4, 0.4, 0.4), and Specular: (0.774597,0.774597,0.774597).
My question is, how do I create a simple cube and apply this material/texture to it in Glut/OpenGL?
Do I use "glutSolidCube()"? If so, how do I then apply the chrome texture to it?
Can any GLUT/OpenGL people point me in the right direction?
This should be as simple as calling glMaterialfv() before glutSolidCube().
I haven't done OpenGL since school, but here's some display loop code from an old project that used a sphere that should get you on the right track:
_Ambient[CHROME][0] = 0.25f;
_Ambient[CHROME][1] = 0.25f;
_Ambient[CHROME][2] = 0.25f;
_Ambient[CHROME][3] = 1.0f;
_Diffuse[CHROME][0] = 0.4f;
_Diffuse[CHROME][1] = 0.4f;
_Diffuse[CHROME][2] = 0.4f;
_Diffuse[CHROME][3] = 1.0f;
_Specular[CHROME][0] = 0.774597f;
_Specular[CHROME][1] = 0.774597f;
_Specular[CHROME][2] = 0.774597f;
_Specular[CHROME][3] = 1.0f;
_Shininess[CHROME] = 76.8f;
void Display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, _Ambient[CHROME]);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, _Diffuse[CHROME]);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, _Specular[CHROME]);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, _Shininess[CHROME]);
// Translations...
glutSolidSphere(_Radius, _Slices, _Stacks);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With