Sign in to follow this  

What can be wrong?

Recommended Posts

I am rendering a set of triangles(more than 10k tris) using the Directx8's DrawPrimitive function. Its a cylinder and half the triangles are missing on the cylindrical face. I can think of 2 possible problems 1. The normal of the triangles can be wrong - This cannot be the case as I am setting CULL_NONE. So even if the normals are wrong it should render anyway. 2. Some triangles are missing from the data - This may not be the case as it is a closed model and the no of nodes is approx equal to twice the no of tris. Is there anything in directx which can cause this kind of problem? Any clue?

Share this post

Link to post
Share on other sites
Do you know of Pix? check it out into the DX SDK documentation. It will help you when you have such kind of issues.

This is D3D8, so you can't use Pix. However, you still can check for some debug runtime output - have you done that?

Since you already tried turning off backface culling, I would look to (2). Check to make sure that you are constructing your primitives correctly (whether they are tri lists or strips, or whatever). Perhaps posting code for this part would be helpful.

I would also verify that your parameters to DrawPrimitive() are correct. Perhaps you are drawing a lower number of primitives because of an incorrect argument.

Share this post

Link to post
Share on other sites
I am drawing each triangle as a D3DPT_TRIANGLELIST. So my assumption is that if there is a problem in drawing(the arguments to function etc) then all triangles should have the same problem. I am pasting the code below.

Public Sub RenderScene()
Dim l As Line
'Clear the buffer
m_d3d.Clear C_WHITE

'Start the rendering

m_d3d.Device.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE
m_d3d.Device.SetRenderState D3DRS_FILLMODE, D3DFILL_SOLID

'Draw the triangle
For i = 0 To m_count - 1

'Stop the rendering

End Sub

Triangle draw is as follows

Public Sub Draw()
If d3d Is Nothing Then
Exit Sub
End If

'Set source vertex buffer for rendering
d3d.Device.SetStreamSource 0, m_vbData, VertexSize

'Draw the triangle
d3d.Device.DrawPrimitive D3DPT_TRIANGLELIST, 0, 1
End Sub

The triangle data I am reading from an existing file. I am not sure how to confirm if all triangles are present. But i would consider the probability of the problem in input data as very less because an external 3rd party program draws the model correctly.

I am a newbie in directx and probably i am doing something which is obviously wrong.

Share this post

Link to post
Share on other sites
Also note that this is the slow way to do things. In general you want to have only one DrawPrimitive per renderstate or texture change so you can get very high fps. To do this you might have to put your vertices into a vertex buffer (this can be what your .Draw does) and then render the entire thing at once, for example using a triangleList.

Get even fancier and use index buffers for even more speed... my VB code is something like

mD3DDevice.SetIndices mIndexBuffer, 0
mD3DDevice.DrawIndexedPrimitive D3DPT_TRIANGLELIST, mlStartVertex, mlIndexCount, mlStartIndex, mlIndexCount / 3

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this