Re: Light

New Message Reply Date view Thread view Subject view Author view

From: Allan Schaffer (allan++at++sgi.com)
Date: 03/20/2000 14:15:32


On Mar 19, 6:33pm, Mike wrote:
> When someone selects a light the second time it should turn off?
> void function () {
> static int flagForLight = 0;
>
> Shared->light = new pfLight;
>
> Shared->light->setSpotDir (0.0,0.0,0.0);
> Shared->light->setPos(0.0,1.0,1.0);
>
> Shared->lm = new pfLightModel;
> Shared->lm->setAmbient(0.0f,0.0f,1.0f);
> Shared->lm->apply;
> pfEnable(PFEN_LIGHTING);
>
> if(flagForLight == 0) {
> Shared->light->on();
> flagForLight = 1;
> else {
> Shared->light->off();
> flagForLight = 0;
> }
> }

The code logic here looks troublesome -- you seem to be creating a
_new_ light (and lightmodel) each time this function is called. The
pointer to the old light (and lightmodel) is lost and the old light
never turned off. Call it enough times and OpenGL will complain
about too many lights.

Keeping this in the same general style I think I'd do something
similar to this:

     static int flagForLight = 0;
     static int first = 0;
 
     if (!first)
     {
        Shared->light = new pfLight;
 
        Shared->light->setSpotDir (0.0,0.0,0.0);
        Shared->light->setPos(0.0,1.0,1.0);
 
        Shared->lm = new pfLightModel;
        Shared->lm->setAmbient(0.0f,0.0f,1.0f);
        Shared->lm->apply;
        pfEnable(PFEN_LIGHTING);
        first = 1;
     }
 
     if(flagForLight == 0) {
         Shared->light->on();
         flagForLight = 1;
     else {
         Shared->light->off();
         flagForLight = 0;
     }

Allan

-- 
Allan Schaffer                                            allan++at++sgi.com
Silicon Graphics                           http://reality.sgi.com/allan


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Mon Mar 20 2000 - 14:16:24 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.