Skip to content

2. Create your first plugin

Mikael Ems edited this page Jan 31, 2020 · 1 revision

Create your first plugin from scratch

We are going to recreate the Solid Color Source from Resolume, as it is quite straightforward.

Create a new Visual Studio project

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 :

  1. Duplicate one of the existing .vcxproj file for example Add.vcxproj
  2. Rename the new one to SolidColor.vcxproj.
  3. Open SolidColor.vcxproj
  4. Delete the line that looks like this : <ProjectGuid>{FC65EF1A-9029-40B9-B703-F1A8F563D458}</ProjectGuid>
  5. Replace Add by SolidColor in those lines :
    <ClCompile Include="..\..\source\plugins\Add\Add.cpp" />
    <ClInclude Include="..\..\source\plugins\Add\Add.h" />
  1. Create two files named SolidColor.cpp and SolidColor.h in source/plugins/SolidColor that will hold your plugin's code.

Add your project to the solution

  1. Open the FFGL Plugin.sln file
  2. Right click on Solution 'FFGL Plugin in the solution explorer
  3. Click on Add then Existing Project
  4. Select the SolidColor.vcxproj

Code !

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()
{
}

Start to understand how the framework works

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.