Back to index

radiance  4R0+20100331
Defines | Functions | Variables
rglsrc.c File Reference
#include "copyright.h"
#include "radogl.h"

Go to the source code of this file.

Defines

#define L_NONE   0
#define L_SOURCE   1
#define L_FLAT   2
#define L_SPHERE   3

Functions

static void l_flatsrc (int)
static void l_sphsrc (int)
static void l_source (int)
void lightinit ()
void lightclean ()
void lightdefs ()
int o_source (OBJREC *o)
int doflatsrc (MATREC *m, FVECT pos, FVECT norm, double area)
int dosphsrc (MATREC *m, FVECT pos, double area)

Variables

static const char RCSid [] = "$Id: rglsrc.c,v 3.6 2003/11/14 17:22:06 schorsch Exp $"
double expval = 0.
COLOR ambval = {0.2, 0.2, 0.2}
int dolights = MAXLIGHTS
int glightid [MAXLIGHTS]
static int lightlist
struct {
int type
MATRECm
FVECT pos
FVECT norm
double area
lightrec [MAXLIGHTS]
static int nlights

Define Documentation

#define L_FLAT   2

Definition at line 26 of file rglsrc.c.

#define L_NONE   0

Definition at line 24 of file rglsrc.c.

#define L_SOURCE   1

Definition at line 25 of file rglsrc.c.

#define L_SPHERE   3

Definition at line 27 of file rglsrc.c.


Function Documentation

int doflatsrc ( MATREC m,
FVECT  pos,
FVECT  norm,
double  area 
)

Definition at line 123 of file rglsrc.c.

{
       if (!dolights || !issrcmat(m) || area <= FTINY)
              return(0);
                                          /* record type & material */
       lightrec[nlights].type = L_FLAT;
       (lightrec[nlights].m = m)->nlinks++;
                                          /* assign geometry */
       VCOPY(lightrec[nlights].pos, pos);
       VCOPY(lightrec[nlights].norm, norm);
       lightrec[nlights].area = area;
       nlights++; dolights--;
       return(1);
}

Here is the caller graph for this function:

int dosphsrc ( MATREC m,
FVECT  pos,
double  area 
)

Definition at line 143 of file rglsrc.c.

{
       if (!dolights || !issrcmat(m) || area <= FTINY)
              return(0);
                                          /* record type & material */
       lightrec[nlights].type = L_SPHERE;
       (lightrec[nlights].m = m)->nlinks++;
                                          /* assign geometry */
       VCOPY(lightrec[nlights].pos, pos);
       lightrec[nlights].area = area;
       nlights++; dolights--;
       return(1);
}

Here is the caller graph for this function:

static void l_flatsrc ( int  n) [static]

Definition at line 186 of file rglsrc.c.

{
       GLfloat       vec[4];
       register MATREC      *m = lightrec[n].m;
       int    thislight = glightid[n];
                                          /* assign position */
       VCOPY(vec, lightrec[n].pos); vec[3] = 1.;
       glLightfv(thislight, GL_POSITION, vec);
                                          /* assign color */
       vec[0] = expval*lightrec[n].area*colval(m->u.l.emission,RED);
       vec[1] = expval*lightrec[n].area*colval(m->u.l.emission,GRN);
       vec[2] = expval*lightrec[n].area*colval(m->u.l.emission,BLU);
       vec[3] = 1.;
       glLightfv(thislight, GL_SPECULAR, vec);
       glLightfv(thislight, GL_DIFFUSE, vec);
       vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.;
       glLightfv(thislight, GL_AMBIENT, vec);
       glLightf(thislight, GL_SPOT_EXPONENT, 1.);
       glLightf(thislight, GL_CONSTANT_ATTENUATION, 0.);
       glLightf(thislight, GL_LINEAR_ATTENUATION, 0.);
       glLightf(thislight, GL_QUADRATIC_ATTENUATION, 1.);
       if (m->type == MAT_SPOT && m->u.l.spotang < 90.) {
              glLightf(thislight, GL_SPOT_CUTOFF, m->u.l.spotang);
              glLightfv(thislight, GL_SPOT_DIRECTION, m->u.l.spotdir);
       } else {
              glLightf(thislight, GL_SPOT_CUTOFF, 90.);
              VCOPY(vec, lightrec[n].norm);
              glLightfv(thislight, GL_SPOT_DIRECTION, vec);
       }
       glEnable(thislight);
}

Here is the caller graph for this function:

static void l_source ( int  n)

Definition at line 162 of file rglsrc.c.

{
       register MATREC      *m = lightrec[n].m;
       int    thislight = glightid[n];
       GLfloat       vec[4];
                                          /* assign direction */
       VCOPY(vec, lightrec[n].pos);
       vec[3] = 0.;
       glLightfv(thislight, GL_POSITION, vec);
                                          /* assign color */
       vec[0] = expval*lightrec[n].area*colval(m->u.l.emission,RED);
       vec[1] = expval*lightrec[n].area*colval(m->u.l.emission,GRN);
       vec[2] = expval*lightrec[n].area*colval(m->u.l.emission,BLU);
       vec[3] = 1.;
       glLightfv(thislight, GL_SPECULAR, vec);
       glLightfv(thislight, GL_DIFFUSE, vec);
       vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.;
       glLightfv(thislight, GL_AMBIENT, vec);
       glEnable(thislight);
}

Here is the caller graph for this function:

static void l_sphsrc ( int  n)

Definition at line 221 of file rglsrc.c.

{
       GLfloat       vec[4];
       register MATREC      *m = lightrec[n].m;
       int    thislight = glightid[n];
                                          /* assign position */
       VCOPY(vec, lightrec[n].pos); vec[3] = 1.;
       glLightfv(thislight, GL_POSITION, vec);
                                          /* assign color */
       vec[0] = expval*lightrec[n].area*colval(m->u.l.emission,RED);
       vec[1] = expval*lightrec[n].area*colval(m->u.l.emission,GRN);
       vec[2] = expval*lightrec[n].area*colval(m->u.l.emission,BLU);
       vec[3] = 1.;
       glLightfv(thislight, GL_SPECULAR, vec);
       glLightfv(thislight, GL_DIFFUSE, vec);
       vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.;
       glLightfv(thislight, GL_AMBIENT, vec);
       glLightf(thislight, GL_SPOT_EXPONENT, 0.);
       glLightf(thislight, GL_CONSTANT_ATTENUATION, 0.);
       glLightf(thislight, GL_LINEAR_ATTENUATION, 0.);
       glLightf(thislight, GL_QUADRATIC_ATTENUATION, 1.);
       if (m->type == MAT_SPOT && m->u.l.spotang <= 90.) {
              glLightf(thislight, GL_SPOT_CUTOFF, m->u.l.spotang);
              glLightfv(thislight, GL_SPOT_DIRECTION, m->u.l.spotdir);
       } else
              glLightf(thislight, GL_SPOT_CUTOFF, 180.);
       glEnable(thislight);
}

Here is the caller graph for this function:

void lightclean ( void  )

Definition at line 64 of file rglsrc.c.

{
       if ((dolights += nlights) <= 0)
              return;
       glPopAttrib();
}

Here is the caller graph for this function:

void lightdefs ( void  )

Definition at line 73 of file rglsrc.c.

{
       if (!nlights)
              return;
       glNewList(lightlist, GL_COMPILE);
       while (nlights--) {
              switch (lightrec[nlights].type) {
              case L_FLAT:
                     l_flatsrc(nlights);
                     break;
              case L_SPHERE:
                     l_sphsrc(nlights);
                     break;
              case L_SOURCE:
                     l_source(nlights);
                     break;
              default:
                     error(CONSISTENCY, "botched light type in lightdefs");
              }
              freemtl(lightrec[nlights].m);
              lightrec[nlights].type = L_NONE;
       }
       glEndList();
       rgl_checkerr("defining lights");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void lightinit ( void  )

Definition at line 43 of file rglsrc.c.

{
       GLfloat       ambv[4];

       if (!dolights)
              return;
       glPushAttrib(GL_LIGHTING_BIT);
       if (expval <= FTINY && bright(ambval) > FTINY)
              expval = 0.2/bright(ambval);
       ambv[0] = expval*colval(ambval,RED);
       ambv[1] = expval*colval(ambval,GRN);
       ambv[2] = expval*colval(ambval,BLU);
       ambv[3] = 1.;
       glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambv);
       glCallList(lightlist = newglist());
       rgl_checkerr("in lightinit");
       nlights = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int o_source ( OBJREC o)

Definition at line 101 of file rglsrc.c.

{
       if (!dolights || !issrcmat((MATREC *)o->os))
              return(0);
       if (o->oargs.nfargs != 4)
              objerror(o, USER, "bad # real arguments");
                                          /* record type & material */
       lightrec[nlights].type = L_SOURCE;
       (lightrec[nlights].m = (MATREC *)o->os)->nlinks++;
                                          /* assign direction */
       VCOPY(lightrec[nlights].pos, o->oargs.farg);
                                          /* compute solid angle */
       if (o->oargs.farg[3] <= FTINY)
              objerror(o, USER, "zero size");
       lightrec[nlights].area = 2.*PI*(1. - cos(PI/180./2.*o->oargs.farg[3]));
       nlights++; dolights--;
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

COLOR ambval = {0.2, 0.2, 0.2}

Definition at line 14 of file rglsrc.c.

Definition at line 16 of file rglsrc.c.

double expval = 0.

Definition at line 12 of file rglsrc.c.

Initial value:
 {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2,
                     GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7}

Definition at line 18 of file rglsrc.c.

int lightlist [static]

Definition at line 21 of file rglsrc.c.

struct { ... } lightrec[MAXLIGHTS] [static]
int nlights [static]

Definition at line 37 of file rglsrc.c.

const char RCSid[] = "$Id: rglsrc.c,v 3.6 2003/11/14 17:22:06 schorsch Exp $" [static]

Definition at line 2 of file rglsrc.c.