Direct2d 1.1 Development Notes Special Effects (2) simple custom Special Effects

Source: Internet
Author: User
Tags xml example

(For more information, see the source)


This section introduces a simple custom special effect as a concept.

First, the header file is required.

#include <d2d1effectauthor.h>#include <d2d1effecthelpers.h>

To implement a custom D2d effect, you must inherit id2d1effectimpl and implement its interface.


Well, this is because we only want to introduce the concept, so this custom special effect is set as a shadow, so does Microsoft.


The implementation is ready for use, because the input of special effects can also be special effects.


Transform

Transform Graph,

So the tree should be inside


In the previous section, we know that a special effect can be created using a guid, so we shouldRegister Special Effects:

Use id2d1factory1: register1_tfromstring for special effect registration

Parameter 1: User-Defined guid to be registered

Parameter 2: an XML string used to describe the effect

Parameter 3: bound control variable array

Parameter 4: array Length

Parameter 5: Create an object pointer to call a function. We recommend that you use a private static member method.


The GUID generation tool is provided with vs express for Windows desktop.

Tool-create guid

You can create a guid. If define_guid is used, we recommend that you delay the location where the "initguid. H" file is contained. Otherwise, the link will fail.




An XML example is as follows:

// The first line cannot contain \ n. I don't know if it is a bug const wchar * pszxml = LR "XML (<? XML version = "1.0"?> <Effect> <! -- System Properties note that name does not support Chinese characters --> <property name = "displayname" type = "string" value = "shadow effect"/> <property name = "author" Type = "string" value = "dustpg"/> <property name = "category" type = "string" value = "transform"/> <property name = "Description" type =" string "value =" such as question "/> <inputs> <input name =" Source "/> </inputs> <! -- Custom attributes can be used to describe input variables --> <property name = 'offset' type = 'vector2'> <property name = 'displayname' type = 'string' value = 'image offset '/> <property name = 'Min' type = 'vector2' value =' (-1000.0, -1000.0) '/> <property name = 'max' type = 'vector2' value = '(1000.0, 1000.0) '/> <property name = 'default' type = 'vector2' value =' (0.0, 0.0) '/> </property> </Effect>) XML ";

Use the C ++ 11 sound source string to easily create strings such as scripts and XML.

The format is not required. You can understand it at a glance. Custom Attributes are not random. refer to the following

(If there is a byte array, isn't it random? bytes ( ̄) bytes)

Data Type Corresponding XML Value
Pwstr String
Bool Bool
Uint Uint32
Int Int32
Float Float
D2d_vector_2f Vector2
D2d_vector_3f Vector3
D2d_vector_4f Vector4
D2d_matrix_3x2_f Matrix3x2
D2d_matrix_4x3_f Matrix4x3
D2d_matrix_4x4_f Matrix4x4
D2d_matrix_5x4_f Matrix5x4
Byte [] Blob
Iunknown * Iunknown
Id2d1colorcontext* Colorcontext
CLSID CLSID
Enumeration (D2d1_interpolation_mode, Etc .) Enum


Control variable binding:

Required: name, read callback interface, and write callback interface.

The two interfaces are member methods.


For example, what we write in XML is a binding control variable: Two-dimensional vector.

const D2D1_PROPERTY_BINDING bindings[] = {        D2D1_VALUE_TYPE_BINDING(L"Offset", &SetOffset, &GetOffset),    };


In this way, create a binding

The two methods are declared as follows:

    HRESULT         SetOffset(D2D_VECTOR_2F offset);    D2D_VECTOR_2F   GetOffset();




Create an object in the function dynamically.




In this way, you can create a special effect. The next step is to implement the id2d1effectimpl interface,

Id2d1effectimpl inherits from iunknown, so I won't talk about how to implement the three interfaces of this old guy.


Id2d1effectimpl: Initialize initializes the object. This method is called after the object is created.

Used to initialize and prepare data, and set the initial transformation logic diagram.


Id2d1effectimpl: setgraph is called when the input quantity changes. Most special effects are input objects,

You only need to return e_notimpl. If there are multiple numbers, you need to handle them by yourself.


Id2d1effectimpl: prepareforrender will be called before being rendered. For example, we modified the degree of Gaussian blur,

To change the output, you need to prepare it.

Here we can modify the deviation quantity.



Implement logical chart settings:


If there is only one transformation, simply use id2d1transformgraph: setsingletransformnode.

However, our shadow has two conversion nodes: the shadow effect and translation conversion that comes with D2d.


The initialization method provides an id2d1javastcontext parameter, which can be used

Id2d1effectcontext: createeffect creates registered special effects, and there are some built-in transformations.



Add transition nodes:

Use id2d1transformgraph: addnode to add all transformation nodes first... This is a static linked list. Oh no, what is the implementation of the static tree?


Id2d1transformgraph: connecttow.tinput connects the specified input end of this effect to the specified input end of the specified Transformation

Id2d1transformgraph: connectnode connects the output end of the former to the input end specified by the latter

Id2d1transformgraph: setoutputnode uses the output end of the specified transformation as the output end of this special effect.


Example: familiar with connecting nodes

For example, we want to implement an advanced shadow-display the original input image.


Connection diagram (assuming that the object has been created andAddnode):

        pTransformGraph->ConnectToEffectInput(0, pShadow, 0);        pTransformGraph->ConnectNode(pShadow, p2DAffineTransform, 0);        pTransformGraph->ConnectNode(p2DAffineTransform, pComposite, 0);        pTransformGraph->ConnectToEffectInput(0, pComposite, 1);        pTransformGraph->SetOutputNode(pComposite);


More complex examples:


Connection diagram (assuming that the object has been created and has been addnode ):

        pTransformGraph->ConnectToEffectInput(0, pArithmeticComposite, 0);        pTransformGraph->ConnectToEffectInput(0, pShadow, 0);        pTransformGraph->ConnectNode(pShadow, pCompositeV1, 0);        pTransformGraph->ConnectNode(pShadow, pPointSpecular, 0);        pTransformGraph->ConnectNode(pPointSpecular, pCompositeV1, 1);        pTransformGraph->ConnectNode(pShadow, p2DAffineTransform, 0);        pTransformGraph->ConnectNode(pCompositeV1, pArithmeticComposite, 1);        pTransformGraph->ConnectNode(pShadow, p2DAffineTransform, 0);        pTransformGraph->ConnectNode(pArithmeticComposite, pCompositeV2, 0);        pTransformGraph->ConnectNode(p2DAffineTransform, pCompositeV2, 1);        pTransformGraph->SetOutputNode(pCompositeV2);


Now, the example of shadow is provided below.


Only shadow...


: Click here


Direct2d 1.1 Development Notes Special Effects (2) simple custom Special Effects

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.