PDA

View Full Version : Returning to state



dt
02-24-2005, 03:21 AM
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

Relic
02-24-2005, 04:35 AM
Very simple:

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

dt
02-24-2005, 05:33 AM
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

Relic
02-24-2005, 06:40 AM
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.)