Results 1 to 4 of 4

Thread: Returning to state

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2005
    Posts
    26

    Returning to state

    Hi

    I am a newbie here. what I am doing is drawing a number of individual spheres which constitute an object. There are thousands of spheres and I have arrays of all the positional information relative to an origin. I am using the solid sphere routines and the glTranslate commands to move to the next position. However I want to simply forget about the last spheres psotion and awlays draw relative to the origin?

    Can someone clear up the issue whether I should use PopMatrix here to ensure that my function that draws the sphere originates back at the origin?

    Any help would be appreciated. Thanks

    Brett

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Returning to state

    Very simple:
    Code :
    // Assume glMatrixMode(GL_MODELVIEW) is current.
    for (each sphere)
    {
      glPushMatrix();
        glTranslatef(sphereCenter.x, sphereCenter.y, sphereCenter.z);
        glutSolidSphere(...);
      glPopMatrix();
    }
    Might be faster if you generate a display list with your sphere inside instead of calling glutSolidSphere (immediate mode) all over again.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2005
    Posts
    26

    Re: Returning to state

    Ok thats great!!

    Thanks very much.

    How would i specify a sphere of a certain color... I tried to do this last nite with some code I doctored from a copy but found that I could need to specify a colour type and shading and get say three diferent spheres drawn by a function into three different colors. It also included a light effect but I found this did not seem to work. How can the above code be easily integrated to select say one of two colors by a boolean?

    Thanks again

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Returning to state

    Coloring depends on lighting conditions.
    Simplified for starters:
    - Lighting off: Color is taken from the primary color (glColor and alikes).
    - Lighting on: Lighting is done with the current material (glMaterial and friends). You must have normals per vertex to get OpenGL lighting to work properly.

    Have a look at the RedBook (OpenGL Programming Guide). There is a PDF of an old version to be found on the internet.

    Read the FAQs here:
    http://www.opengl.org/resources/faq/technical/

    Check out the http://nehe.gamedev.net/ tutorials.
    (I don't like the "drawing in the idle loop" paradigm, but other than that, a good site to begin with.)

Similar Threads

  1. Separate sampler state from texture state
    By The Fiddler in forum OpenGL: General
    Replies: 79
    Last Post: 03-15-2010, 05:12 PM
  2. checking state before setting state
    By supagu in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-11-2004, 10:55 PM
  3. returning to glut
    By saian in forum OpenGL: Linux
    Replies: 1
    Last Post: 03-21-2002, 03:15 AM
  4. Better error returning
    By imported_Theo in forum OpenGL: General
    Replies: 1
    Last Post: 12-11-2000, 01:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean