Delphi FireMonkey 3D programming, delphifiremonkey
A Preliminary Study on Delphi FireMonkey 3D programming: The FireMonkey framework of Delphi supports 3D programming. For cross-platform purposes, Delphi has built a virtual 3D framework on this framework. Similar to OpenGL, Delphi has the concept of Shader. Therefore, the code is similar to OpenGL code. Only OpenGL APIs are C-based, and many data types correspond to FireMonkey. They have the same name and similar usage, but they are all objects.
If you drag a few 3D controls to the interface, you can also do 3D programming, but the effect is limited. Therefore, if you really want to do 3D programming, you have to write your own code. That is, the concepts of vertex coordinates, materials, lights, and so on are similar to those of OpenGL.
Unfortunately, there are too few articles on FireMonkey for 3D programming on the Internet. A demo program that comes with Delphi is Lowlevel3D, which can be found at the bottom of the folder of the example program after it is installed.
Here, I tested how to write code and draw images on FireMonkey's 3D interface.
1. Create a FireMonkey project and select 3D project. In this way, you can create a project. Its main Form is inherited from TForm3D.
2. write code in the Form OnRender event.
3. Drag a Timer and write "Invalidate" in the event to trigger the program screen and the OnRender event.
4. The OnRender event provides the Context of the current window interface, which is very important. Drawing depends on it. It provides some plotting methods.
5. There is a Helper class in Context. Here I will do a simple test and I will not create any vertex or anything. I will use this Helper method to draw a blue rectangle to the screen.
The Code is as follows:
Procedure TForm3.Form3DRender (Sender: TObject; Context: TContext3D); var Center, Size: TPoint3D; AOpacity: Single; AColor: TAlphaColor; begin // you can use Context to draw your own images in 3D mode. Here is an abstraction layer Code implemented by FireMonkey. Based on the platform, OpenGL or D3D Center: = TPoint3d will be called. create (0, 0, 0); Size: = TPoint3d. create (-1, 1, 0); AOpacity: = 1; AColor: = TAlphaColorRec. blue; Context. fillCube (Center, Size, AOpacity, AColor); end; procedure TForm3.Timer1Timer (Sender: TObject); begin Invalidate; end;
Here, TPoint3D is declared in the System. Math. Vectors unit, so the uses unit is required.
The above code passes the test.