Commit 9dbca6b3 authored by Ken Martin's avatar Ken Martin
Browse files

Initial revision

parent 64b89e97
/*=========================================================================
Program: Visualization Toolkit
Module: OglrCam.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Toolkit. 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
=========================================================================*/
// .NAME vtkOglrCamera - SGI OpenGL camera
// .SECTION Description
// vtkOglrCamera is a concrete implementation of the abstract class vtkCamera.
// vtkOglrCamera interfaces to the Silicon Graphics OpenGL rendering library.
#ifndef __vtkOglrCamera_hh
#define __vtkOglrCamera_hh
#include "CamDev.hh"
class vtkOglrRenderer;
class vtkOglrCamera : public vtkCameraDevice
{
public:
virtual char *GetClassName() {return "vtkOglrCamera";};
void Render(vtkCamera *cam, vtkRenderer *ren);
void Render(vtkCamera *cam, vtkOglrRenderer *ren);
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: OglrLgt.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Toolkit. 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
=========================================================================*/
// .NAME vtkOglrLight - SGI OpenGL light
// .SECTION Description
// vtkOglrLight is a concrete implementation of the abstract class vtkLight.
// vtkOglrLight interfaces to the Silicon Graphics OpenGL rendering library.
#ifndef __vtkOglrLight_hh
#define __vtkOglrLight_hh
#include "LgtDev.hh"
class vtkOglrRenderer;
class vtkOglrLight : public vtkLightDevice
{
protected:
public:
char *GetClassName() {return "vtkOglrLight";};
void Render(vtkLight *lgt, vtkRenderer *ren,int light_index);
void Render(vtkLight *lgt, vtkOglrRenderer *ren,int light_index);
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: OglrProp.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Toolkit. 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
=========================================================================*/
// .NAME vtkOglrProperty - SGI OpenGL property
// .SECTION Description
// vtkOglrProperty is a concrete implementation of the abstract class
// vtkProperty. vtkOglrProperty interfaces to the Silicon Graphics
// OpenGL rendering library.
#ifndef __vtkOglrProperty_hh
#define __vtkOglrProperty_hh
#include "PropDev.hh"
class vtkOglrRenderer;
class vtkOglrProperty : public vtkPropertyDevice
{
public:
char *GetClassName() {return "vtkOglrProperty";};
void Render(vtkProperty *prop, vtkRenderer *ren);
void Render(vtkProperty *prop, vtkOglrRenderer *ren);
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: OglrRen.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Toolkit. 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
=========================================================================*/
// .NAME vtkOglrRenderer - SGI OpenGL renderer
// .SECTION Description
// vtkOglrRenderer is a concrete implementation of the abstract class
// vtkRenderer. vtkOglrRenderer interfaces to the Silicon Graphics OpenGL
// graphics library.
#ifndef __vtkOglrRenderer_hh
#define __vtkOglrRenderer_hh
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "Renderer.hh"
#include <GL/gl.h>
class vtkOglrRenderer : public vtkRenderer
{
protected:
int NumberOfLightsBound;
public:
vtkOglrRenderer();
void Render(void); // overides base
char *GetClassName() {return "vtkOglrRenderer";};
void PrintSelf(ostream& os, vtkIndent indent);
vtkGeometryPrimitive *GetPrimitive(char *);
void ClearLights(void);
int UpdateActors(void);
int UpdateCameras(void);
int UpdateLights(void);
// stereo related stuff
virtual float *GetCenter();
virtual void DisplayToView();
virtual void ViewToDisplay();
virtual int IsInViewport(int x,int y);
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: OglrRenW.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Toolkit. 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
=========================================================================*/
// .NAME vtkOglrRenderWindow - SGI OpenGL rendering window
// .SECTION Description
// vtkOglrRenderWindow is a concrete implementation of the abstract class
// vtkRenderWindow. vtkOglrRenderer interfaces to the Silicon Graphics
// OpenGL graphics library.
#ifndef __vtkOglrRenderWindow_hh
#define __vtkOglrRenderWindow_hh
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "XRenWin.hh"
#include "GL/glx.h"
class vtkOglrRenderWindow : public vtkXRenderWindow
{
protected:
GLXContext ContextId;
int MultiSamples;
long OldMonitorSetting;
public:
vtkOglrRenderWindow();
char *GetClassName() {return "vtkOglrRenderWindow";};
void PrintSelf(ostream& os, vtkIndent indent);
vtkRenderer *MakeRenderer();
vtkLightDevice *MakeLight();
vtkCameraDevice *MakeCamera();
vtkTextureDevice *MakeTexture();
vtkPropertyDevice *MakeProperty();
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);
void SetSize(int,int);
virtual int GetDesiredDepth();
virtual Colormap GetDesiredColormap();
virtual Visual *GetDesiredVisual();
XVisualInfo *GetDesiredVisualInfo();
vtkSetMacro(MultiSamples,int);
vtkGetMacro(MultiSamples,int);
// stereo rendering stuff
virtual void StereoUpdate();
// Description:
// Set/Get the pixel data of an image, transmitted as RGBRGB...
virtual unsigned char *GetPixelData(int x,int y,int x2,int y2,int front);
virtual void SetPixelData(int x,int y,int x2,int y2,unsigned char *,int front);
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: OglrText.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Toolkit. 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
=========================================================================*/
// .NAME vtkOglrTexture - SGI OpenGL texture map
// .SECTION Description
// vtkOglrTexture is a concrete implementation of the abstract class
// vtkTexture. vtkOglrTexture interfaces to the Silicon Graphics OpenGL
// rendering library.
#ifndef __vtkOglrTexture_hh
#define __vtkOglrTexture_hh
#include "TextDev.hh"
class vtkOglrRenderer;
class vtkOglrTexture : public vtkTextureDevice
{
public:
vtkOglrTexture();
char *GetClassName() {return "vtkOglrTexture";};
void Load(vtkTexture *txt, vtkRenderer *ren);
void Load(vtkTexture *txt, vtkOglrRenderer *ren);
protected:
vtkTimeStamp LoadTime;
long Index;
static long GlobalIndex;
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: OglrCam.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Toolkit. 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 "OglrRenW.hh"
#include "OglrRen.hh"
#include "OglrCam.hh"
void oglrlookat(float vx, float vy, float vz, float px, float py, float pz,
float twist )
{
GLfloat theta, phi;
float temp1, temp2;
temp1 = (px-vx)*(px-vx) + (pz-vz)*(pz-vz);
if ( temp1 == 0 )
{
cerr << "in OglrCamera: zero denominator in lookat!\n";
}
theta = (GLfloat)atan2(
((double)(( (px-vx) / (float)(sqrt((double)(temp1)))))),
((double)(( (vz-pz) / (float)(sqrt((double)(temp1)))))) );
theta *= 180.0/M_PI;
temp2 = (px-vx)*(px-vx) + (py-vy)*(py-vy) + (pz-vz)*(pz-vz);
if ( temp2 == 0 )
{
cerr << "zero denominator in lookat!\n";
}
phi = (GLfloat)atan2(
(double)(( (vy-py) / (float)(sqrt((double)(temp2))))),
(double)(( sqrt((double)((px-vx)*(px-vx)+(pz-vz)*(pz-vz))) /
(sqrt((double)(temp2))))) );
phi *= 180.0/M_PI;
glRotatef( (GLfloat)(-twist), 0.0, 0.0, 1.0 );
glRotatef( phi, 1.0, 0.0, 0.0 );
glRotatef( theta, 0.0, 1.0, 0.0 );
glTranslatef( (GLfloat)( -vx ), (GLfloat)( -vy ), (GLfloat)( -vz ) );
}
// bonus stereo perspective function - from manual
void oglrstereopersp(float fovy, float aspect, float near, float far,
float conv, float eye)
{
float left, right, top, bottom;
float gltan;
eye = tan(eye*3.1415926/180.0)*conv;
gltan = tan(fovy/2.0*M_PI/180.0);
top = gltan*near;
bottom = -top;
gltan = tan(fovy*aspect/2.0*M_PI/180.0);
left = -gltan*near - eye/conv*near;
right = gltan*near - eye/conv*near;
glLoadIdentity();
glFrustum(left,right,bottom,top,near,far);
glTranslatef(-eye,0.0,0.0);
}
// Description:
// Implement base class method.
void vtkOglrCamera::Render(vtkCamera *cam, vtkRenderer *ren)
{
this->Render(cam, (vtkOglrRenderer *)ren);
}
// Description:
// Actual camera render method.
void vtkOglrCamera::Render(vtkCamera *cam, vtkOglrRenderer *ren)
{
float aspect[3];
float *vport;
float *bg_color;
long clr;
int left,right,bottom,top;
float twist;
int stereo;
float *Position, *FocalPoint, *ClippingRange;
int *size;
// get the bounds of the window
size = ((vtkOglrRenderWindow*)(ren->GetRenderWindow()))->GetSize();
// find out if we should stereo render
stereo = ((vtkOglrRenderWindow*)(ren->GetRenderWindow()))->GetStereoRender();
vport = ren->GetViewport();
left = (int)(vport[0]*(size[0] -1));
right = (int)(vport[2]*(size[0] - 1));
// if were on a stereo renderer draw to special parts of screen
if (stereo)
{
switch ((ren->GetRenderWindow())->GetStereoType())
{
case VTK_STEREO_CRYSTAL_EYES:
if (cam->GetLeftEye())
{
bottom = (int)(532 + (1023-532)*vport[1]);
top = (int)(532 + (1023-532)*vport[3]);
}
else
{
bottom = (int)(491*vport[1]);
top = (int)(491*vport[3]);
}
break;
default:
bottom = (int)(vport[1]*(size[1] -1));
top = (int)(vport[3]*(size[1] - 1));
}
}
else
{
bottom = (int)(vport[1]*(size[1] -1));
top = (int)(vport[3]*(size[1] - 1));
}
glViewport(left,bottom,(right-left+1),(top-bottom+1));
glEnable( GL_SCISSOR_TEST );
glScissor( left, bottom,(right-left+1),(top-bottom+1));
/* for stereo we have to fiddle with aspect */
if (stereo)
{
switch ((ren->GetRenderWindow())->GetStereoType())
{
case VTK_STEREO_CRYSTAL_EYES:
aspect[0] = 1.0;
aspect[1] = 2.0*(float)(top-bottom+1)/(float)(right-left+1);
break;
default:
aspect[0] = 1.0;
aspect[1] = (float)(top-bottom+1)/(float)(right-left+1);
}
}
else
{
aspect[0] = 1.0;
aspect[1] = (float)(top-bottom+1)/(float)(right-left+1);
}
ren->SetAspect(aspect);
glMatrixMode( GL_PROJECTION);
ClippingRange = cam->GetClippingRange();
Position = cam->GetPosition();
FocalPoint = cam->GetFocalPoint();
// if were on a stereo renderer use correct perspective for eye
if (stereo)
{
if (cam->GetLeftEye())
{
oglrstereopersp(cam->GetViewAngle(), aspect[0] / aspect[1],
ClippingRange[0],ClippingRange[1],
cam->GetDistance(),-1.0*cam->GetEyeAngle());
}
else
{
oglrstereopersp(cam->GetViewAngle(), aspect[0] / aspect[1],
ClippingRange[0],ClippingRange[1],
cam->GetDistance(),1.0*cam->GetEyeAngle());
}
}
else
{
oglrstereopersp(cam->GetViewAngle(), aspect[0] / aspect[1],
ClippingRange[0], ClippingRange[1],
cam->GetDistance(),0.0);
}
// get twist from camera object twist
twist = cam->GetTwist();
twist = twist*180.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
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
oglrlookat(Position[0], Position[1], Position[2],
FocalPoint[0], FocalPoint[1], FocalPoint[2],
twist);
// get the background color
bg_color = ren->GetBackground();
if (ren->GetErase())
{
glClearColor( ((GLclampf)(bg_color[0])),
((GLclampf)(bg_color[1])),
((GLclampf)(bg_color[2])),
((GLclampf)(1.0)) );
glClearDepth( (GLclampd)( 1.0 ) );
vtkDebugMacro(<< "glClear\n");
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
// if we have a stereo renderer, draw other eye next time
if (stereo)
{
if (cam->GetLeftEye()) cam->SetLeftEye(0);
else cam->SetLeftEye(1);
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: OglrLgt.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Toolkit. 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 "OglrRen.hh"
#include "OglrLgt.hh"
// Description:
// Implement base class method.
void vtkOglrLight::Render(vtkLight *lgt, vtkRenderer *ren,int light_index)
{
this->Render(lgt, (vtkOglrRenderer *)ren,light_index);
}
// Description:
// Actual light render method.
void vtkOglrLight::Render(vtkLight *lgt, vtkOglrRenderer *ren,int light_index)
{
float dx, dy, dz;
float color[4];
float *Color, *Position, *FocalPoint;
float Intensity;
float Info[4];
// get required info from light
Intensity = lgt->GetIntensity();
Color = lgt->GetColor();
color[0] = Intensity * Color[0];
color[1] = Intensity * Color[1];
color[2] = Intensity * Color[2];
color[3] = 1.0;
FocalPoint = lgt->GetFocalPoint();
Position = lgt->GetPosition();
dx = FocalPoint[0] - Position[0];
dy = FocalPoint[1] - Position[1];
dz = FocalPoint[2] - Position[2];
glLightfv( light_index, GL_DIFFUSE, color);
glLightfv( light_index, GL_SPECULAR, color);
if( ren->GetBackLight())
{
glLightfv( light_index+1, GL_DIFFUSE, color);
glLightfv( light_index+1, GL_SPECULAR, color);
}
// define the light source
if (!lgt->GetPositional())
{
Info[0] = -dx;
Info[1] = -dy;
Info[2] = -dz;
Info[3] = 0.0;
glLightfv( light_index, GL_POSITION, Info );
// define another mirror light if backlit is on
if (ren->GetBackLight())
{
Info[0] = dx;
Info[1] = dy;
Info[2] = dz;
Info[3] = 0.0;
glLightfv( light_index + 1, GL_POSITION, Info );
}
}
else
{
Info[0] = Position[0];
Info[1] = Position[1];
Info[2] = Position[2];
Info[3] = 1.0;
glLightfv( light_index, GL_POSITION, Info );
Info[0] = dx;
Info[1] = dy;
Info[2] = dz;
glLightfv( light_index, GL_SPOT_DIRECTION, Info );
Info[0] = lgt->GetExponent();
glLightfv( light_index, GL_SPOT_EXPONENT, Info );
Info[0] = lgt->GetConeAngle();
glLightfv( light_index, GL_SPOT_CUTOFF, Info );