<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Limegarden.net &#187; DirectX</title>
	<atom:link href="http://limegarden.net/tag/directx/feed/" rel="self" type="application/rss+xml" />
	<link>http://limegarden.net</link>
	<description>Personal site of Wouter Lindenhof</description>
	<lastBuildDate>Wed, 01 Feb 2012 23:07:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Brick4 in week 10</title>
		<link>http://limegarden.net/2010/03/29/brick4-in-week-10/</link>
		<comments>http://limegarden.net/2010/03/29/brick4-in-week-10/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 12:29:08 +0000</pubDate>
		<dc:creator>Wouter Lindenhof</dc:creator>
				<category><![CDATA[Brick4]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[DirectX]]></category>
		<category><![CDATA[graduation project]]></category>
		<category><![CDATA[Procedural]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://limegarden.net/?p=299</guid>
		<description><![CDATA[Well, the major glitches in the building creation system are finished. The graphics also look nice now. Anyway a picture says more than a thousand words in this case.]]></description>
			<content:encoded><![CDATA[<p>Well, the major glitches in the building creation system are finished. The graphics also look nice now. Anyway a picture says more than a thousand words in this case.<br />
<a href="http://limegarden.net/wp-content/uploads/2010/03/Week10.png"><img src="http://limegarden.net/wp-content/uploads/2010/03/Week10-300x233.png" alt="Brick after 10 weeks of development" title="Week10" width="300" height="233" class="aligncenter size-medium wp-image-300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://limegarden.net/2010/03/29/brick4-in-week-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rewriting examples: Direct3D tutorial 1 with D3DVERTEXELEMENT9</title>
		<link>http://limegarden.net/2010/01/04/rewriting-examples-direct3d-tutorial-1-with-d3dvertexelement9/</link>
		<comments>http://limegarden.net/2010/01/04/rewriting-examples-direct3d-tutorial-1-with-d3dvertexelement9/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 12:14:06 +0000</pubDate>
		<dc:creator>Wouter Lindenhof</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[DirectX]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://limegarden.net/2010/01/04/rewriting-examples-direct3d-tutorial-1-with-d3dvertexelement9/</guid>
		<description><![CDATA[A while ago a friend asked me how to do something with Direct3D (better known as DirectX) about streams. I really enjoyed it since it was sometime I have worked with my favorite 3D API and so&#160;I explained the usage of VertexDeceleration by rewriting the very first tutorial of Direct3D of which you can see [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago a friend asked me how to do something with Direct3D (better known as DirectX) about streams. I really enjoyed it since it was sometime I have worked with my favorite 3D API and so&nbsp;I explained the usage of VertexDeceleration by rewriting the very first tutorial of Direct3D of which you can see the result below</p>
<pre class="brush: c++; ">

#include &lt;windows.h&gt;
#include &lt;d3d9.h&gt;
#pragma comment(lib, &quot;d3d9.lib&quot;)
#include &lt;d3dx9.h&gt;
#pragma comment(lib, &quot;d3dx9.lib&quot;)

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	static TCHAR szAppName[] = TEXT (&quot;DirectXStreamExample&quot;);
	HWND         hwnd;
	MSG          msg;
	WNDCLASSEX   wndclassex = {0};
	wndclassex.cbSize        = sizeof(WNDCLASSEX);
	wndclassex.style         = CS_HREDRAW | CS_VREDRAW;
	wndclassex.lpfnWndProc   = WndProc;
	wndclassex.cbClsExtra    = 0;
	wndclassex.cbWndExtra    = 0;
	wndclassex.hInstance     = hInstance;
	wndclassex.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
	wndclassex.hCursor       = LoadCursor (NULL, IDC_ARROW);
	wndclassex.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
	wndclassex.lpszMenuName  = NULL;
	wndclassex.lpszClassName = szAppName;
	wndclassex.hIconSm       = wndclassex.hIcon;

	if (!RegisterClassEx (&amp;amp;wndclassex))
	{
		MessageBox (NULL, TEXT (&quot;RegisterClassEx failed!&quot;), szAppName, MB_ICONERROR);
		return 0;
	}
	hwnd = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW,
		szAppName,
		TEXT (&quot;DirectXStreamExample&quot;),
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		640,
		480,
		NULL,
		NULL,
		hInstance,
		NULL); 

	ShowWindow (hwnd, iCmdShow);
	UpdateWindow (hwnd);

	// Now setup DirectX
	IDirect3D9* d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
	D3DPRESENT_PARAMETERS presentParameters;
	memset(&amp;amp;presentParameters, 0, sizeof(D3DPRESENT_PARAMETERS));
	presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
	presentParameters.BackBufferFormat = D3DFMT_UNKNOWN;
	presentParameters.Windowed = true;
	IDirect3DDevice9* device = 0;
	d3d9-&gt;CreateDevice(0, D3DDEVTYPE_HAL, hwnd, D3DCREATE_MIXED_VERTEXPROCESSING, &amp;amp;presentParameters, &amp;amp;device);

	// Create our custom vertex format
	struct POSCOLORVERTEX
	{
		float X, Y, Z, W;
		DWORD color;
	};
	POSCOLORVERTEX vertices[] = {
		{150.0f,  50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255,0,0)},
		{250.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0,255,0)},
		{ 50.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0,0,255)},
	};

	// Create a vertex decleration
	// Think of a vertex decleration as an object that describes a single custom
	// vertex.

	// 	typedef struct _D3DVERTEXELEMENT9
	// 	{
	// 		WORD    Stream;     // Stream index
	// 		WORD    Offset;     // Offset in the stream in bytes
	// 		BYTE    Type;       // Data type
	// 		BYTE    Method;     // Processing method
	// 		BYTE    Usage;      // Semantics
	// 		BYTE    UsageIndex; // Semantic index
	// 	} D3DVERTEXELEMENT9, *LPD3DVERTEXELEMENT9;

	// Example 1: Tutorial 1 of the DirectX SDK
	// using weighted position (aka screen coordinates) and colors but without
	// using the Fixed Pipeline
	D3DVERTEXELEMENT9 PosColorVertexElements[] = {
		{0, 0,  D3DDECLTYPE_FLOAT4,		D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT,	0},
		{0, 16, D3DDECLTYPE_D3DCOLOR,	D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,		0},
		D3DDECL_END()
	};

#if 0
	// Example 2: If you want to add UV it would become something like this:
	D3DVERTEXELEMENT9 PosColorUVVertexElements[] = {
		{0, 0,  D3DDECLTYPE_FLOAT4,		D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT,	0},
		{0, 16, D3DDECLTYPE_D3DCOLOR,	D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,		0},
		{0, 20, D3DDECLTYPE_FLOAT2,		D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,	0},
		D3DDECL_END()
	};
	// Example 3: And if you want UVs first
	D3DVERTEXELEMENT9 PosColorNormalVertexElements[] = {
		{0, 0,		D3DDECLTYPE_FLOAT2,		D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,	0},
		{0, 8,		D3DDECLTYPE_FLOAT4,		D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT,	0},
		{0, 8+16,	D3DDECLTYPE_D3DCOLOR,	D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,		0},
		D3DDECL_END()
	};
	// Example 4: And if you want to send two UV&#039;s
	D3DVERTEXELEMENT9 PosColorNormalVertexElements[] = {
		{0, 0,  D3DDECLTYPE_FLOAT4,		D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT,	0},
		{0, 16, D3DDECLTYPE_D3DCOLOR,	D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,		0},
		{0, 20, D3DDECLTYPE_FLOAT2,		D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,	0}, // Maps to TEXCOORD0 in shader
		{1, 28, D3DDECLTYPE_FLOAT2,		D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,	0},	// Maps to TEXCOORD1 in shader
		D3DDECL_END()
	};
#endif

	IDirect3DVertexDeclaration9* vertexDecleration = 0;
	device-&gt;CreateVertexDeclaration(PosColorVertexElements, &amp;amp;vertexDecleration);
	device-&gt;SetVertexDeclaration(vertexDecleration);

	// Create vertex buffer
	IDirect3DVertexBuffer9*  vertexBuffer;
	device-&gt;CreateVertexBuffer(
		3*sizeof(POSCOLORVERTEX),
		0,
		0,								// DON&#039;T pass the FVF code if you are using vertex decleration
		D3DPOOL_DEFAULT,
		&amp;amp;vertexBuffer,
		0);

	// Fill the vertex buffer
	void* pVertices = 0;
	vertexBuffer-&gt;Lock(0, sizeof(vertices), (void**)&amp;amp;pVertices, 0);
	memcpy(pVertices, vertices, sizeof(vertices));
	vertexBuffer-&gt;Unlock();

	bool keepRunning = true;

	while(keepRunning)
	{
		// Render
		device-&gt;Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
		device-&gt;BeginScene();
		// Rendering of scene objects happens here
		// 1. Set the vertex decleration
		// 2. Set the stream source
		device-&gt;SetVertexDeclaration(vertexDecleration);
		device-&gt;SetStreamSource(0, vertexBuffer, 0, sizeof(POSCOLORVERTEX));
		device-&gt;DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
		// End the scene
		device-&gt;EndScene();
		device-&gt;Present(0,0,0,0);

		if (PeekMessage(&amp;amp;msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT) keepRunning = false;
			else
			{
				TranslateMessage (&amp;amp;msg);
				DispatchMessage (&amp;amp;msg);
			}
		}
	}

	vertexBuffer-&gt;Release();
	vertexDecleration-&gt;Release();
	device-&gt;Release();
	d3d9-&gt;Release();

	return msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_DESTROY:
		{
			PostQuitMessage (0);
			return (0);
		}break;
	}
	return DefWindowProc (hwnd, message, wParam, lParam);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://limegarden.net/2010/01/04/rewriting-examples-direct3d-tutorial-1-with-d3dvertexelement9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Donuts! (Procedural Torus in C++)</title>
		<link>http://limegarden.net/2010/01/04/donuts-procedural-torus-in-c/</link>
		<comments>http://limegarden.net/2010/01/04/donuts-procedural-torus-in-c/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 12:13:45 +0000</pubDate>
		<dc:creator>Wouter Lindenhof</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[code snippit]]></category>
		<category><![CDATA[DirectX]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[Procedural]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://limegarden.net/2010/01/04/donuts-procedural-torus-in-c/</guid>
		<description><![CDATA[Recently I got a mail through the contact form of my website about texture mapping on torus (a donut) who said that [cci_cpp]D3DXCreateTorus[/cci_cpp] didn't not provide texture coordinates. The reason why DirectX and OpenGL (and GLUT) don't provide texture coordinates with these function is best seen when you generate a cube. A cube has 8 [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I got a mail through the contact form of my website about texture mapping on torus (a donut) who said that [cci_cpp]D3DXCreateTorus[/cci_cpp] didn't not provide texture coordinates. The reason why DirectX and OpenGL (and GLUT) don't provide texture coordinates with these function is best seen when you generate a cube. A cube has 8 vertices, however when you add texture coordinates it will increase because otherwise they will share the same texture coordinate. With normals it is no problem (in fact you would prefer that) but if you have a dice (from 1 to 6) than each vertex would use a single texture coordinate for three sides. Just draw an unfolded dice on paper where each edge is connected, but does not cross another edge. It is simply not possible. These complexities are the reason why those procedural mesh functions are so simple. Adding these functionalities would increase complexity of the function and requires you to explain it. On top of that the developers have no idea how you are going to use that function. Maybe you don't want to use the legal texture range [0...1] but [0...3].</p>
<p>Anyway I have decided to take it on and here is the result. You can download the source code here: <a href='http://limegarden.net/wp-content/uploads/2010/01/TorusDX.zip'>TorusDX.zip</a>.I have not commented it, but it is pretty straight forward. The texture that I used is from Dilbert.</p>
<p><a href="http://limegarden.net/wp-content/uploads/2010/01/Donut.png"><img src="http://limegarden.net/wp-content/uploads/2010/01/Donut.png" alt="" title="Donut" width="500" height="500" class="aligncenter size-full wp-image-265" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://limegarden.net/2010/01/04/donuts-procedural-torus-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi Threaded Direct3D</title>
		<link>http://limegarden.net/2009/01/29/multi-threaded-direct3d/</link>
		<comments>http://limegarden.net/2009/01/29/multi-threaded-direct3d/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 02:18:24 +0000</pubDate>
		<dc:creator>Wouter Lindenhof</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[DirectX]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[multithreading]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://limegarden.net/2009/01/29/multi-threaded-direct3d/</guid>
		<description><![CDATA[In the previous post I mentioned that I would look in to multi threaded rendering and I have done that. The minimal example attached and available for download is really simple sample, that creates a Direct3D device and cleans it. If you would further apply the trick that is described on the 26 slide of [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous post I mentioned that I would look in to multi threaded rendering and I have done that. The minimal example attached and available for download is really simple sample, that creates a Direct3D device and cleans it. </p>
<p>If you would further apply the trick that is described on the 26 slide of <a href="http://www.slideshare.net/psteinb/optimizing-direct-x-on-multi-core-architectures">Optimizing Direct X On Multi Core Architectures</a> then I'm certain you can create something very flexible.</p>
<p>For example: If you need a vertex buffer, you lock the RenderingThread using [cci_cpp]RenderingThread::Lock[/cci_cpp] which will only be released once the [cci_cpp]CRITICAL_SECTION[/cci_cpp] has been released by another thread. Then you could ask the RenderingThread to create a wrapper of [cci_cpp]IDirect3DVertexBuffer9[/cci_cpp] which has added function that it will buffer everything and only update [cci_cpp]IDirect3DVertexBuffer9[/cci_cpp] inside the RenderingThread. If done correct you can easily multithread without having to worry about the following error message:</p>
<p>[ccWN_text]Direct3D9: (WARN) <img src='http://limegarden.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> evice that was created without D3DCREATE_MULTITHREADED is being used by a thread other than the creation thread.[/ccWN_text]</p>
<p>You can download the source code here: <a href='http://limegarden.net/wp-content/uploads/2009/01/DirectXMultiThreaded.zip'>DirectXMultiThreaded.zip (source only)</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://limegarden.net/2009/01/29/multi-threaded-direct3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using DXUT</title>
		<link>http://limegarden.net/2008/08/19/using-dxut/</link>
		<comments>http://limegarden.net/2008/08/19/using-dxut/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 23:36:41 +0000</pubDate>
		<dc:creator>Wouter Lindenhof</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[DirectX]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://limegarden.net/2008/08/19/using-dxut/</guid>
		<description><![CDATA[DXUT is the DirectX Utility Toolkiit and until recently whenever you called it's name I would immediately note down your name on my list of people to ignore. And in case your wondering, yes, I always lose the list. Anyhow, as a programmer I always want to reinvent the wheel, not because I think I [...]]]></description>
			<content:encoded><![CDATA[<p>DXUT is the DirectX Utility Toolkiit and until recently whenever you called it's name I would immediately note down your name on my list of people to ignore. And in case your wondering, yes, I always lose the list.</p>
<p>Anyhow, as a programmer I always want to reinvent the wheel, not because I think I know better or can do a better job, but more because I want to get familiar with. By know I have rewritten a lot of my own engines because there was always something missing here or there.</p>
<p>Is DXUT better than my own engines? Maybe, but DXUT is not an engine, it's a template, you could even combine DXUT with few of my engines. The only thing it does is creating structure in your application (by events like OnDeviceCreate, OnDeviceDestroy, OnDeviceReset, etc) and further it creates the window for you.</p>
<p>You also got access to a lot of other features, but they are optional. The only thing I dislike is the fact it includes DX10 specific elements in it, which you don't always want. I believe that a earlier version would allow you to use a define to disable it and else you could add it back yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://limegarden.net/2008/08/19/using-dxut/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

