home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue42 / opengl / glStereo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-11-22  |  4.6 KB  |  154 lines

  1.  (*
  2.  
  3.  *)
  4.  (*******************************************************)
  5.  unit glStereo;
  6.                         interface
  7.  (*******************************************************)
  8.   Uses  Windows,Classes, opengl, GLFuncs, GLTexWin;
  9.  
  10.  Type
  11.  
  12.   TCustomGLStereo = class(TCustomGLTexture)
  13.   // has all the stereo stuff
  14.    private
  15.    // key to accessing the render stuff
  16.   (*   procedure PaintWindow(DC: HDC);             override;*)
  17.    // Draw the window called by PaintWindow or the thread
  18.  
  19.    protected
  20.  
  21.     fStereoOn     : Boolean ; //signal for stereo mode
  22.     fStereoState  : GLStereoState;  //Current Stereo State
  23.  
  24.     Procedure GLRenderWindow(DoSwap:Boolean);         override;
  25.     Procedure Clearscreen;                 override;
  26.     //clear all the glbuffers
  27.  
  28.  
  29.     Procedure SetStereoOn(aVal:Boolean);
  30.     Procedure SetStereoMode(aVal:GLStereoState);
  31.  
  32.    Public
  33.     constructor Create(AOwner: TComponent); Override; 
  34.  
  35.     Procedure BuildDisplayLists;              Override;
  36.    {This procedure builds all the standard display objects for the gl
  37.    session}
  38.  
  39.     Property StereoOn   : Boolean       Read fStereoOn    Write SetStereoOn;
  40.     Property StereoState: GLStereoState Read fStereoState Write SetStereoMode;
  41.   end;
  42.  
  43. {procedure Register;}
  44. (*************************************************************)
  45. (*************************************************************)
  46.                         implementation
  47. (*************************************************************)
  48. constructor TCustomGLStereo.Create(AOwner: TComponent);
  49. Begin
  50.   Inherited ;
  51.   fStereoState:=steRedBlue;
  52. end;
  53. (******* ******************************************************)
  54.  Procedure TCustomGLStereo.BuildDisplayLists;
  55.      Begin
  56.       If assigned(fShareGL) or not fStdDisplayList then exit;
  57.       Inherited ;
  58.       iF FGENERALlISTS=0 then exit;
  59.     end;
  60. (*************************************************************)
  61.  Procedure TCustomGLStereo.SetStereoOn(aVal:Boolean);
  62.    Begin
  63.      If fStereoOn=aVal then exit;
  64.      fStereoOn:=aVal;
  65.      If fStereoOn then
  66.       Begin
  67.         LightingOn:=True;
  68.         HeadLightOn:=True;
  69.         Perspective:=True;
  70.       end;
  71.      Repaint;
  72.    end;
  73. (*************************************************************)
  74.  Procedure TCustomGLStereo.SetStereoMode(aVal:GLStereoState);
  75.    Begin
  76.     If aVal=fStereoState then exit;
  77.     fStereoState:=aVal;
  78.     Repaint;
  79.    end;
  80. (**************************************************************)
  81. Procedure TCustomGLStereo.Clearscreen;
  82.     //clear all the glbuffers
  83. Begin
  84.   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_ACCUM_BUFFER_BIT);
  85. end;
  86. (*************************************************************)
  87. Procedure TCustomGLStereo.GLRenderWindow(DoSwap:Boolean);
  88.    // Draw the window called by PaintWindow or the thread
  89.      Procedure DoRedBlue;
  90.         Var amb:tGLLightVal;
  91.             aDist:Double;
  92.         Begin
  93.            ClearScreen;
  94.            aDist:=viewer.Range;
  95.            Viewer.ShiftLookAt(aDist);
  96.          //setup left eye
  97.             With amb do
  98.              Begin
  99.               R:=1;G:=0;B:=0;A:=1//Default values
  100.              end;
  101.            SetGlobalAmbient(amb);
  102.            Viewer.SetViewPoint(vLeftEye);
  103.            Inherited GLRenderWindow(false);
  104.          // add to accumulation buffer
  105.            glAccum(GL_accum,1);
  106.  
  107.            fRebuildNeeded:=True;
  108.  
  109.          //setup Right eye
  110.             With amb do
  111.              Begin
  112.               R:=0;G:=1;B:=1;A:=1//Default values
  113.              end;
  114.            SetGlobalAmbient(amb);
  115.            Viewer.SetViewPoint(vRightEye);
  116.            Inherited GLRenderWindow(false);
  117.            glAccum(GL_Accum,1);
  118.  
  119.          // put it all together and swap in
  120.            glAccum(GL_Return,1);
  121.  
  122.            If not fDrawToOther then
  123.               Begin
  124.                  If SwapBuffers(fRenderDC) and fGDIGeneric and fpfd_Swap_Copy
  125.                     then  fValidBuffer:=True;
  126.               end;
  127.             With amb do
  128.              Begin
  129.               R:=1;G:=1;B:=1;A:=1.0//Default values
  130.              end;
  131.            fLights[0].SetLightColor(amb);
  132.            Viewer.SetViewPoint(vCentrePt);
  133.            Viewer.ShiftLookAt(-aDist);
  134.         end;
  135.    Begin
  136.       If not fStereoOn then inherited
  137.       else
  138.        Case  fStereoState of
  139.          steNone:Inherited;
  140.          steRedBlue:DoRedBlue;
  141.          steBuffer:inherited;
  142.        end;
  143.    end;
  144. (*************************************************************)
  145. (*
  146. procedure TCustomGLStereo.PaintWindow(DC: HDC);
  147. Begin
  148.     Inherited;
  149. end;
  150. *)
  151. (*************************************************************)
  152.  
  153. end.
  154.