Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagecpp
titleProcedural Checker Example
firstline1
linenumberstrue
#include <math.h>
#include "mx_extensionmanager.h"
#include "mx_textureextension.h"
#include "maxwell.h"
#include "maxwellversions.h"

class CproceduralChecker : public CtextureExtension
{
	DECLARE_EXTENSION_METHODS( "Checker", CproceduralChecker, 1 )
	unsigned int uRepeat, vRepeat;
	Cmaxwell* pMaxwellLocal;

public:
	CproceduralChecker()
	{
		getExtensionData()->createUInt( "repeatU", 10, 1, 10000 );
		getExtensionData()->createUInt( "repeatV", 10, 1, 10000 );
	}
	~CproceduralChecker()
	{
	}
	bool initializeForRendering( Cmaxwell* pMaxwell, CtextureMap* map )
	{
		pMaxwellLocal = pMaxwell;
		getExtensionData()->getUInt( "repeatU", uRepeat );
		getExtensionData()->getUInt( "repeatV", vRepeat );
		return true;
	}
	bool getRGB( Crgb& rgb, real u, real v, const IntersectionInfo* intersectionInfo )
	{
		int pu = ( ( int )( uRepeat * fabs( u ) ) ) % 2;
		int pv = ( ( int )( vRepeat * fabs( v ) ) ) % 2;
		rgb.r *= pu ^ pv;
		rgb.g *= pu ^ pv;
		rgb.b *= pu ^ pv;
		return true;
	}
};

//Startup code
extern "C" ALWAYSEXPORT int getSdkVersion()
{
    return MAXWELL_SDK_VERSION;
}

extern "C" ALWAYSEXPORT int StartExtension( CextensionManager& extensionManager )
{
    int i = 0;
    if( extensionManager.registerTextureExtension( new CproceduralChecker ) ) i++;
    return i;
}