Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: How to color a sphere non-uniformly ?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2009
    Posts
    2

    How to color a sphere non-uniformly ?

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

  2. #2
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: How to color a sphere non-uniformly ?

    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.

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: How to color a sphere non-uniformly ?

    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.

  4. #4
    Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    386

    Re: How to color a sphere non-uniformly ?

    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

    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
    Am I doing your homework for you?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •