Jump to content

  • Log In with Google      Sign In   
  • Create Account

jack872

Member Since 09 Dec 2010
Offline Last Active Aug 03 2014 07:47 AM

Posts I've Made

In Topic: Progressive Sin Wave

17 August 2013 - 06:22 AM

Thank you very much, you were right. Also, the casting from float to int amplified the problem.

Now I've changed my constants and used a float dt instead of an integer and works pretty good. :) 


In Topic: Integrating GUI to DirectX game

05 August 2013 - 04:24 AM

Thanks unbird,

I've fixed that part of code, now it doesn't render anything (or at least I can't see it). Between, yes, I've compiled the sample and works quite well....I'm using the same states but doesn't work anyway in the game. Well, to be honest, it works at the beginning on the video intro, but when the game gets into it menu, starts to give me these issues. The problem is I don't know what states the game is changing. I really don't know what to do :(

Didn't do so many changes into the code, just added two lines here

HRESULT myIDirect3DDevice9::Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
{
	if (m_pStateBlock[0] && m_pStateBlock[1]) 
	{
		D3DXMATRIX matView, projection;
		D3DXMatrixIdentity(&matView);
		Rocket::Core::Vector2i size = RocketGUI::getInstance().getSize();
		m_pIDirect3DDevice9->SetTransform(D3DTS_VIEW, &matView);
		D3DXMatrixOrthoOffCenterLH(&projection, .0f, (float)size.x, (float)size.y, .0f, -1.f, 1.f);
		m_pIDirect3DDevice9->SetTransform(D3DTS_PROJECTION, &projection);

		m_pStateBlock[1]->Capture();
		m_pStateBlock[0]->Apply();
		RocketGUI::getInstance().render();
		m_pStateBlock[1]->Apply();
	}

	HRESULT hRes = m_pIDirect3DDevice9->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
	return hRes; 
}

And enabled the alpha-blending (like the sample https://github.com/lloydw/libRocket/blob/master/Samples/basic/directx/src/main.cpp)
 

void myIDirect3DDevice9::saveStates()
{
	Utils::debug(LOGGER_DEBUG, "Saving DX states...");

	HRESULT rs;
	rs = m_pIDirect3DDevice9->CreateStateBlock(D3DSBT_ALL, m_pStateBlock);
	CDAssert (rs != D3D_OK, (rs ==  D3DERR_OUTOFVIDEOMEMORY) ? "CreateStateBlock error: out of video memory" : "CreateStateBlock error");
	rs = m_pIDirect3DDevice9->CreateStateBlock(D3DSBT_ALL, m_pStateBlock+1);
	CDAssert (rs != D3D_OK, (rs ==  D3DERR_OUTOFVIDEOMEMORY) ? "CreateStateBlock error: out of video memory" : "CreateStateBlock error");

	m_pStateBlock[1]->Capture();

	// Z Buffer states
	m_pIDirect3DDevice9->SetRenderState(D3DRS_ZENABLE, FALSE);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);

	// Alpha states
	m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_ALWAYS);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHAREF, 0);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);

	// Blending states
	m_pIDirect3DDevice9->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

	// Stencil buffer states
	m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILENABLE, FALSE);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILREF, 0);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILMASK, 0xffffffff);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
	m_pIDirect3DDevice9->SetRenderState(D3DRS_LIGHTING, FALSE);
	
	// Sampler states
	m_pIDirect3DDevice9->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
	m_pIDirect3DDevice9->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);

	// Texture states
	m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
	m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
	m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

	m_pStateBlock[0]->Capture();
	m_pStateBlock[1]->Apply();

	Utils::debug(LOGGER_DEBUG, "DX states saved.");
}

In Topic: Integrating GUI to DirectX game

04 August 2013 - 08:30 AM

For GUI rendering you probably need set the view transform to identity and the projection to an orthographic.

 

just tried right now, doesn't work. It doesn't get translated anymore but it is still grey.


In Topic: Integrating GUI to DirectX game

04 August 2013 - 07:45 AM

This is the way I set the states:

void myIDirect3DDevice9::saveStates()
{
Utils::debug(LOGGER_DEBUG, "Saving DX states...");
 
HRESULT rs;
rs = m_pIDirect3DDevice9->CreateStateBlock(D3DSBT_ALL, m_pStateBlock);
CDAssert (rs != D3D_OK, (rs ==  D3DERR_OUTOFVIDEOMEMORY) ? "CreateStateBlock error: out of video memory" : "CreateStateBlock error");
rs = m_pIDirect3DDevice9->CreateStateBlock(D3DSBT_ALL, m_pStateBlock+1);
CDAssert (rs != D3D_OK, (rs ==  D3DERR_OUTOFVIDEOMEMORY) ? "CreateStateBlock error: out of video memory" : "CreateStateBlock error");
 
m_pStateBlock[1]->Capture();
 
// Z Buffer states
m_pIDirect3DDevice9->SetRenderState(D3DRS_ZENABLE, FALSE);
m_pIDirect3DDevice9->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
m_pIDirect3DDevice9->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
 
// Alpha states
m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_ALWAYS);
m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHAREF, 0);
m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
 
// Blending states
m_pIDirect3DDevice9->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
m_pIDirect3DDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);
 
// Stencil buffer states
m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILENABLE, FALSE);
m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILREF, 0);
m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILMASK, 0xffffffff);
m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
m_pIDirect3DDevice9->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
m_pIDirect3DDevice9->SetRenderState(D3DRS_LIGHTING, FALSE);
 
// Sampler states
m_pIDirect3DDevice9->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
m_pIDirect3DDevice9->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
 
// Texture states
m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
 
m_pStateBlock[0]->Capture();
m_pStateBlock[1]->Apply();
 
Utils::debug(LOGGER_DEBUG, "DX states saved.");
}
 
This is the rendering:
HRESULT myIDirect3DDevice9::Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
{
if (m_pStateBlock[0] && m_pStateBlock[1]) 
{
m_pStateBlock[1]->Capture();
m_pStateBlock[0]->Apply();
RocketGUI::getInstance().render();
m_pStateBlock[1]->Apply();
}
 
HRESULT hRes = m_pIDirect3DDevice9->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
return hRes; 
} 

and this is how the librocket renderinterface works:

void RenderInterfaceDirectX::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation)
{
D3DXMATRIX world_transform;
D3DXMatrixTranslation(&world_transform, translation.x, translation.y, 0);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &world_transform);
 
RocketD3D9CompiledGeometry* d3d9_geometry = (RocketD3D9CompiledGeometry*) geometry;
 
g_pd3dDevice->SetFVF(vertex_fvf);
g_pd3dDevice->SetStreamSource(0, d3d9_geometry->vertices, 0, sizeof(RocketD3D9Vertex));
g_pd3dDevice->SetIndices(d3d9_geometry->indices);
 
if (d3d9_geometry->texture != NULL)
g_pd3dDevice->SetTexture(0, d3d9_geometry->texture);
else
g_pd3dDevice->SetTexture(0, NULL);
 
g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 
d3d9_geometry->num_vertices, 0, d3d9_geometry->num_primitives);
}
But this is what I get
lwwo.png

As you can see it renders a big grey rectangle which gets rototranslated when the game camera moves

In Topic: Map collisions

12 February 2011 - 02:46 AM

For 2D collision detection, you can use normal physics engines like ODE (Open Dynamics), Newton, Bullet, Havok, PhysX.
I don't get it. What does color have to do with collision?
All you need is the position of objects.

If you want to read the framebuffer, then it would be glReadPixels.


Mine is a racing game, and for the collisions I want to use a background image wich tells me where the vehicle can go.
like this:

http://t3.gstatic.com/images?q=tbn:ANd9GcRH2tXwuuLLYs8u6O2Wz2h4WEzLlT87N5ojRJoCTQT8mJEkI9ngsA&t=1

but I need something that retrives the color on a x,y position so I can easly compare with the one of the vehicle....

PARTNERS