Crazy geometry (help)

Started by
9 comments, last by MrMonkey 21 years, 9 months ago
Hey all, I am tearing my hair out over a seemingly stupid problem, and I hope there''s salvation here. I have been to integrate a very simple terrain rendering class, and rendering it as an indexed primitive... but I''ve had an inordinate amount of problems doing so. I have finally achieved the following, and can''t seem to do any better. Anyone have any thoughts? Thanks for the thoughts
•º°”˜˜”°º••º°”˜˜”°º•
Advertisement
I had a similar problem. In my case I had some "rubbish" data in my vertex buffer. Try looking at the code that fills the vertex buffer and make sure that the numbers ok.

I''ve got some tutorials on my site, including a simple terrain generator (looks very similar to yours). Take a look at tutorial 8, it may help you.

http://www.andypike.com/tutorials/directx8/

All the best
Andy

-----------------------------
Andy Pike
DirectX 8 Tutorials: www.andypike.com
-----------------------------Andy PikeDirectX 8 Tutorials: www.andypike.comBatch Image Processing Software
Haha... that''s great.

I was actually attempting to use your exact demo.
I followed your steps exactly (only renaming some variables here and there). I have checked the VB line by line numerous times...but to no avail. It works great in your download... but looks like the above when I run mine.
sigh.
•º°”˜˜”°º••º°”˜˜”°º•
Yup, in making my own map parser I also had the same problem... what is happening is that somewhere you are adding vertices that are being set using uninitialised variables... the reason they stretch off to infinity is because of the garbage value the variables have if you don''t initialise your variables. So try running through with a debug watching the variables that form your vertices and watch for the bad values, then you can begin to track the problem to its source.
Cheers,SteveLiquidigital Online
Thanks for the help guys.
So here''s the update. I found my problem (sort of).
in my render() I had the following lines (didn''t work):
g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, m_NumVerts/2, 0, m_NumPolys/2);
g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, m_NumVerts/2, m_NumVerts/2, m_NumPolys/2, m_NumPolys/2);

So I replaced it w/ the simple:
g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, m_NumVerts, 0, m_NumPolys);


Which does work. The problem is, I''m using a test map, and the one I want to use is too big to render in one shot (which is why I tried to break it up in the first place). Am I way off base here, or is my syntax repairable?
Thanks.

•º°”˜˜”°º••º°”˜˜”°º•
The fourth parameter to DIP is starting index, not starting primitive.

---
Come to #directxdev IRC channel on AfterNET
Yup as stated above your 4th parameter needs to indicate the starting index... you may be able to temporarily fix it by using these two lines:

g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, m_NumVerts/2, 0, m_NumPolys/2);
g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, m_NumVerts/2, m_NumVerts/2, m_NumVerts/2, m_NumPolys/2);

But thats assuming you have the same number of indices as you have vertices which is probably not the case. I would probably fix that by keeping track of the number of indices in a member variable and using that variable when setting your start index in DrawIndexedPrimitive, or perform a more accurate calculation on your number of vertices to get the number of indices you have but thats dependant on how you are using your index buffer so without seeing more code I couldn''t give you the exact calculation.
Cheers,SteveLiquidigital Online
Thanks again for all your help- you guys rock.

So, as it happens, I do have a member variable that holds the amount of Indices (m_NumIndices). But I doubt that the following would be valid (or am I wrong?):

g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, m_NumVerts/2, 0, m_NumPolys/2);
g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, m_NumVerts/2, m_NumVerts/2, m_NumIndices/2, m_NumPolys/2);


Can I assume that, by the second DIP call,I have rendered exacly 1/2 of the Indices?

(BTW, my code is very closely based on Mr. Andy Pike''s stuff, at:
His Terrain Tutorial )
•º°”˜˜”°º••º°”˜˜”°º•
Well the number of indices you use halved should be a sufficent number of indices to render half of your vertices. Say you have a quad using 4 vertices and are using an index buffer containing 6 indices to tell DrawIndexedPrimitve how to use the four vertices, the first 3 indices would be vertices 0, 1 and 2. Your 4th, 5th and 6th indices would be vertices 0, 2 and 3.

So yes, the first half of the indices would be sufficient indices to draw the first triangle and the second half of the indices would be sufficient to draw the second triangle. This should scale up absolutely fine when using more vertices and indices.

So in answer to your question, I think yes, your new calls to DrawIndexedPrimitive should in theory work fine... let us know if it doesnt work though.
Cheers,SteveLiquidigital Online
Darnit.
Well, it almost works (but apparently, I live a long way from theory).
Using the following code to render, I results in the image below.
g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, m_NumVerts/2, 0, m_NumPolys/2);
g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, m_NumVerts/2 , m_NumVerts/2, m_NumIndices/2, m_NumPolys/2 );



I was beginning to question my VB and IB, but since the sucker renders fine w/o spliting up the DIP calls, I think all my structures are ok.
BTW, it appears that the vertex that exploded is the first one that I define in my IB.
•º°”˜˜”°º••º°”˜˜”°º•

This topic is closed to new replies.

Advertisement