-
Notifications
You must be signed in to change notification settings - Fork 0
2. Create your first plugin
We are going to recreate the Solid Color Source from Resolume, as it is quite straightforward.
You remember that FFGL Plugin.sln
corresponds to the solution containing all of the example project. Each project is represented as a .vcxproj
file. The simplest way to start a new project is the following :
- Duplicate one of the existing
.vcxproj
file for exampleAdd.vcxproj
- Rename the new one to
SolidColor.vcxproj
. - Open
SolidColor.vcxproj
- Delete the line that looks like this :
<ProjectGuid>{FC65EF1A-9029-40B9-B703-F1A8F563D458}</ProjectGuid>
- Replace
Add
bySolidColor
in those lines :
<ClCompile Include="..\..\source\plugins\Add\Add.cpp" />
<ClInclude Include="..\..\source\plugins\Add\Add.h" />
- Create two files named
SolidColor.cpp
andSolidColor.h
insource/plugins/SolidColor
that will hold your plugin's code.
- Open the
FFGL Plugin.sln
file - Right click on
Solution 'FFGL Plugin
in the solution explorer - Click on Add then Existing Project
- Select the
SolidColor.vcxproj
Copy paste this in SolidColor.h
#pragma once
#include <FFGLSDK.h>
class SolidColor: public Source
{
public:
SolidColor();
~SolidColor();
};
Copy paste this in SolidColor.cpp
#include "SolidColor.h"
static PluginInstance p = Source::CreatePlugin< SolidColor >( {
"SC01", // plugin unique ID
"My SolidColor" // Plugin name
} );
static const std::string fshader = R"(
void main()
{
fragColor = vec4(color,1.0);
}
)";
SolidColor::SolidColor()
{
SetFragmentShader( fshader );
AddHueColorParam( "color" );
}
SolidColor::~SolidColor()
{
}
You can see in the code above that we create a class representing our plugin. This one extends from the Source
class as we are creating a source, but we can also extends from Mixer
or Effect
to create the appropriate kind of plugin. Those classes extends from the Plugin
class that is where most of the magic happens.
Each plugin need to at least provide a fragment shader, here it will just set the pixel color to the value of the variable color
. As you can see in the constructor of the SolidColor class, we set the fragment shader and declare a new parameter also named color
.
The Plugin class keeps track of all the parameters, it will add to the fragment shader the uniform variable declaration and send its value to the shader before each render call. It also takes care of telling Resolume that we have a Hue Color Param, Resolume will then know it needs to display a colorpicker.