Using the Main CathodeRetro Class

Once you have your project set up and you have implemented the required interfaces, you're ready to start using the main CathodeRetro::CathodeRetro class.

Creating a CathodeRetro Instance

You will need to #include "CathodeRetro/CathodeRetro.h" to begin.

Next, you will need to create an instance of the CathodeRetro::IGraphicsDevice-derived class that you implemented in the previous step.

Now you can pass a pointer to that instance to the constructor of the CathodeRetro class, as well as information about the type of signal you are (initially) trying to emulate:

  • The type of signal (for instance: "Composite") to emulate
  • The dimensions of the input texture
  • a set of source settings that describe the properties of the hypothetical "machine" that is generating the composite or S-Video signal.

(The above values can be changed at a later time via a call to the UpdateSourceSettings method)

There are additional settings that control the quality of the signal, the decoding process, and the way the virtual CRT TV appears, which can be set via the UpdateSettings method.

Setting the Output Size

You will now need to let the CathodeRetro instance know the dimensions of the texture that we will be rendering to. You can do this by calling its SetOutputSize method.

Note that you will need to call this function at least once before Render is called, and should additionally be called every time the output size changes (for instance, if the window you are rendering into gets resized).

Rendering

Now that everything is set up, you can call the Render method on your CathodeRetro instance.

  • Takes an RGB or RGBA CathodeRetro::ITexture pointer as the input - the dimensions of this texture should match the width/height that were specified in the constructor or UpdateSourceSettings.
  • The scanlineType parameter specifies whether we are rendering an "even" or "odd" frame (for interlaced frames), or whether it's a "progressive" (non-interlaced) frame.
  • The output texture's dimensions must match the dimensions specified via SetOutputSize.

Example Code

              #include "CathodeRetro/CathodeRetro.h"
              #include "CathodeRetro/SettingPresets.h"

              void Run()
              {
                using namespace CathodeRetro;

                // A pointer to your IGraphicsDevice-derived class.
                MyGraphicsDeviceImpl *myDevice = ...;

                // Also some texture that is going to be rendered through
                //  the system.
                ITexture *myInputTexture = ... ;

                // Construct a new CathodeRetro instance
                CathodeRetro cr { 
                  myDevice, 
                  SignalType::Composite,    // Emulate a composite signal
                  myInputTexture->Width(),
                  myInputTexture->Height(),
                  k_sourcePresets[0],       // Use the first source setting 
                                            //  preset
                };

                // The dimensions of the output texture
                uint32_t outputWidth = ...;
                uint32_t outputHeight = ...;

                // Call this before we start rendering.
                cr.SetOutputSize(outputWidth, outputHeight);

                ScanlineType scanType = 
                  ScanlineType::Odd;
                for (each frame) // pseudocode!
                {
                  // Get the output texture that we need.
                  IRenderTarget *myOutputTexture = ...;

                  cr.Render(
                    myInputTexture,
                    scanType,
                    myOutputTexture);

                  // Alternate even/odd for interlacing, if desired.
                  scanType = 
                    (scanType == ScanlineType::Odd)
                      ? ScanlineType::Even
                      : ScanlineType::Odd;
                }
              }