Coding a Dogwaffle Connection in C++

Post Reply
Simon
C.E.O.
Posts: 2300
Joined: Wed Dec 01, 2004 8:13 am
Location: Kingston Upon Thames, U.K.
Contact:

Coding a Dogwaffle Connection in C++

Post by Simon »

This is not a tutorial for Curvy 3D, but rather a rare look inside Curvy's source code to help application authors link to Dogwaffle.

This example uses VOLE (open source) as a neat OLE wrapper

Code: Select all

/* VOLE Header Files */
#include <vole/vole.hpp>
/* STLSoft Header Files */
#include <comstl/util/initialisers.hpp>
#include <comstl/util/variant.hpp>
#include <winstl/error/error_desc.hpp>

// ... other headers for error reporting here ...

void TestOLE()
{
	try
	{
		TRACE("Test OLE\n");
		comstl::ole_init    coinit;

		// Start server ...
		vole::object dog = vole::object::create("Dogwaffle.Dogwaffle_Class", CLSCTX_LOCAL_SERVER, vole::coercion_level::valueCoercion);

		comstl::variant r = dog.invoke_method<comstl::variant>(L"Dog_GetRBuffer");
		comstl::variant g = dog.invoke_method<comstl::variant>(L"Dog_GetGBuffer");
		comstl::variant b = dog.invoke_method<comstl::variant>(L"Dog_GetBBuffer");
		comstl::variant a = dog.invoke_method<comstl::variant>(L"Dog_GetABuffer");

		SAFEARRAY* sa = r.parray;

		int w = dog.get_property<int>(L"Dog_BufferHeight");
		int h = dog.get_property<int>(L"Dog_BufferWidth");

		int x = (*sa).rgsabound[0].cElements;
		int y = (*sa).rgsabound[1].cElements;

		byte* R = (byte*)((*r.parray).pvData);
		byte* G = (byte*)((*g.parray).pvData);
		byte* B = (byte*)((*b.parray).pvData);
		byte* A = (byte*)((*a.parray).pvData);

		int lx = x-1;
		int ly = y-1;

		ASSERT(w==lx);
		ASSERT(h==ly);

		for(int j=0;j<ly;++j)
			for(int i=0;i<lx;++i)
			{
				int p = i+j*x;
// Example filter - I normally copy Curvy's image buffers to Dogwaffle here...
				R[p] = rand()%32;
				G[p] = rand()%32;
				B[p] = rand()%32;
				A[p] = (i*256)/lx;
			}

			dog.invoke_method<void>(L"Dog_SetRBuffer",r);
			dog.invoke_method<void>(L"Dog_SetGBuffer",g);
			dog.invoke_method<void>(L"Dog_SetBBuffer",b);
			dog.invoke_method<void>(L"Dog_SetABuffer",a);

			dog.invoke_method<void>(L"Dog_Refresh");
	}
	catch(vole::vole_exception &x)
	{
		cout << "error: " << x.what() << ": " << winstl::error_desc(x.hr()).c_str() << endl;
	}
	catch(std::exception &x)
	{
		cout << "error: " << x.what() << endl;
	}

}
[/code]
donfelipe
Posts: 16
Joined: Wed May 18, 2005 2:48 pm
Location: San Diego, California
Contact:

Post by donfelipe »

Thanks, much appreciated.

If there are other developers looking at this code, and interested in using Dogwaffle as a framework for imaging and frame-by-frame animation or more, check the SDK and free source code snippets, most in VB but also some in Delphi, as submitted by Artweaver:

http://www.thebest3d.com/dogwaffle/sdk

For examples of other applications who have created a plug into Dogwaffle, check
http://www.thebest3d.com/dogwaffle/3rdpartyplugins

and
http://www.thebest3d.com/artweaver
Post Reply