• Advertisement
Sign in to follow this  

D3d problem: Not rendering

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

For some reason this code has decided not to work, or even produce some kind of error...As far as I can tell it is identical to some of my other code which works, so I'm not sure what I did wrong here.
struct Vertex
{
	float x,y,z;
	unsigned col;
	float u,v;
	Vertex(float x, float y, float u, float v, unsigned col)
		:x(x),y(y),z(0.0f), u(u),v(v), col(col)
	{}
};
static const unsigned VertexFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
...
device->CreateVertexBuffer(sizeof(Vertex)*100, D3DUSAGE_DYNAMIC, VertexFVF, D3DPOOL_DEFAULT, &primVB, 0);
...
void Graphics::DrawLine(float x1,float y1, float x2,float y2, unsigned c1, unsigned c2)
{
	Vertex *vertices;
	primVB->Lock(0,0, (void**)&vertices, D3DLOCK_DISCARD);
	vertices[0] = Vertex(x1,y1, 0,0, c1);
	vertices[1] = Vertex(x2,y2, 0,0, c2);
	primVB->Unlock();
	
	device->SetFVF(VertexFVF);
	device->SetStreamSource(0, primVB, 0, sizeof(Vertex));
	device->SetTexture(0,0);
	device->SetTransform(D3DTS_WORLD, &matIdentity);
	device->DrawPrimitive(D3DPT_LINELIST, 0, 1);
}


[Edited by - Fire Lancer on April 21, 2009 4:08:53 PM]

Share this post


Link to post
Share on other sites
Advertisement
So what does it do? Does it render a black line on a black backbuffer? Have you tried a different clear color to see if the primitive is there but just with the wrong color?

Shouldn't D3DFVF_TEX1 be D3DFVF_TEX0?

Why do you specify texture coordinates but set the texture to 0? Skip the D3DFVF_TEX0 from the FVF and try to render again.

Oh and I guess your constructor is actually called Vertex and not VBVertex [grin]

Finally, naming the constructor's parameters the same as the member attributes is no good idea. I am surprised that this should compile at all.

Share this post


Link to post
Share on other sites
Quote:
Shouldn't D3DFVF_TEX1 be D3DFVF_TEX0?

No. The former specifies that there is one set of texture coordinate in the format, whereas the latter specifies that there are none.

Quote:
Finally, naming the constructor's parameters the same as the member attributes is no good idea. I am surprised that this should compile at all.

This is valid and well-defined behavior.

Share this post


Link to post
Share on other sites
Quote:
Original post by Waterwalker
So what does it do? Does it render a black line on a black backbuffer? Have you tried a different clear color to see if the primitive is there but just with the wrong color?

As I said it simply does not render, no errors nothing. The rest of the game works fine, but the lines are not rendering...

Quote:

Why do you specify texture coordinates but set the texture to 0? Skip the D3DFVF_TEX0 from the FVF and try to render again.

Same reason I have 100 elements in that buffer. It's a general purpose vertex buffer for drawing various stuff that doesnt have its own static buffer, and some of those primitives (triangles, quads, circles, etc) do use texture cordinates and take an optional texture argument. Seeing as lines and points are basicly the only primitives that can't be textures I figured it didn't make sense to give them their own vertex buffer.

Quote:

Oh and I guess your constructor is actually called Vertex and not VBVertex

Yes, that was just a mistake from cutting out the VB stuff to do with the primitive drawing, from surfaces, sprites, etc. Didnt see the need to post all the stuff that did work.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike.Popoloski
Quote:
Shouldn't D3DFVF_TEX1 be D3DFVF_TEX0?

No. The former specifies that there is one set of texture coordinate in the format, whereas the latter specifies that there are none.

Thanks for clarifying that, I haven't used FVF in a long time.

Quote:
Original post by Mike.Popoloski
Quote:
Finally, naming the constructor's parameters the same as the member attributes is no good idea. I am surprised that this should compile at all.

This is valid and well-defined behavior.

Ok, I didn't know that. But what if I implement the contructor's body and access e.g. x. Will this use the parameter or the class' attribute?

@OP
Did you try to actually use a texture for the sake of testing with your lines? Have you tried to clear the render target and only render the lines without the remainder of your graphics? Is your projection matrix still valid at this point of rendering? Which coordinates do you have for your lines?

Share this post


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

  • Advertisement