I try to show an image in a TGLHudSprite in some odd way...
Here is my try..
i have a material library and a hudsprite...
myMatlib: TGLMaterialLibrary
mySprite: TGLHudSprite
next i create this objects...
myMatlib:= TGLMaterialLibrary.Create(self);
mySprite:= TGLHudSprite.CreateAsChild(MainScene.Background);
mySprite.Material.MaterialLibrary:= myMatlib;
mySprite.Material.LibMaterialName:= '';
mySprite.position.x:= 512;
mySprite.position.y:= 384;
mySprite.visible:= true;
run it and logical mySprite shows nothing... now i add a material... with this function..
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;
Texture.TextureMode := tmModulate;
BlendingMode := bmTransparency;
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);
end;
Name := aMaterialName;
end;
end;
so i add a material with...
AddMaterial(myMatlib,'c:\pic.png','pic');
and then i set the material in my hudSprite...
mySprite.material.libmaterialname:= 'pic';
Everything works fine for now...
The thing i want to do is to freeandnil my material library recreated again, add a different material with the same name 'pic' and show it in my hudsprite...
so i make this....
FreeAndNil(myMatlib);
AddMaterial(myMatlib,'c:\spic.png','pic');
mySprite.material.libmaterialname:= 'pic';
With this i get nothing but only a black picture...
What i am doing wrong...?
Btw the material loaded correcty bcs in a second sprite i create and not setting any other material it shows the "pic" correctly...
Maybe you need do this again: mySprite.Material.MaterialLibrary:= myMatlib; mySprite.Material.LibMaterialName:= 'myMaterialName';