Jump to content
  • Advertisement
Sign in to follow this  
Screamer

Drawing lines with color

This topic is 3630 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

I am trying to draw lines which represent the axis in my game for debugging purposes. Thing is i can't get them to be colored the lines are showing up properly though. When i look at the color values in pix they are not showing up as I set them.
//creation code

	gd3dDevice->SetVertexDeclaration(VertexPC::Decl);
	gd3dDevice->CreateVertexBuffer(6 * sizeof(VertexPC), D3DUSAGE_WRITEONLY,
		0, D3DPOOL_MANAGED, &axis_Vb_, 0);


	VertexPC* v = 0;
	axis_Vb_->Lock(0, 0, (void**)&v, 0);

	//x-axis RED
	//D3DCOLOR_ARGB
	v[0].pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	v[0].color = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f);
	v[1].pos = D3DXVECTOR3(1.0f,  0.0f, 0.0f);
	v[1].color = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f);

	//y-axis GREEN 
	v[2].pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	v[2].color = D3DXCOLOR( 0.0f, 1.0f, 0.0f, 1.0f);
	v[3].pos = D3DXVECTOR3( 0.0f, 1.0f, 0.0f);
	v[3].color = D3DXCOLOR( 0.0f, 1.0f, 0.0f, 1.0f);

	//z-axis BLUE
	v[4].pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	v[4].color = D3DXCOLOR( 0.0f, 0.0f, 1.0f, 1.0f);
	v[5].pos = D3DXVECTOR3(0.0f,  0.0f,  1.0f);
	v[5].color = D3DXCOLOR( 0.0f, 0.0f, 1.0f, 1.0f);

	axis_Vb_->Unlock();

//draw code

	gd3dDevice->SetRenderState(D3DRS_COLORVERTEX, D3DSHADE_GOURAUD );

	if(myDebugComponent->showAxis_)
	{		
		
		gd3dDevice->SetVertexDeclaration(VertexPC::Decl);
		gd3dDevice->SetStreamSource( 0, axis_Vb_, 0, sizeof(VertexPC) );
		gd3dDevice->DrawPrimitive(D3DPT_LINELIST, 0, 3);
	}

Share this post


Link to post
Share on other sites
Advertisement
Sorry forgot that part.


struct VertexPC
{
VertexPC()
:pos(0.0f, 0.0f, 0.0f),
color(0.0f, 0.0f, 0.0f, 0.0f){}
VertexPC(float x, float y, float z,
float r, float g, float b, float a ):pos(x,y,z), color(r,g,b,a){}
VertexPC(const D3DXVECTOR3& v, const D3DXCOLOR& c)
:pos(v),color(c){}

D3DXVECTOR3 pos;
D3DXCOLOR color;

static IDirect3DVertexDeclaration9* Decl;
};



D3DVERTEXELEMENT9 VertexPCElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END()
};
GFX->gd3dDevice->CreateVertexDeclaration(VertexPCElements, &VertexPC::Decl);




Share this post


Link to post
Share on other sites
You do not state what exactly is wrong with the colors. But you can check those:

1)
Your color values for the red axis are resulting in white.

2)
Did you disable lighting? Lines are affected by lighting as well.

3)
Did you turn off textures? Lines can be textured too.

Share this post


Link to post
Share on other sites
You do not state what exactly is wrong with the colors. But you can check those:

1)
Your color values for the red axis are resulting in white.
All the time the color shows up as black.

2)
Did you disable lighting? Lines are affected by lighting as well.
I turned on a directional light that should be enough to light the lines.

3)
Did you turn off textures? Lines can be textured too.
There are no textures on the lines, they are just lines.

Share this post


Link to post
Share on other sites
Quote:
Original post by Screamer
1)
Your color values for the red axis are resulting in white.
All the time the color shows up as black.

2)
Did you disable lighting? Lines are affected by lighting as well.
I turned on a directional light that should be enough to light the lines.

3)
Did you turn off textures? Lines can be textured too.
There are no textures on the lines, they are just lines.


Regarding 2)
You do not provide normals, if you don't DirectX assumes a null vector, making all your lines black. To test if this is the cause of the problem disable lighting before drawing your lines.

Regarding 3)
So did you set NULL as current texture?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!