PDA

View Full Version : How to color a sphere non-uniformly ?



am577
05-07-2009, 09:49 AM
I am drawing a sphere using 'gluSphere()', after setting the color with 'glColor3f()'. I would like to apply different colors to the two sides of the sphere e.g. to specify the colors separately for each segment of the sphere. Is there a way to do that, that is documented online ?
Thanks for any pointers...

_NK47
05-07-2009, 09:58 AM
either with texture or rendering the sphere with multiple draw calls one part at a time, changing the color. gluSphere renderes whole sphere i guess but you could use clipping planes to cut through. better yet textures.

dletozeun
05-07-2009, 10:04 AM
Just write your own sphere drawing code and you will have control of texture coordinates or the color of each vertex. Otherwise you won't.

MaxH
05-07-2009, 11:54 AM
As NK47 suggests, you could use gluSphere to draw two spheres with different colors or textures, then use glClipPlane to cut away half of each sphere. This approach would be the easier of the two - BUT is limited to fairly simple sphere tesselations. This is how I did the earth in the figure below ...

Two Spheres Cut In Half Using glClipPlane (http://imagebin.ca/view/ZU6-RFT.html)

If you want to get fancy and apply lots of different colors/textures to various pieces of the sphere, you have to write your own sphere routine, as dletozeun says. This is how I did the polygonal earth below. It's not that hard to write your own sphere routine. It would be an interesting OpenGL exercise for a beginner.

Polygonal Sphere (http://imagebin.ca/view/F0uCZbU.html)