• Advertisement

Archived

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

D3DLIGHT_POINT

This topic is 5640 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 Guys, I am trying, to get a little point light on my screen. The Problem is that no light appears on my screen. This is, what i do :
  
bool DX_Init(HWND hwnd)
{
	D3DDISPLAYMODE d3ddm;

	if ((pID3D8 = Direct3DCreate8(D3D_SDK_VERSION)) == NULL)
	{
		return false;
	}

	if (FAILED(pID3D8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
	{
		return false;
	}

	D3DPRESENT_PARAMETERS D3DPP;
	ZeroMemory(&D3DPP, sizeof(D3DPP));
	D3DPP.SwapEffect				= D3DSWAPEFFECT_FLIP;
	D3DPP.Windowed					= false;
	D3DPP.BackBufferCount			= 1;
	D3DPP.MultiSampleType			= D3DMULTISAMPLE_NONE;
	D3DPP.EnableAutoDepthStencil	= true;
	D3DPP.AutoDepthStencilFormat	= D3DFMT_D16;
	D3DPP.hDeviceWindow				= hwnd;
	D3DPP.BackBufferWidth			= SCREEN_WIDTH;
	D3DPP.BackBufferHeight			= SCREEN_HEIGHT;
	D3DPP.BackBufferFormat			= d3ddm.Format;
	D3DPP.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	D3DPP.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE;

	D3DPP.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

	if (FAILED(pID3D8->CreateDevice(D3DADAPTER_DEFAULT,
						D3DDEVTYPE_HAL,
						hwnd,
						D3DCREATE_HARDWARE_VERTEXPROCESSING,
						&D3DPP,
						&pID3DDevice)))
	{
		return false;
	}
	
	pID3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pID3DBackBufferSurface8);
    pID3DDevice->SetRenderState(D3DRS_LIGHTING, true);
	pID3DDevice->SetRenderState(D3DRS_AMBIENT,  D3DCOLOR_XRGB(250, 250, 50));
    pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); 
	pID3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);  

	return true;
}

void DX_SetCamera()
{
	D3DXMATRIX matView;
	D3DXMatrixLookAtLH(&matView,&D3DXVECTOR3(0.0f, 0.0f,-30.0f),&D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
	pID3DDevice->SetTransform(D3DTS_VIEW, &matView);
}

void DX_SetProjection()
{
	D3DXMATRIX matProj;
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.0f, 1.0f, 500.0f);
	pID3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);
}

bool DX_Load_Lights()
{
	ZeroMemory(&D3D_Spot, sizeof(D3DLIGHT8));

	D3DVECTOR temp;
	temp.x = 0.0f;
	temp.y = 0.0f;
	temp.z = 1.0f;

	D3D_Spot.Type =	D3DLIGHT_POINT; 
	D3D_Spot.Position = temp;
	D3D_Spot.Diffuse.r = 0.5f;
	D3D_Spot.Diffuse.g = 0.5f;
	D3D_Spot.Diffuse.b = 0.5f;
	D3D_Spot.Range		= 15.0f;

	D3D_Spot.Attenuation0 = 0.0f;
	D3D_Spot.Attenuation1 = 1.0f;
	D3D_Spot.Attenuation2 = 0.0f;

	pID3DDevice->SetLight(0, &D3D_Spot);
	pID3DDevice->LightEnable(0, true);

	return true;
}

void DX_Render()
{
	if (pID3DDevice == NULL)
	{
		return;
	}
	pID3DDevice->BeginScene();
	pID3DDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f, 0);

	DX_SetCamera(); 
	DX_SetProjection();

	//SET Custom Polygon Format

	//pID3DDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);


	//Render Polygons !

	//pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP , 1, &g_Vertex[0], sizeof(VERTEX));

	
	pID3DDevice->EndScene();
	pID3DDevice->Present(NULL, NULL, NULL, NULL);
}
  
I am really grateful for answers !

Share this post


Link to post
Share on other sites
Advertisement
Its not difficult.

It looks right...

No light should appear from that code. There are no polygons to light up.

Share this post


Link to post
Share on other sites
But its a Point Light. Shouldnt a pointlight just appear as a little illuminating light source ?

[edited by - Metzler on August 14, 2002 2:42:54 PM]

Share this post


Link to post
Share on other sites
No. Lights in DirectX are merely positions in space that determine how polygons should be shaded/illuminated. They are no ''physical'' objects, hence you cannot see them rendered. If you need to display lights, you can use a number of methods, such as a 3-D mesh or a 2-D billboarded sprite. You can even render a simple list of line primitives or points to represent the light in your scene.



Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX

Share this post


Link to post
Share on other sites

  • Advertisement