D3D9 Chams Tutorial

Posts 1–15 of 66 · Page 1 of 5
D3D9 Chams Tutorial
This is a D3D9 chams tutorial.

Defines -

Code:
bool Chams;
UINT m_Stride;
LPDIRECT3DTEXTURE9    texGreen;
LPDIRECT3DTEXTURE9    texYellow;

Above Initialize() -

Code:
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{
	if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)) )
		return E_FAIL;
	
	WORD colour16 =	((WORD)((colour32>>28)&0xF)<<12)
			|(WORD)(((colour32>>20)&0xF)<<8)
			|(WORD)(((colour32>>12)&0xF)<<4)
			|(WORD)(((colour32>>4)&0xF)<<0);

	D3DLOCKED_RECT d3dlr;    
	(*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
	WORD *pDst16 = (WORD*)d3dlr.pBits;

	for(int xy=0; xy < 8*8; xy++)
		*pDst16++ = colour16;

	(*ppD3Dtex)->UnlockRect(0);

	return S_OK;
}


Initialize() -

Code:
GenerateTexture(m_pD3Ddev, &texYellow,D3DCOLOR_ARGB(255,255,255,0));
GenerateTexture(m_pD3Ddev, &texGreen,D3DCOLOR_ARGB(255,0,255,0));
DrawIndexedPrimitive -

Code:
	if (Chams) 
	{
		if (m_Stride == 44)
		{
             DWORD dwOldZEnable = D3DZB_TRUE;
             m_pD3Ddev->SetTexture(0, texYellow);
             m_pD3Ddev->GetRenderState(D3DRS_ZENABLE, &dwOldZEnable);
             m_pD3Ddev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
			 m_pD3Ddev->DrawIndexedPrimitive(Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
             m_pD3Ddev->SetRenderState(D3DRS_ZENABLE, dwOldZEnable);
             m_pD3Ddev->SetTexture(0, texGreen);
}
	}
SetStreamSource -

Code:
if( StreamNumber == 0 ){m_Stride = Stride;}
BeginScene -

Code:
		if (GetAsyncKeyState(VK_INSERT)&1)
{
	Chams = !Chams;
}
What you need?

C++ , MS Visual Studio

A SDK , I use august 2007

The stride is the CA main player stride, the hotkey is insert if you successfully make chams and compile!

Post all errors and questions I WILL help ~~~~
D3D_Starterkit_v3.0b.rarattachment deleted · 1,520 downloads before removal
I wish I understood this :/
Quote Originally Posted by Synns View Post
This is a D3D9 chams tutorial.

Defines -

Code:
bool Chams;
UINT m_Stride;
LPDIRECT3DTEXTURE9    texGreen;
LPDIRECT3DTEXTURE9    texYellow;

Above Initialize() -

Code:
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{
	if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)) )
		return E_FAIL;
	
	WORD colour16 =	((WORD)((colour32>>28)&0xF)<<12)
			|(WORD)(((colour32>>20)&0xF)<<8)
			|(WORD)(((colour32>>12)&0xF)<<4)
			|(WORD)(((colour32>>4)&0xF)<<0);

	D3DLOCKED_RECT d3dlr;    
	(*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
	WORD *pDst16 = (WORD*)d3dlr.pBits;

	for(int xy=0; xy < 8*8; xy++)
		*pDst16++ = colour16;

	(*ppD3Dtex)->UnlockRect(0);

	return S_OK;
}


Initialize() -

Code:
GenerateTexture(m_pD3Ddev, &texYellow,D3DCOLOR_ARGB(255,255,255,0));
GenerateTexture(m_pD3Ddev, &texGreen,D3DCOLOR_ARGB(255,0,255,0));
DrawIndexedPrimitive -

Code:
	if (Chams) 
	{
		if (m_Stride == 44)
		{
             DWORD dwOldZEnable = D3DZB_TRUE;
             m_pD3Ddev->SetTexture(0, texYellow);
             m_pD3Ddev->GetRenderState(D3DRS_ZENABLE, &dwOldZEnable);
             m_pD3Ddev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
			 m_pD3Ddev->DrawIndexedPrimitive(Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
             m_pD3Ddev->SetRenderState(D3DRS_ZENABLE, dwOldZEnable);
             m_pD3Ddev->SetTexture(0, texGreen);
}
	}
SetStreamSource -

Code:
if( StreamNumber == 0 ){m_Stride = Stride;}
BeginScene -

Code:
		if (GetAsyncKeyState(VK_INSERT)&1)
{
	Chams = !Chams;
}
What you need?

C++ , MS Visual Studio

A SDK , I use august 2007

The stride is the CA main player stride, the hotkey is insert if you successfully make chams and compile!

Post all errors and questions I WILL help ~~~~
0mg only if i understood this...
anyways.. this sh0uld be "stickied"
Nice dude,its almost the same as d3d8
Got 2 errors :/.

Deleting intermediate files and output files for project 'TatniumD3D - Win32 Debug'.
--------------------Configuration: TatniumD3D - Win32 Debug--------------------
Compiling...
d3d9dev.cpp
c:\documents and settings\mihkel\desktop\d3d9\d3d9dev.cpp(17) : error C2601: 'GenerateTexture' : local function definitions are illegal
c:\documents and settings\mihkel\desktop\d3d9\d3d9dev.cpp(17) : fatal error C1903: unable to recover from previous error(s); stopping compilation
d3d9int.cpp
d3d9tex.cpp
d3d9.cpp
main.cpp
Error executing cl.exe.

TatniumD3D.dll - 2 error(s), 0 warning(s)


and the source is this

HRESULT CD3DManager::Initialize()
{
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{

(the red mark is the source of the errors :/)
Quote Originally Posted by aprill27 View Post
Got 2 errors :/.

Deleting intermediate files and output files for project 'TatniumD3D - Win32 Debug'.
--------------------Configuration: TatniumD3D - Win32 Debug--------------------
Compiling...
d3d9dev.cpp
c:documents and settingsmihkeldesktopd3d9d3d9dev.cpp(17) : error C2601: 'GenerateTexture' : local function definitions are illegal
c:documents and settingsmihkeldesktopd3d9d3d9dev.cpp(17) : fatal error C1903: unable to recover from previous error(s); stopping compilation
d3d9int.cpp
d3d9tex.cpp
d3d9.cpp
main.cpp
Error executing cl.exe.

TatniumD3D.dll - 2 error(s), 0 warning(s)


and the source is this

HRESULT CD3DManager::Initialize()
{
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{

(the red mark is the source of the errors :/)
Try swapping it around like this
Code:
{
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
}
Quote Originally Posted by juppeli View Post
Try swapping it around like this
Code:
{
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
}
naa dont think so created 35 errors
Quote Originally Posted by aprill27 View Post
Got 2 errors :/.

Deleting intermediate files and output files for project 'TatniumD3D - Win32 Debug'.
--------------------Configuration: TatniumD3D - Win32 Debug--------------------
Compiling...
d3d9dev.cpp
c:documents and settingsmihkeldesktopd3d9d3d9dev.cpp(17) : error C2601: 'GenerateTexture' : local function definitions are illegal
c:documents and settingsmihkeldesktopd3d9d3d9dev.cpp(17) : fatal error C1903: unable to recover from previous error(s); stopping compilation
d3d9int.cpp
d3d9tex.cpp
d3d9.cpp
main.cpp
Error executing cl.exe.

TatniumD3D.dll - 2 error(s), 0 warning(s)


and the source is this

HRESULT CD3DManager::Initialize()
{
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{

(the red mark is the source of the errors :/)
You don't put the generate texture function in Initialize() you put it ABOVE it, so it will look like this!

[php]HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{
if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)) )
return E_FAIL;

WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
|(WORD)(((colour32>>20)&0xF)<<8)
|(WORD)(((colour32>>12)&0xF)<<4)
|(WORD)(((colour32>>4)&0xF)<<0);

D3DLOCKED_RECT d3dlr;
(*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
WORD *pDst16 = (WORD*)d3dlr.pBits;

for(int xy=0; xy < 8*8; xy++)
*pDst16++ = colour16;

(*ppD3Dtex)->UnlockRect(0);

return S_OK;
}

HRESULT CD3DManager::Initialize()
{
/*
initialize Resources such as textures
(managed and unmanaged [D3DPOOL]),
vertex buffers, and other D3D rendering resources
...
m_pD3Ddev->CreateTexture(..., ..., &m_pD3Dtexture);
*/


GenerateTexture(m_pD3Ddev, &texRed,D3DCOLOR_ARGB(255,255,0,0));
GenerateTexture(m_pD3Ddev, &texPurple,D3DCOLOR_ARGB(255,160,32,240));
GenerateTexture(m_pD3Ddev, &texGreen,D3DCOLOR_ARGB(255,0,255,0));
GenerateTexture(m_pD3Ddev, &texYellow,D3DCOLOR_ARGB(255,255,255,0));
GenerateTexture(m_pD3Ddev, &texOrange,D3DCOLOR_ARGB(255,255,140,0));
GenerateTexture(m_pD3Ddev, &texPink,D3DCOLOR_ARGB(255,255,192,203));
GenerateTexture(m_pD3Ddev, &texBlue,D3DCOLOR_ARGB(255,0,0,255));
GenerateTexture(m_pD3Ddev, &texViolet,D3DCOLOR_ARGB(208,32,144,0));
GenerateTexture(m_pD3Ddev, &texSea,D3DCOLOR_XRGB( 32, 178, 170 ));
GenerateTexture(m_pD3Ddev, &texBlack,D3DCOLOR_XRGB( 0, 0, 0 ));
GenerateTexture(m_pD3Ddev, &texSlate,D3DCOLOR_XRGB( 47, 79, 79 ));
GenerateTexture(m_pD3Ddev, &texCoral,D3DCOLOR_XRGB( 255, 127, 80 ));
GenerateTexture(m_pD3Ddev, &texDOrange,D3DCOLOR_XRGB( 255, 140, 0 ));
GenerateTexture(m_pD3Ddev, &texGrey,D3DCOLOR_XRGB( 190, 190, 190 ));

return S_OK;
}[/php]
OMFG i got 50 errors
--------------------Configuration: TatniumD3D - Win32 Debug--------------------
Compiling...
d3d9dev.cpp
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(42) : error C2061: syntax error : identifier 'GenerateTexture'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(42) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(43) : error C2061: syntax error : identifier 'm_pD3Ddev'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(43) : error C2059: syntax error : ')'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(129) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(130) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(174) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(175) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(205) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(205) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
d3d9int.cpp
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(42) : error C2061: syntax error : identifier 'GenerateTexture'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(42) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(43) : error C2061: syntax error : identifier 'm_pD3Ddev'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(43) : error C2059: syntax error : ')'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(129) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(130) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(174) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(175) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(205) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(205) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
d3d9tex.cpp
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(42) : error C2061: syntax error : identifier 'GenerateTexture'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(42) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(43) : error C2061: syntax error : identifier 'm_pD3Ddev'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(43) : error C2059: syntax error : ')'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(129) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(130) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(174) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(175) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(205) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(205) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
d3d9.cpp
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(42) : error C2061: syntax error : identifier 'GenerateTexture'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(42) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(43) : error C2061: syntax error : identifier 'm_pD3Ddev'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(43) : error C2059: syntax error : ')'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(129) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(130) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(174) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(175) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(205) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(205) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
main.cpp
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(42) : error C2061: syntax error : identifier 'GenerateTexture'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(42) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(43) : error C2061: syntax error : identifier 'm_pD3Ddev'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(43) : error C2059: syntax error : ')'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(129) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(130) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(174) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(175) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(205) : error C2059: syntax error : 'if'
c:\documents and settings\matt\desktop\d3d_starterkit_v3.0b\d3d9\d3 d9dev.h(205) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
Error executing cl.exe.

TatniumD3D.dll - 50 error(s), 0 warning(s)
You should add how to add the SDK, the D3D9 cpp and headers, and what type of file to make.
Quote Originally Posted by gbitz View Post
You should add how to add the SDK, the D3D9 cpp and headers, and what type of file to make.
can you help me/us by tellign us how to add the SDK, the D3D9 cpp and headers, and what type of file to make. thanks O_O
I opened up the DirectX9 project with VC++ 2008 Express Edition, and I got these errors.

Code:
1>------ Build started: Project: TatniumD3D, Configuration: Debug Win32 ------
1>Compiling...
1>d3d9tex.cpp
1>c:documents and settingsjohndesktopd3d9d3d9.h(8) : fatal error C1083: Cannot open include file: 'd3dx9.h': No such file or directory
1>d3d9int.cpp
1>c:documents and settingsjohndesktopd3d9d3d9.h(8) : fatal error C1083: Cannot open include file: 'd3dx9.h': No such file or directory
1>d3d9dev.cpp
1>c:documents and settingsjohndesktopd3d9d3d9.h(8) : fatal error C1083: Cannot open include file: 'd3dx9.h': No such file or directory
1>main.cpp
1>c:documents and settingsjohndesktopd3d9d3d9.h(8) : fatal error C1083: Cannot open include file: 'd3dx9.h': No such file or directory
1>d3d9.cpp
1>c:documents and settingsjohndesktopd3d9d3d9.h(8) : fatal error C1083: Cannot open include file: 'd3dx9.h': No such file or directory
1>Generating Code...
1>Creating browse information file...
1>Microsoft Browse Information Maintenance Utility Version 9.00.21022
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>BSCMAKE: error BK1506 : cannot open file '.Debugmain.sbr': No such file or directory
1>Build log was saved at "file://c:Documents and SettingsJohnDesktopD3D9DebugBuildLog.htm"
1>TatniumD3D - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Well, I need make a dll project file with this right?
Posts 1–15 of 66 · Page 1 of 5
This thread is closed for replies.

Similar Threads

Tags for this Thread

Need help?