⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 delphi 最好的3D控件GLScene_Demos
💻 PAS
字号:
{: Using materials in a TGLDirectOpenGL OnRender.<p>

   This demo shows how to dynamically create materials in a material library
   and use them in a TGLDirectOpenGL to render your own stuff.<br>
   The render is quite simple: two quads, each with its own texture. The
   TGLDirectOpenGL is placed in a small hierarchy with a torus and dummy cube,
   and the rotation animation are handled by those two object to show that
   the OnRender code uses the hierarchy.
}
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  GLCadencer, GLScene, GLObjects, GLTexture, GLMisc, GLBehaviours,
  GLWin32Viewer, GLGeomObjects;

type
  TForm1 = class(TForm)
    GLScene1: TGLScene;
    GLSceneViewer1: TGLSceneViewer;
    GLMaterialLibrary: TGLMaterialLibrary;
    GLCamera1: TGLCamera;
    DummyCube1: TGLDummyCube;
    Torus1: TGLTorus;
    DirectOpenGL1: TGLDirectOpenGL;
    GLLightSource1: TGLLightSource;
    GLCadencer1: TGLCadencer;
    procedure DirectOpenGL1Render(var rci: TRenderContextInfo);
    procedure FormCreate(Sender: TObject);
  private
    { D閏larations priv閑s }
  public
    { D閏larations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses OpenGL1x, JPeg;

procedure TForm1.FormCreate(Sender: TObject);
begin
   // dynamically create 2 materials and load 2 textures
   with GLMaterialLibrary do begin
      with AddTextureMaterial('wood', '..\..\media\ashwood.jpg') do
         Material.FrontProperties.Emission.Color:=clrGray50;
      with AddTextureMaterial('stone', '..\..\media\walkway.jpg') do
         Material.FrontProperties.Emission.Color:=clrGray50;
   end;
end;

procedure TForm1.DirectOpenGL1Render(var rci: TRenderContextInfo);
var
   material : TGLLibMaterial;
begin
   // disable face culling
   glDisable(GL_CULL_FACE);
   // 1st quad, textured with 'wood', using standard method
   GLMaterialLibrary.ApplyMaterial('wood', rci);
   glBegin(GL_QUADS);
      glTexCoord2f(0, 1);  glVertex3f(0.5, 0.5, -0.5);
      glTexCoord2f(0, 0);  glVertex3f(-0.5, 0.5, -0.5);
      glTexCoord2f(1, 0);  glVertex3f(-0.5, 0, 0.5);
      glTexCoord2f(1, 1);  glVertex3f(0.5, 0, 0.5);
   glEnd;
   GLMaterialLibrary.UnApplyMaterial(rci);
   // 2nd quad, textured with 'stone'
   // we "manually" apply the material, this can be usefull if you want to have
   // some dynamic material control
   material:=GLMaterialLibrary.Materials.GetLibMaterialByName('stone');
   material.Material.Apply(rci);
   glBegin(GL_QUADS);
      glTexCoord2f(0, 1);  glVertex3f(0.5, -0.5, -0.5);
      glTexCoord2f(0, 0);  glVertex3f(0.5, 0, 0.5);
      glTexCoord2f(1, 0);  glVertex3f(-0.5, 0, 0.5);
      glTexCoord2f(1, 1);  glVertex3f(-0.5, -0.5, -0.5); 
   glEnd;
   material.Material.UnApply(rci);
   // enable face culling again
   glEnable(GL_CULL_FACE);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -