• 15
• 15
• 11
• 9
• 10

# Just a line when rendering a Triangle[solved]

This topic is 4591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi I have a quite strange Porblem: I'm just trying to render a triangle(exported from Maya) and the Vertices+Indices are imported correctly(i checked that with a debugger) except the v Coordinate of the first Vertex but that can't cause may problem(can it?) but instead of the Trangle i just see a 1 or 2 pixel thick line :/: The debugger says that the vertices vector is filled with this(this is actually an array filled with the contents of the vector): and the Indices are 0,1,2. Am i right in the opinion that the Problem can only be in the rendering code? creation of the VertexBuffer:
FVF=D3DFVF_XYZ|D3DFVF_TEX1;

/*if( FAILED( m_pEngine->g_pD3DDevice->CreateVertexBuffer(Verts.size()*sizeof(std::vector<Vertex>::value_type),
0,
FVF,
D3DPOOL_DEFAULT,
&pVBuffer,   //<---inherited from BaseMesh
NULL ) ) )
{
MessageBox(0,"Fetter Error1!","Error",0);
PostQuitMessage(1);
}*/
if( FAILED( m_pEngine->g_pD3DDevice->CreateVertexBuffer(complVertices.size()*sizeof(complVertex),
0,
FVF,
D3DPOOL_DEFAULT,
&pVBuffer,   //<---inherited from BaseMesh
NULL ) ) )
{
MessageBox(0,"Fetter Error1!","Error",0);
PostQuitMessage(1);
}
VOID *pVData;
pVBuffer->Lock(0,0,(void**)&pVData,0);	//lock buffer
std::vector<complVertex>::pointer Vptr = &complVertices[0];
memcpy(pVData,Vptr,complVertices.size()*sizeof(complVertex));						//copy data to buffer
pVBuffer->Unlock();


the render code:
	m_pEngine->g_pD3DDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME); // with solid i see nothing...
m_pEngine->g_pD3DDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
m_pEngine->g_pD3DDevice->SetFVF(FVF);
m_pEngine->g_pD3DDevice->SetStreamSource(0,pVBuffer,0,sizeof(complVertex));
m_pEngine->g_pD3DDevice->SetIndices(pIBuffer);
m_pEngine->g_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,complVertices.size(),0,Indices.size()/3);


the indices should work...i havent't changed anything with them Edit: for some reason the images don't work :/ just click on the not displayed image Edit2: Can this messed up v Coord cause the problem? i don't think so ...but i'm out of ideas :( regards, m4gnus [Edited by - m4gnus on August 29, 2005 4:45:51 AM]

##### Share on other sites
perhaps you are looking at the triangle from the side?

A triangle from the side will look like a line.

##### Share on other sites
The look from the side thing is highly likely as one of the coordinates is defined down the Z-axis -- usually in DX we view down the Z-axis in which case the point would make the triangle appear as a line. Try playing with the view settings or the imported data (it might be that Maya uses a right-handed coordinate system; you'd have to swap X and Z).

Quote:
 Fetter error!

Lol.

Quote:
 except the v Coordinate

What is the V-coordinate? Is it the second part of a texture coordinate (u,v)? In that case it will not hurt the mesh position.

Illco

##### Share on other sites
Quote:
 What is the V-coordinate? Is it the second part of a texture coordinate (u,v)? In that case it will not hurt the mesh position.
Yep it is...

No i'm not looking at the triangle from the side...i looked at it from different views and it was always a line. The strange thing is is that with the same thing i already rendered a cube(ok the cube didn't work completely,some faces weren't rendered that's why i thought i'll start debugging with a simple triangle)

so no more suggestions? should i post other code snippets?

regards,
m4gnus

##### Share on other sites
I think the thing you should pay attention to, is the fact it doesn't draw anything in solid mode, and only draws a single line, in wireframe.

Is see two possible things:
1) You're drawing from the top/side. I know you said you double checked, but I'd triple check :). Try changing all 3 values of the eye point.

2) You're drawing a degenerate triangle. This means, two of the 3 points are at exactly the same location. This would form a line, with no thickness, so in solid mode, it draws nothing. You'll need to check both the indices and the vertices and make sure each point is at a different location.

Other than that, I havn't a clue :).

Good luck.

##### Share on other sites
Quote:
 2) You're drawing a degenerate triangle. This means, two of the 3 points are at exactly the same location. This would form a line, with no thickness, so in solid mode, it draws nothing. You'll need to check both the indices and the vertices and make sure each point is at a different location.

That's exactly what came to my mind when i went swimmin...i think somewhere my indices are changed..

@1:
I orbited around it...so it isn't a real triangle for sure!

Edit: hmmm that's strange. I checked the Index and Vertex Array right after the creation of the Index+Vertexbuffer... Do you notice anything strange in the render code?

Edit2: ok i found a problem! complVertices.size() returns 2 right before calling DrawPrimitive..so yes i think i'm rendering a degenerated triangle now i "only" need to figure our why one elemnt of the vector gets removed ...

Edit3: Ok when i do a loop and copy every element of the vector to an array the array contains 3 Elements but Vector.size() returns 2...wtf?

regards,
m4gnus

[Edited by - m4gnus on August 28, 2005 1:32:34 PM]