• Advertisement

Archived

This topic is now archived and is closed to further replies.

See-thru problem (again) and wireframe not working

This topic is 5007 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everybody. About a year ago I posted about having a problem with my mesh's texture being see through (not invisible, but you can see other primitives through eachother). Well, I rewrote that program and fixed it somehow, and now its back (but in a different program). I'm playing around with vertices, and I have it render 16 of them (4 triangle strips). I guess I should also tell you that my CCW culling isn't working either. And, my wireframe doesn't work either. This is my creation code:
// Create graphics here

m_pInterface	= NULL;
m_pDevice	= NULL;
m_pSprite	= NULL;

D3DPRESENT_PARAMETERS PresentParams;
ZeroMemory(&PresentParams, sizeof(D3DPRESENT_PARAMETERS));
PresentParams.BackBufferCount	= 1;
PresentParams.BackBufferFormat	= D3DFMT_A8R8G8B8;
PresentParams.BackBufferWidth	= (int)GetState(EG_WIDTH);
PresentParams.BackBufferHeight	= (int)GetState(EG_HEIGHT);
PresentParams.hDeviceWindow	= GetWindow();
PresentParams.SwapEffect	= D3DSWAPEFFECT_DISCARD;
PresentParams.Windowed	= (bool)GetState(EG_WINDOWED) ? TRUE : FALSE;
PresentParams.EnableAutoDepthStencil	= TRUE;
PresentParams.AutoDepthStencilFormat	= D3DFMT_D16;
m_pInterface = Direct3DCreate9(D3D_SDK_VERSION);
if(m_pInterface == NULL)
{
	LogError("Error creating Direct3D interface pointer.\n");
	return false;
}

HRESULT hResult = GetInterface()->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, GetWindow(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PresentParams, &m_pDevice);
if(FAILED(hResult))
{
	LogError("Error creating Direct3D device pointer.\n\tHRESULT:%s\n", DXGetErrorDescription9(hResult));
	return false;
}

GetDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
GetDevice()->SetRenderState(D3DRS_LIGHTING, FALSE);
GetDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
GetDevice()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
GetDevice()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
GetDevice()->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE ); 
GetDevice()->SetRenderState(D3DRS_ALPHAREF, 0x02 ); 
GetDevice()->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
GetDevice()->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
GetDevice()->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
GetDevice()->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
GetDevice()->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);

hResult = D3DXCreateSprite(GetDevice(), &m_pSprite);
if(FAILED(hResult))
{
	LogError("Error creating Direct3DX sprite pointer.\n\tHRESULT:%s\n", DXGetErrorDescription9(hResult));
	return false;
}

D3DXMATRIX matProjection;
float FOV = D3DX_PI/4;
float Aspect = (float)GetState(EG_WIDTH).m_iValue / (float)GetState(EG_HEIGHT).m_iValue;
D3DXMatrixPerspectiveFovLH(&matProjection, FOV, Aspect, 1.0f, 1000.0f);

hResult = GetDevice()->SetTransform(D3DTS_PROJECTION, &matProjection);
if(FAILED(hResult))
{
	LogError("Error setting Direct3D projection matrix.\n\tHRESULT:%s\n", DXGetErrorDescription9(hResult));
	return false;
}

hResult = GetDevice()->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, EgTransparent, 1.0f, 0);
if(FAILED(hResult))
{
	LogError("Error clearing Direct3D buffer.\n\tHRESULT:%s\n", DXGetErrorDescription9(hResult));
	return false;
}
And my rendering code:
   
/*
class EgVertex
{
public:
float m_fX, m_fY, m_fZ;
D3DCOLOR m_clrDiffuse;
float m_fU, m_fV;

void SetPosition(float x, float y, float z);
void SetColor(D3DCOLOR clrColor);
void SetTextureCoords(float u, float v);
operator D3DXVECTOR3() const;
operator D3DXVECTOR2() const;
operator D3DCOLOR() const;
};
As a side question, can I do this with my class:
D3DXVECTOR3 Position = (D3DXVECTOR3)MyVertex;
D3DXVECTOR2 TextureCoords = (D3DXVECTOR2)MyVertex;
D3DCOLOR Color = (D3DCOLOR)MyVertex;
*/
// const DWORD EgVertexFvf = (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1)

// EgWhite = 0xffffffff

EgVertex vVertices[16] =
{		
	{-1, 0, 1, EgWhite, 0, 0},{0, 1, 1, EgWhite, 1, 0},
	{-1, 0, 0, EgWhite, 0, 1},{0, 0, 0, EgWhite, 1, 1},
	
	{0, 1, 1, EgWhite, 0, 0},{1, 0,	1, EgWhite, 1, 0},
	{0, 0, 0, EgWhite, 0, 1},{1, 0,	0, EgWhite, 1, 1},
	
	{-1, 0, 0, EgWhite, 0, 0},{0, 0, 0, EgWhite, 1, 0},
	{-1, 1, -1, EgWhite, 0, 1},{0, 0, -1, EgWhite, 1, 1},
	
	{0, 0, 0, EgWhite, 0, 0},{1, 0,	0, EgWhite, 1, 0},
	{0, 0, -1, EgWhite, 0, 1},{1, 0, -1, EgWhite, 1, 1},
};

IDirect3DVertexBuffer9* pBuffer = NULL;
int iLength = 16 * sizeof(EgVertex);
D3DXMATRIX matWorld;
D3DXMATRIX matTrans;
D3DXMATRIX matRotX, matRotY, matRotZ;
D3DXMatrixIdentity(&matWorld);
D3DXMatrixIdentity(&matTrans);
D3DXMatrixIdentity(&matRotX);
D3DXMatrixIdentity(&matRotY);
D3DXMatrixIdentity(&matRotZ);
D3DXMatrixTranslation(&matTrans, 0, -2, 10);
D3DXMatrixRotationX(&matRotX, D3DXToRadian(fRotX));
D3DXMatrixRotationY(&matRotY, D3DXToRadian(fRotY));
D3DXMatrixRotationZ(&matRotZ, D3DXToRadian(fRotZ));
D3DXMatrixMultiply(&matWorld, &matRotX, &matRotY);
D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ);
D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans);
g_Engine.GetDevice()->SetTransform(D3DTS_WORLD, &matWorld);

g_Engine.GetDevice()->CreateVertexBuffer(iLength, D3DUSAGE_WRITEONLY, EgVertexFvf, D3DPOOL_DEFAULT, &pBuffer, NULL);

void* pVertices = NULL;
pBuffer->Lock(0, 0, (void**)&pVertices, 0);
memcpy(pVertices, (void*)&vVertices, iLength);
pBuffer->Unlock();

g_Engine.GetDevice()->SetTexture(0, tTexture.GetTexture());

g_Engine.GetDevice()->SetStreamSource(0, pBuffer, 0, sizeof(EgVertex));
g_Engine.GetDevice()->SetFVF(EgVertexFvf);
g_Engine.GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
g_Engine.GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2);
g_Engine.GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 2);
g_Engine.GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 12, 2);

g_Engine.GetDevice()->SetTexture(0, NULL);
pBuffer->Release();


Edit: Here's my Begin() and End() functions:
   
//##################################################################################

// Begin()

// Info: Clears and begins the buffer. 

//##################################################################################

HRESULT EgEngine::Begin()
{
	HRESULT hResult = GetDevice()->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, EG_RGB(255, 0, 255), 1.0f, 0);
	if(FAILED(hResult))
	{
		LogError("Error clearing Direct3D buffer.\n\tHRESULT:%s\n", DXGetErrorDescription9(hResult));
		return hResult;
	}
	
	hResult = GetDevice()->BeginScene();
	if(FAILED(hResult))
	{
		LogError("Error beginning Direct3D scene.\n\tHRESULT:%s\n", DXGetErrorDescription9(hResult));
		return hResult;
	}
	
	hResult = GetSprite()->Begin();
	if(FAILED(hResult))
	{
		LogError("Error beginning Direct3DX sprite.\n\tHRESULT:%s\n", DXGetErrorDescription9(hResult));
		return hResult;
	}
	return hResult;
}

//##################################################################################

// End()

// Info: Ends and presents the buffer. 

//##################################################################################

HRESULT EgEngine::End()
{
	HRESULT hResult = GetSprite()->End();
	if(FAILED(hResult))
	{
		LogError("Error ending Direct3DX sprite.\n\tHRESULT:%s\n", DXGetErrorDescription9(hResult));
		return hResult;
	}
	
	hResult = GetDevice()->EndScene();
	if(FAILED(hResult))
	{
		LogError("Error ending Direct3D scene.\n\tHRESULT:%s\n", DXGetErrorDescription9(hResult));
		return hResult;
	}
	
	hResult = GetDevice()->Present(NULL, NULL, NULL, NULL);
	if(FAILED(hResult))
	{
		LogError("Error presenting Direct3D buffer.\n\tHRESULT:%s\n", DXGetErrorDescription9(hResult));
		return hResult;
	}
	return hResult;
}
If you need any more of the code, please say so! Also, would it be faster to make 18 tris (for a tri-list) instead of a tri-strip? I have more questions after that, but thats for a different topic :D Thanks Edit2: I decided to post an image: The one on the right is from the front, and the one on the left is rotated a little. [edited by - Programmer16 on June 9, 2004 12:37:21 PM] [edited by - Programmer16 on June 9, 2004 1:02:19 PM]

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement