Skip to main content
GameDev.net gamedev.net
🔒 Locked

line color?

Started by majek Feb 27, 2009 at 11:59 AM 1 replies 550+ views
Original Post
majek
majek
Hello again, sorry for all the newb questions. I'm trying to draw 3 lines (red green and blue) at the origin so I can visualize the x y and z axis. The lines are rendered correctly but they are black. Am I doing something wrong? Is there a better way to draw colored lines?
#define D3DFVF_LINEVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
	
struct LINEVERTEX
{
	FLOAT px, py, pz;
	D3DCOLOR diffuse;
};
	
LPDIRECT3DVERTEXBUFFER9 LineVB = NULL;
vector<LINEVERTEX> Lines;
	
HRESULT InitAxis()
{
	LINEVERTEX lv;
	
	// Red line
	lv.px = 0.0f;
	lv.py = 0.0f;
	lv.pz = 0.0f;
	lv.diffuse = D3DCOLOR_XRGB(255, 0, 0);
	Lines.push_back(lv);
	lv.px = 10.0f;
	lv.py = 0.0f;
	lv.pz = 0.0f;
	lv.diffuse = D3DCOLOR_XRGB(255, 0, 0);
	Lines.push_back(lv);
	
	// Green line
	lv.px = 0.0f;
	lv.py = 0.0f;
	lv.pz = 0.0f;
	lv.diffuse = D3DCOLOR_XRGB(0, 255, 0);
	Lines.push_back(lv);
	lv.px = 0.0f;
	lv.py = 10.0f;
	lv.pz = 0.0f;
	lv.diffuse = D3DCOLOR_XRGB(0, 255, 0);
	Lines.push_back(lv);
	
	// Blue line
	lv.px = 0.0f;
	lv.py = 0.0f;
	lv.pz = 0.0f;
	lv.diffuse = D3DCOLOR_XRGB(0, 0, 255);
	Lines.push_back(lv);
	lv.px = 0.0f;
	lv.py = 0.0f;
	lv.pz = 10.0f;
	lv.diffuse = D3DCOLOR_XRGB(0, 0, 255);
	Lines.push_back(lv);
	
	// Create the vertex buffer
	if (FAILED(D3DDevice->CreateVertexBuffer((UINT)Lines.size() * sizeof(LINEVERTEX), 0, D3DFVF_LINEVERTEX, D3DPOOL_DEFAULT, &LineVB, NULL)))
	{
		MessageBox(NULL, "Error creating vertex buffer", "Error", MB_OK);
		return E_FAIL;
	}
	
	// Fill the vertex buffer
	VOID* pVertices;
	if (FAILED(LineVB->Lock(0, 0, (void**)&pVertices, 0)))
	{
		MessageBox(NULL, "Error filling vertex buffer", "Error", MB_OK);
		return E_FAIL;
	}
	memcpy(pVertices, &(Lines[0]), Lines.size() * sizeof(LINEVERTEX));
	LineVB->Unlock();
	
	return S_OK;
}
	
VOID Render()
{
	// ...
	D3DDevice->SetStreamSource(0, LineVB, 0, sizeof(LINEVERTEX));
	D3DDevice->SetFVF(D3DFVF_LINEVERTEX);
	D3DDevice->DrawPrimitive(D3DPT_LINELIST, 0, (UINT)Lines.size() / 2);
	// ...
}

Aardvajk
Aardvajk
Probably still got lighting on.

Device->SetRenderState(D3DRS_LIGHTING,false);


D3D lighting is on by default but if there are no light sources defined, all things recieve no light, even lines, and therefore appear black.
majek
majek
Thanks EasilyConfused, you solved my problem again =) I thought I tried disabling lighting but apperently not.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.