Create a Chrome Cube in OpenGL / Glut?

I am trying to make a chrome cube in GLUT / OpenGL and I don’t know exactly how to do it.

I searched the “Material Table” in the textbook, which shows that “Chrome” is: Environment: (0.25, 0.25, 0.25), Diffuse: (0.4, 0.4, 0, 4) and Mirror: (0.774597.0.774597.0.774597).

My question is: how to create a simple cube and apply this material / texture to it in Glut / OpenGL?

Am I using "glutSolidCube ()"? If so, how do I apply the chrome texture to it?

Can GLUT / OpenGL people point me in the right direction?

+3
source share
2 answers

It should be as simple as calling glMaterialfv()before glutSolidCube().

OpenGL , , , :

_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();
}
+5

? , , , . . OpenGL glTexGen.

NeHe 23 . GLSL. .

+2

Source: https://habr.com/ru/post/1706314/


All Articles