Click here to Skip to main content
15,885,869 members
Articles / Multimedia / DirectX

Interactive 3D Spectrum Analyzer Visualization for Windows Media Player

Rate me:
Please Sign up or sign in to vote.
5.00/5 (12 votes)
17 May 2009CPOL12 min read 164.4K   6.5K   41  
Interactive 3D Spectrum Analyzer for Windows Media Player using DirectX 9 and some light GPGPU.
///////////////////////////////////////////////////////////////////////////////
//  Copyright (c) 2009 Carlo McWhirter. All Rights Reserved.	
//  Copyright (c) 2009 Hyteq Systems. All Rights Reserved.	
//  
//  http://www.hyteq.com
//
//	Hyteq Systems Educational License
//
//  This file is part of WM3DSpectrum, also known as 3D Spectrum Analyzer for
//  Windows Media Player. This file, the project that this file is part of, and
//  the resulting compiled program files are intended to be used for educational
//  purposes only. Use of this file or this project for any non-educational or
//  non-observatory purpose is strictly prohibited without the express written 
//  consent of all of the copyright holders listed above.
//
//  This file may only be modified and later redistributed by one or more of the
//  copyright holders listed above. Suggestions for bug fixes, enhancements,
//  and other modifications must be sent directly to one of the copyright holders.
//  
//  This file may be modified without being redistributed by any recipient of 
//  this file provided the modifications are NOT intentionaly or unintentionaly 
//  directed toward malicious or illegal purposes, but, instead, toward educational
//  purposes only.
//
//	THIS SOFTWARE IS PROVIDED 'AS-IS', WITHOUT ANY EXPRESS OR IMPLIED
//  WARRANTY. IN NO EVENT WILL THE AUTHORS BE HELD LIABLE FOR ANY DAMAGES
//  ARISING FROM THE USE OF THIS SOFTWARE.
//
//  This notice may not be removed from this file or altered in any manner.
//
///////////////////////////////////////////////////////////////////////////////

#pragma once
#include "rendererinterface.h"

extern const char* gEffect;

// Vertex Structure definitions
struct VertexPos
{
	VertexPos():pos(0.0f, 0.0f, 0.0f){}
	VertexPos(float x, float y, float z):pos(x,y,z){}
	VertexPos(const D3DXVECTOR3& v):pos(v){}

	D3DXVECTOR3 pos;
};

struct VertexCol
{
	VertexCol():pos(0.0f, 0.0f, 0.0f),col(0x00000000){}
	VertexCol(float x, float y, float z, D3DCOLOR c):pos(x,y,z), col(c){}
	VertexCol(const D3DXVECTOR3& v, D3DCOLOR c):pos(v),col(c){}

	D3DXVECTOR3 pos;
	D3DCOLOR    col;
};

// CGridRenderer implements the IRenderable interface and supports the windowed rendering mode.
// CGridRenderer is used to render the 3D effects and 2D billboards.
class CGridRenderer :
	public IRenderable
{
public:
	CGridRenderer(void);
	~CGridRenderer(void);

	virtual void Intitialize(LPRENDERCONTEXT context);
	virtual void Destroy(LPRENDERCONTEXT context);
	virtual void Prerender(LPRENDERCONTEXT context);
	virtual void Render(LPRENDERCONTEXT context);
	virtual void LostDevice(LPRENDERCONTEXT context);
	virtual void ResetDevice(LPRENDERCONTEXT context);
	virtual bool CanRenderWindowed();
	virtual bool CanRenderNonWindowed();

protected:
	void MakePointGrid(int iRows, int iCols, float dx, float dz,
		const D3DXVECTOR3& center, std::vector<D3DXVECTOR3>& verts,
		std::vector<DWORD>& indices);
	void PrerenderAToB(LPRENDERCONTEXT context);
	void PrerenderBToA(LPRENDERCONTEXT context);
	void CreateDefaultPoolObjects(LPRENDERCONTEXT context);

protected:
	IDirect3DTexture9*		m_pDataTexA;
	IDirect3DTexture9*		m_pDataTexB;
	IDirect3DTexture9*		m_pSwapTex;
	IDirect3DSurface9*		m_pDataTexASurface;
	IDirect3DSurface9*		m_pDataTexBSurface;
	IDirect3DSurface9*		m_pSwapSurface;
	ID3DXRenderToSurface*	m_pRenderToSurface;

	IDirect3DVertexDeclaration9* m_pVertPosDecl;
	IDirect3DVertexDeclaration9* m_pVertDecl;
	IDirect3DVertexBuffer9* m_pVertBuff;
	IDirect3DIndexBuffer9*	m_pIndexBuff;
	ID3DXEffect*            m_pEffect;
	ID3DXSprite*			m_pSprite;
	ID3DXFont*				m_pFont;
	D3DXHANDLE              m_hRoseGardenTech;
	D3DXHANDLE              m_hCityLightsTech;
	D3DXHANDLE				m_hTex;
	D3DXHANDLE              m_hWVP;

	int						m_iVertCount;
	DWORD					m_dwTriangleCount;
	short					m_sCurrentPreset;

	bool					m_bRenderingAToB;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
I'm a Microsoft Certified Professional (MCP) in C++. I'm fluent in C/C++, C# and many other languages.

Comments and Discussions