Hanuman
Hanuman

Reputation: 642

Changle the color of Teapot in GLGravity Iphone project

I have downloaded the GLGravity project from apple site. I am trying to change the color of the teapot, but it is not changing

Upvotes: 0

Views: 473

Answers (1)

Tommy
Tommy

Reputation: 100622

The GLGravity sample, as last updated on 6th July 2010, uses the GLES 1.x fixed pipeline, with the built-in lighting support. The colour of the teapot is therefore a result of the light and material properties, which are set on lines 125 to 147 of GLGravityView.m.

In practise, you'll notice that matAmbient, matDiffuse and matSpecular are different intensities of white. So the object itself is white. That means that the colour you see is defined entirely by the light. That's a conceptually odd way around to do it possibly, but there it is.

The net effect is that the colour of the teapot is defined by lightAmbient and lightDiffuse. lightAmbient is another shade of white, lightDiffuse being the one you want to play with. As downloaded immediately it is (on line 126):

const GLfloat           lightDiffuse[] = {1.0, 0.6, 0.0, 1.0};

Giving a vaguely copper look. If you change that to:

const GLfloat           lightDiffuse[] = {0.0, 0.0, 1.0, 1.0};

Then you'll get a blue teapot. The first three elements of that vector are R, G, B in the range [0.0, 1.0]. Set them to change the overall colour of the teapot.

Upvotes: 1

Related Questions