Commit b07019bf authored by Ken Martin's avatar Ken Martin
Browse files

Initial revision

parent 8fe2659e
/*=========================================================================
Program: Visualization Library
Module: GlrCam.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#ifndef __vlGlrCamera_hh
#define __vlGlrCamera_hh
#include "Camera.hh"
#include "gl.h"
class vlGlrRenderer;
class vlGlrCamera : public vlCamera
{
public:
virtual char *GetClassName() {return "vlGlrCamera";};
void Render(vlRenderer *ren); // overides base
void Render(vlGlrRenderer *ren); // real function
};
#endif
/*=========================================================================
Program: Visualization Library
Module: GlrLgt.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#ifndef __vlGlrLight_hh
#define __vlGlrLight_hh
#include "Light.hh"
#include "gl.h"
class vlGlrRenderer;
class vlGlrLight : public vlLight
{
protected:
public:
char *GetClassName() {return "vlGlrLight";};
void Render(vlRenderer *ren,int light_index); // overides base
void Render(vlGlrRenderer *ren,int light_index); // real function
};
#endif
/*=========================================================================
Program: Visualization Library
Module: GlrProp.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#ifndef __vlGlrProperty_hh
#define __vlGlrProperty_hh
#include "Property.hh"
#include "gl.h"
class vlGlrRenderer;
class vlGlrProperty : public vlProperty
{
public:
char *GetClassName() {return "vlGlrProperty";};
void Render(vlRenderer *ren); // overides base
void Render(vlGlrRenderer *ren);
};
#endif
/*=========================================================================
Program: Visualization Library
Module: GlrRen.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#ifndef __vlGlrRenderer_hh
#define __vlGlrRenderer_hh
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "Renderer.hh"
#include "gl.h"
class vlGlrRenderer : public vlRenderer
{
protected:
int NumberOfLightsBound;
public:
vlGlrRenderer();
void Render(void); // overides base
char *GetClassName() {return "vlGlrRenderer";};
void PrintSelf(ostream& os, vlIndent indent);
vlGeometryPrimitive *GetPrimitive(char *);
void ClearLights(void);
int UpdateActors(void);
int UpdateCameras(void);
int UpdateLights(void);
};
#endif
/*=========================================================================
Program: Visualization Library
Module: GlrRenW.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#ifndef __vlGlrRenderWindow_hh
#define __vlGlrRenderWindow_hh
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "RenderW.hh"
class vlGlrRenderWindow : public vlRenderWindow
{
protected:
int Gid;
int MultiSamples;
Window WindowId;
Window NextWindowId;
Display *DisplayId;
Colormap ColorMap;
public:
vlGlrRenderWindow();
char *GetClassName() {return "vlGlrRenderWindow";};
void PrintSelf(ostream& os, vlIndent indent);
vlRenderer *MakeRenderer();
vlActor *MakeActor();
vlLight *MakeLight();
vlCamera *MakeCamera();
void Start(void);
void Frame(void);
void Connect(void);
void WindowConfigure(void);
void WindowInitialize(void);
void Initialize(void);
virtual void SetFullScreen(int);
void WindowRemap(void);
void PrefFullScreen(void);
int *GetPosition();
int *GetSize();
void SetSize(int,int);
// Xwindow get set functions
Display *GetDisplayId();
void SetDisplayId(Display *);
Window GetWindowId();
void SetWindowId(Window);
vlSetMacro(MultiSamples,int);
vlGetMacro(MultiSamples,int);
};
#endif
/*=========================================================================
Program: Visualization Library
Module: GlrCam.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include <math.h>
#include "GlrRen.hh"
#include "GlrCam.hh"
// typecast if neccessary
void vlGlrCamera::Render(vlRenderer *ren)
{
this->Render((vlGlrRenderer *)ren);
}
// set the appropriate attributes in Glr for this camera
//
void vlGlrCamera::Render(vlGlrRenderer *ren)
{
float aspect[3];
float *vport;
float *bg_color;
long width,height;
long clr;
int left,right,bottom,top;
float twist;
int stereo;
// get the bounds of the window
getsize(&width,&height);
// find out if we should stereo render
stereo = ren->GetStereoRender();
// must use width -1 and height -1 because width*1.0 = width,
// but the maximum pixel value allowed is width -1
width--; height--;
vport = ren->GetViewport();
left = (int)(vport[0]*width);
right = (int)(vport[2]*width);
bottom = (int)(vport[1]*height);
top = (int)(vport[3]*height);
viewport(left,right,bottom,top);
aspect[0] = 1.0;
aspect[1] = (float)(top-bottom+1)/(float)(right-left+1);
ren->SetAspect(aspect);
mmode(MPROJECTION);
perspective((short)(10.0*this->ViewAngle), aspect[0] / aspect[1],
this->ClippingRange[0], this->ClippingRange[1]);
// get twist from camera object twist
twist = this->GetTwist();
twist = twist*1800.0/3.1415926;
// since lookat modifies the model view matrix do a push
// first and set the mmode. This will be undone in the
// render action after the actors! message sis sent
mmode(MVIEWING);
pushmatrix();
lookat(this->Position[0], this->Position[1], this->Position[2],
this->FocalPoint[0], this->FocalPoint[1], this->FocalPoint[2],
(short)(twist));
// get the background color
bg_color = ren->GetBackground();
// Set the background and clear the zbuff
clr = 0xff000000;
clr |= ((int)(255*bg_color[2])) << 16;
clr |= ((int)(255*bg_color[1])) << 8;
clr |= (int)(255*bg_color[0]);
if (ren->GetErase())
{
czclear(clr, getgdesc(GD_ZMAX));
vlDebugMacro(<< "czclear: " << clr << "\n");
}
// if we have a stereo renderer, draw other eye next time
if (stereo)
{
if (this->LeftEye) this->LeftEye = 0;
else this->LeftEye = 1;
}
}
/*=========================================================================
Program: Visualization Library
Module: GlrLgt.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include <math.h>
#include "GlrRen.hh"
#include "GlrLgt.hh"
// Use directional light instead so mirror lights behave nicer
static float light_info[] = {
LCOLOR, 0.0, 0.0, 0.0,
POSITION, 0.0, 0.0, 0.0, 0.0,
LMNULL
};
// typecast if neccessary
void vlGlrLight::Render(vlRenderer *ren,int light_index)
{
this->Render((vlGlrRenderer *)ren,light_index);
}
// set the appropriate attributes in Glr for this light
void vlGlrLight::Render(vlGlrRenderer *ren,int light_index)
{
float dx, dy, dz;
float color[3];
// get required info from light
color[0] = this->Intensity * this->Color[0];
color[1] = this->Intensity * this->Color[1];
color[2] = this->Intensity * this->Color[2];
dx = this->Position[0] - this->FocalPoint[0];
dy = this->Position[1] - this->FocalPoint[1];
dz = this->Position[2] - this->FocalPoint[2];
// define the light source
light_info[1] = color[0];
light_info[2] = color[1];
light_info[3] = color[2];
light_info[5] = dx;
light_info[6] = dy;
light_info[7] = dz;
vlDebugMacro(<< "Defining front light\n");
lmdef(DEFLIGHT, light_index, 0, light_info);
// define another mirror light if backlit is on
if (ren->GetBackLight())
{
light_info[5] = -dx;
light_info[6] = -dy;
light_info[7] = -dz;
vlDebugMacro(<< "Defining back light\n");
lmdef(DEFLIGHT, light_index + 1, 0, light_info);
}
}
/*=========================================================================
Program: Visualization Library
Module: KglrProp.cc
Language: C++
Date: 2/8/94
Version: 1.5
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include <math.h>
#include "GlrRen.hh"
#include "GlrProp.hh"
#include "GlrPrim.hh"
// temporary material structure
static float mat[] = {
ALPHA, 0.0,
AMBIENT, 0.0, 0.0, 0.0,
DIFFUSE, 0.0, 0.0, 0.0,
SPECULAR, 0.0, 0.0, 0.0,
SHININESS, 0.0,
LMNULL
};
// typecast if neccessary
void vlGlrProperty::Render(vlRenderer *ren)
{
this->Render((vlGlrRenderer *)ren);
}
// set the appropriate attributes in Glr for this property
void vlGlrProperty::Render(vlGlrRenderer *ren)
{
int i, method;
lmcolor (LMC_NULL);
mat[1] = this->Transparency;
mat[15] = this->SpecularPower;
for (i=0; i < 3; i++)
{
mat[i+3] = this->Ambient*this->AmbientColor[i];
mat[i+7] = this->Diffuse*this->DiffuseColor[i];
mat[i+11] = this->Specular*this->SpecularColor[i];
}
lmdef(DEFMATERIAL, 1, 0, mat);
lmbind(MATERIAL, 1);
lmbind (BACKMATERIAL, 0);
// Tell the geometry primitives about the default properties
vlGlrPrimitive::SetProperty(this);
// set interpolation
switch (this->Interpolation)
{
case VL_FLAT:
method = FLAT;
break;
case VL_GOURAUD:
case VL_PHONG:
method = GOURAUD;
break;
default:
method = GOURAUD;
break;
}
shademodel(method);
}
/*=========================================================================
Program: Visualization Library
Module: GlrRen.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include <math.h>
#include <iostream.h>
#include "GlrRen.hh"
#include "GlrProp.hh"
#include "GlrCam.hh"
#include "GlrLgt.hh"
#include "GlrPoly.hh"
#include "GlrTri.hh"
#include "GlrLine.hh"
#include "GlrPnt.hh"
#define MAX_LIGHTS 8
static float amb_light_info[] = {
AMBIENT, 0.2, 0.2, 0.2,
LMNULL
};
vlGlrRenderer::vlGlrRenderer()
{
}
int vlGlrRenderer::UpdateActors()
{
vlActor *anActor;
float visibility;
vlMatrix4x4 matrix;
int num;
int count = 0;
// set matrix mode for actors
mmode(MVIEWING);
// loop through actors
for (num = 1; num <= this->Actors.GetNumberOfMembers(); num++)
{
anActor = this->Actors.GetMember(num);
// if it's invisible, we can skip the rest
visibility = anActor->GetVisibility();
if (visibility == 1.0)
{
count++;
// build transformation
matrix = anActor->GetMatrix();
matrix.Transpose();
// insert model transformation
pushmatrix();
multmatrix((float (*)[4])(matrix[0]));
anActor->Render((vlRenderer *)this);
popmatrix();
}
}
return count;
}
int vlGlrRenderer::UpdateCameras ()
{
// update the viewing transformation
if (!this->ActiveCamera) return 0;
this->ActiveCamera->Render((vlRenderer *)this);
return 1;
}
void vlGlrRenderer::ClearLights (void)
{
short cur_light;
// define a lighting model and set up the ambient light.
// use index 11 for the heck of it. Doesn't matter except for 0.
// update the ambient light
amb_light_info[1] = this->Ambient[0];
amb_light_info[2] = this->Ambient[1];
amb_light_info[3] = this->Ambient[2];
lmdef(DEFLMODEL, 11, 0, amb_light_info);
lmbind(LMODEL, 11);
// now delete all the old lights
for (cur_light = LIGHT0;
cur_light < LIGHT0 + MAX_LIGHTS; cur_light++)
{
lmbind(cur_light,0);
}
this->NumberOfLightsBound = 0;
}
int vlGlrRenderer::UpdateLights ()
{
vlLight *light;
short cur_light;
float status;
int i;
int count = 0;
cur_light= this->NumberOfLightsBound + LIGHT0;
// set the matrix mode for lighting. ident matrix on viewing stack
mmode(MVIEWING);
pushmatrix();
for (i = 1; i <= this->Lights.GetNumberOfMembers(); i++)
{
light = this->Lights.GetMember(i);
status = light->GetSwitch();
// if the light is on then define it and bind it.
// also make sure we still have room.
if ((status > 0.0)&& (cur_light < (LIGHT0+MAX_LIGHTS)))
{
light->Render((vlRenderer *)this,cur_light);
lmbind(cur_light, cur_light);
// increment the current light by one
cur_light++;
count++;
// and do the same for the mirror source if backlit is on
// and we aren't out of lights
if ((this->BackLight > 0.0) &&
(cur_light < (LIGHT0+MAX_LIGHTS)))
{
lmbind(cur_light,cur_light);
// if backlighting is on then increment the current light again
cur_light++;
}
}
}
this->NumberOfLightsBound = cur_light - LIGHT0;
popmatrix();
return count;
}
void vlGlrRenderer::Render(void)
{
// standard render method
this->ClearLights();
this->DoCameras();
this->DoLights();
this->DoActors();
// clean up the model view matrix set up by the camera
mmode(MVIEWING);
popmatrix();
}