Jump to content
  • Advertisement

Archived

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

Cipher3D

D3DPT_POINTLIST And D3DPT_LINELIST don't work!

This topic is 5450 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''m trying to create a textured-quad engine that is based off of the recent "Textured Quads" article - i use a single vertex buffer and lock/unlock them with every sprite i create and set the texture. I also added these functions:
void C2DFramework::DrawPixel(int x,int y,DWORD dwColor)
{
	if (!m_pd3dDevice)	//check if the device is valid or not

		return;

	if (!m_pVertexBuffer)	//check if the vertex buffer is valid or not

		return;

	Vertex* pVertices = NULL;

	//lock the vertex buffer

	m_pVertexBuffer->Lock(0,0,(BYTE**)&pVertices,NULL);
	pVertices[0].m_fX = x;
	pVertices[0].m_fY = y;
	pVertices[0].m_fZ = 0.0f;
	pVertices[0].m_fRhw = 1.0f;
	pVertices[0].m_dwColor = dwColor;
	pVertices[0].m_fTU = pVertices[0].m_fTV = 0.0f;
	m_pVertexBuffer->Unlock();

	m_pd3dDevice->SetStreamSource(0,m_pVertexBuffer,sizeof(Vertex));
	m_pd3dDevice->DrawPrimitive(D3DPT_POINTLIST,0,1);
} //end DrawPixel


and
//drawline - it draws al ine

void C2DFramework::DrawLine(int x0,int y0,int x1,int y1,DWORD dwColor)
{
	if (!m_pd3dDevice)
		return;

	if (!m_pVertexBuffer)
		return;


	Vertex* pVertices = NULL;

	m_pVertexBuffer->Lock(0,0,(BYTE**)&pVertices,NULL);
	pVertices[0].m_fX = x0;
	pVertices[1].m_fX = x1;
	pVertices[0].m_fY = y0;
	pVertices[1].m_fY = y1;
	pVertices[0].m_fZ = pVertices[1].m_fZ = pVertices[0].m_fTU = pVertices[0].m_fTV = pVertices[1].m_fTU = pVertices[1].m_fTV = 0.0f;
	pVertices[0].m_fRhw = pVertices[1].m_fRhw = 1.0f;
	pVertices[0].m_dwColor = pVertices[1].m_dwColor = dwColor;
	m_pVertexBuffer->Unlock();

	m_pd3dDevice->SetStreamSource(0,m_pVertexBuffer,sizeof(Vertex));
	m_pd3dDevice->DrawPrimitive(D3DPT_LINELIST,0,2);
} //end DrawLine

They are functions to plot a pixel and draw a line, respectively. At first they seemed to work (e.g. I could draw them with whatever color I choose). However, when I loaded sprites with color keys white and magenta, and drew them, the lines and points disappeared! Here is the vertex buffer creation function:
/*

  If the user wants 2d rendering, call his
  C2DFramework::Set2DRenderingParamters
*/

void C2DFramework::Set2DRenderingParameters()
{
	//set the vertex shader to transformation and lightning

	m_pd3dDevice->SetVertexShader(D3DFVF_QUADVERTEX);
	
	//create the vertex buffer

	m_pd3dDevice->CreateVertexBuffer(sizeof(Vertex)*4,NULL,D3DFVF_QUADVERTEX,D3DPOOL_MANAGED,&m_pVertexBuffer);
	
	//set the render states

	m_pd3dDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
	m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
	m_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
	m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
	m_pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
} //end


/*
Does anybody have any idea as how to solve this? Any help is appreciated! Thanks, Ciph

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Hey kid, use the DrawPrimiveUP function to render those pixel and lines

Share this post


Link to post
Share on other sites
HOw do i use DrawPrimitiveUP's last parameter? What does "stride" mean?

[edited by - Cipher3D on August 13, 2003 8:10:14 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
do not use the ...UP functions. The other AP is either smoking something or trying to lead you astray.

are you setting the FVF and/or vertex shader somewhere? You need to tell the device the format of your vertices.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It looks like you are using textures, although I''m not sure why...

struct VERTEX
{
float x, y, z, rhw;
DWORD Color;
float u, v;
};

#define D3DFVF_VERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)


m_pD3DDevice->SetFVF(D3DFVF_VERTEX);

Share this post


Link to post
Share on other sites
well i''m using textures for my textured quads...perhaps i should have a seperate FVF for my lines and pixels (they''re not textured, just colored)?

And if thats the case, should I have a seperate vertex buffer or reuse the same vertex buffer except changing the FVF? I''m confusing myself here! LoL.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
it might be advantageous to stick with one fvf. you end up with a bigger than needed vertex, but you avoid switching fvfs, buffers, etc. For the real answer, you''ll have to experiment...

Share this post


Link to post
Share on other sites
ok i have 2 questions:

1) can i use one vertex buffer (I''m using DirectX 8.0 here) and switch between FVF''S?

2) whats the performance hit If i create a vertex buffer and release it everytime I draw a line/pixel? I''m guessing that''s horrendous.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
2) Yes, horrendous. You and I will never speak of this again!

1) You can probably pack multiple formats in your vertex buffer if you are very careful, but based on your current level of understanding (no offense), I''d recommend against it. Get it working with two vertex buffers and optimize later.

Share this post


Link to post
Share on other sites

  • 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!