Archived

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

D3DPT_POINTLIST And D3DPT_LINELIST don't work!

This topic is 5235 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
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
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
You''re probably not getting points and lines because of:

1) You''ve still got blending enabled, which you may, but probably don''t want.

2) You''ve still got a texture with transparent pixels at 0,0, which is the UV you gave your lines and points. Lines and points will use textures if you tell them to, just like triangles do.

3) You never set any texturestagestates when trying to draw lines and points. The color of lines and points is based on the output of texturestages, just line triangles.

4) Your line is 1 primitive, not 2. It takes 2 points to make a line, just like it takes 3 vertices to make a triangle, but it''s still 1 primitive.

5) As said, you never set the FVF. The FVF is the same as when drawing quads in your case. It just defines your vertex structure, which you''ve made identical to your quads(x,y,z,rhw,diffuse,u,v). Just copy that code from your quad function.

6) That article is really bad. They don''t fully setup texture states, and just assume they''re default. If you render something else that changes states, then render a quad with their technique, the output is not fully defined. Also, locking and drawing each quad? And no warning that it''s just a beginner level tutorial, and that this isn''t what you should really do? Some of these articles need big, bold, flashing, warnings on them.

Share this post


Link to post
Share on other sites
The FVF is covered by an Anonymous Poster above. Your vertices are of type D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1.
In DX8: pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)
In DX9: pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)

For the texturestagestates... hmmm. How much detail do post.

The color drawn to the backbuffer is based on a the flow through the texture stages. They can be programmed to read textures, use diffuse color, use a constant color, and to mix these in a variety of ways, such as multiplication, addition.


// Setup to mix diffuse and texture color and alpha for quads

pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

This says for stage 0:
modulate (multiply - colors are treated as 3 floats from 0 to 1) the texture by the diffuse color. Then it says modulate the texture alpha and diffuse alpha.

Then for stage 1, it says "I''m done".

Odds are for lines and points you don''t want textures, just the diffuse color so you''d do this instead:

// Setup texture stages for diffuse color only, and use diffuse alpha

pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);


The number of stages you use will increase as you start doing multitexturing, and complex blending operations. The output of stage 0 and be used as the input to stage 1. The output from stage 1 can be the input to stage 2, and so on.

On modern cards you can also write to a temporary register. ie: Stage 0, calculate something and save it. Stage 1, calculate something entirely different. Stage 2, Modulate Stage 1 with Temp.

What each operation does is covered fairly well in the docs, and in the d3d9types.h file.

Share this post


Link to post
Share on other sites
quote:
Original post by Cipher3D
My lines and pixels finally work, and now all i gotta do is optimize the hell outta it.


No. What you need to do is learn more about how Direct3D works. There are quite a few good books out there as well as many tutorial web sites.

You''re still very new to Direct3D and many things that may seem like optimizations can end up having no effect or a negative effect. I''ve seen many people at about this level go off to optimize their engine and most often they end up wasting their time because they don''t understand exactly what made things slow in the first place.

This isn''t a shot at you. We were all newbies once and we''re all still learning. I''m just trying to steer you towards a better path to get where you want to go.

Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites