我用这个函数来获取材料
function AddMaterial(aMatLib: TGlMaterialLibrary; aFileName, aMaterialName: string):TGlLibMaterial;
begin
result := aMatLib.Materials.Add;
with result do
begin
with Material do
begin
MaterialOptions := [moIgnoreFog, moNoLighting];
Texture.Disabled := false;
BlendingMode := bmTransparency;
Texture.TextureMode := tmModulate;
with FrontProperties do
begin
Ambient.SetColor(1, 1, 1, 1);
Diffuse.SetColor(1, 1, 1, 1);
Emission.SetColor(1, 1, 1, 1);
Specular.SetColor(1, 1, 1, 1);
end;
Texture.ImageClassName := 'TGLCompositeImage';
if ExtractFileExt(aFileName) = '' then
TGLCompositeImage(Texture.Image).LoadFromFile(aFileName + '.png')
else
TGLCompositeImage(Texture.Image).LoadFromFile(aFileName);
//TGLCompositeImage(Texture.Image).LoadFromFile(aFileName);
end;
Name := aMaterialName;
end;
end;
其次,我添加了一个鼠标移动过程
首先是 const 向量颜色
const
OnMoveInObjects_Color: TColorVector = (0.243, 0.243, 0.243, 1.000);
OnOutObjects_Color: TColorVector = (0.000, 0.000, 0.000, 1.000);
创建对象
fsExit:= TGLHUDSprite.CreateAsChild(MainForm.Dummy_mainmenu);
fsExit.Material.MaterialLibrary:= MatLib;
fsExit.Material.LibMaterialName:= 'bexit';
fsExit.SetSquareSize(50);
fsExit.Position.X:= CenterX;
fsExit.Position.Y:= 30;
fsExit.Visible:= true;
然后程序
procedure Check_Mouse_UpPlayer(x,y:Integer);
var
sTVol: FLOAT;
begin
if MainForm.IsMouseOverImage(fsExit,x,y) then
begin
fsExit.Material.FrontProperties.Emission.Color:= OnMoveInObjects_Color;
if IsKeyDown(VK_LBUTTON) then
begin
fade_blur:= true;
ShowExit;
end;
end
else
fsExit.Material.FrontProperties.Emission.Color:= OnOutObjects_Color;
end;
这是 ismouseoverImage 函数...
function TMainForm.IsMouseOverImage(const AButton: TGLHudSprite; const X, Y: Integer):Boolean;
begin
Result := (X >= AButton.Position.X - AButton.Width / 2) and (X <= AButton.Position.X + AButton.Width / 2) and
(Y >= AButton.Position.Y - AButton.Height / 2) and (Y <= AButton.Position.Y + AButton.Height / 2);
end;
现在,当鼠标悬停在图像上时,材料会改变发射颜色,但我没有得到结果......(我什么也没看到)。
我做错了什么...?
谢谢...