Delphix (3) of Delphi and DirectX: tdxdraw

Source: Internet
Author: User
Tags textout
In delphix, all we can see is drawn in tdxdraw.

Tdxdraw has two default drawing surfaces: tdxdraw. Surface and tdxdraw. Primary;
Generally, you need to first plot the image on the background (surface), and then use the tdxdraw. Flip command to switch between the front and back ends to see the rendering effect.

Tdxdraw. Flip replaces the surface and primary objects, so we can plot only on the surface;
Because of DirectX's working mechanism, this switching speed is exceptionally fast (just switching a pointer), so that it can complete very smooth animation and games.

You can also obtain the canvas object from the drawing surface of tdxdraw. Therefore, you can also use the drawing commands of GDI/GDI + in tdxdraw;
However, using GDI/GDI + and DirectX together should reduce the performance of DirectX, but this may always be better, at least better than using GDI/GDI + alone.

The dxdraw1.surface. Canvas object is used in the following example;
After using dxdraw1.surface. Canvas, be sure to release (dxdraw1.surface. Canvas. Release );

In addition, you often need to fill the surface with the specified color before drawing, for example, dxdraw1.surface. Fill (color value );
The color format here is different from that of Delphi, and the order of the color values used in HTML is the same, for example, $ ff0000 indicates red.

In this example:


Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, dxdraws; Type tform1 = Class (tform) dxdraw1: tdxdraw; button1: tbutton; button2: tbutton; Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.button1click (Sender: tobject); var STR: string; begin STR: = formatdatetime ('H: N: S: ZZ ', time); {Get the current time, accurate to milliseconds} dxdraw1.surface. fill ($ ff0000); {fill in red. Note that the color format is the same as that of HTML.} dxdraw1.surface. canvas. brush. style: = bsclear; dxdraw1.surface. canvas. font. color: = clyellow; dxdraw1.surface. canvas. font. size: = 16; dxdraw1.surface. canvas. textout (10, 10, STR); dxdraw1.surface. canvas. release; {release canvas object} dxdraw1.flip; end; {This is the same as the above function, but simplifies WRITING} procedure tform1.button2click (Sender: tobject); var STR: string; begin STR: = formatdatetime ('H: N: S: ZZ ', time); dxdraw1.surface. fill (0); {fill black} with dxdraw1.surface. canvas do begin brush. style: = bsclear; font. color: = cllime; font. size: = 16; textout (10, 10, STR); release; {release canvas object} end; dxdraw1.flip; end.
 
   
 

Form file:

Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 127 clientwidth = 201 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false pixelsperinch = 96 textheight = 13 object dxdraw1: tdxdraw left = 8 Top = 8 width = 185 Height = 81 autoinitialize = true autosize = true color = clblack display. fixedbitcount = false display. fixedratio = true display. fixedsize = true Options = [doallowreboot, dowaitvblank, docenter, do3d, dodirectx7mode, dohardware, doselectdriver] surfaceheight = 81 surfacewidth = 185 taborder = 0 traces = end object button1: tbutton left = 30 top = 95 width = 75 Height = 25 caption = 'button1' taborder = 1 onclick = button1click end object button2: tbutton left = 118 Top = 95 width = 75 Height = 25 caption = 'button2' taborder = 2 onclick = button2click endend
 
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.