0

Is there a way to write text on the surface of a sphere component in FireMonkey, short of creating a bitmap with the text, and importing the text to a TextureMaterialSource?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52

1 Answers1

0

I'm unsure on how you'd go about writing directly to the surface as I've not dealt with the internals of the 3D side of Firemonkey. However, I can go halfway with such a solution.

One possible solution is to use the MakeScreenshot function (which returns a TBitmap result). For example, add a TEdit and a TLabel (or TText) to your form. Using either livebindings or good old label1.text := edit1.text code, you'll be able to set up the screenshot source with the text you wish to display.

I'm assuming you've got a TSphere and a TTextureMaterialSource on your form. Add a TButton onto your form, and use something like this in the OnClick event;

var
  Bmp : TBitmap;
  mstream : TMemorystream;
begin
  mstream := TMemorystream.Create;
  bmp := Label1.MakeScreenshot;
  bmp.SaveToStream(mstream);
  tex.Texture.LoadFromStream(mstream);
  mstream.Free;
end;

Note: tex is the texture object.

I briefly wrote that up but couldn't get it working (presumably because there's more work that needs to be done after the texture has been loaded). It should give you a basic idea of where to work from.

Scott P
  • 1,462
  • 1
  • 19
  • 31