#### Archived

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

# losing primatives in Direct3D

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

## Recommended Posts

Help, please! I''ve implemented a trainglestrip heightfield textured with a jpg of grass (I call it my "lawn"), and every render I get missing primatives- single triangles and/or lines of them. I''m stumped! Some things to know: It''s a heavily modified version of D3D Tutorial 5: textures, with vertexbuffer verticies defining a heightfield, as opposed to a cylinder. I have varied the following, with no change in the error: 1)Vertexbuffer as both a trianglelist and a trianglestrip 2)base images for my texture 3)culling modes 4)dimensions of heightfield The non-rendered primatives depend on my set camera position- I can''t seem to detect any "overlap" in the verticies. Anyone have similar problems? -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- "Hey, I was''t joking... You really /could/ be "boinked" by some irate looney wielding a rubber malet." -Baldor the Bold

##### Share on other sites
..and every render I get missing primatives- single triangles and/or lines of them. I''m stumped!

my friend has problem what is very like to yours on Riva128 ZX card. My terrain editor, with height gird was showing properly on my Savage4 and RivaTNT2Pro+ but he has holes
p.s. can you post a pic?

##### Share on other sites
Need to ask a couple of questions first.

First,
Did you remember to set the Vertex buffer to the correct size? IE..

g_pd3dDevice->CreateVertexBuffer( 50*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB );

would create a VB the size of 50 vertices, change the (x*sizeof(CUSTOMVERTEX)) to whatever the ammount of vertices you are using.

2nd,
Did you turn on the z-buffer, and set it to a reasonable bit-depth?

##### Share on other sites
quote:

Need to ask a couple of questions first.

First,
Did you remember to set the Vertex buffer to the correct size? IE...
...would create a VB the size of 50 vertices, change the (x*sizeof(CUSTOMVERTEX)) to whatever the ammount of vertices you are using.

Yes, I'm using a 20x20 grid, comprised of 2 primatives per square. In my source (modified copy of the tutorial 5: textures source), is my creation of the vertex buffer, which I immediately populate with verticies. Here's the whole function for that:

  //-----------------------------------------------------------------------------// Name: InitGeometry()// Desc: Create the textures and vertex buffers//-----------------------------------------------------------------------------HRESULT InitGeometry(){ // Use D3DX to create a texture from a file based image// if(FAILED(D3DXCreateTextureFromFile( g_pd3dDevice, "Grass.jpg", &g_pTexture ))) if(FAILED(D3DXCreateTextureFromFile( g_pd3dDevice, "banana.bmp", &g_pTexture ))) { Bug("File: Textures.cpp\nFunction: InitGeometry()\nCall: D3DXCreateTextureFromFile\n"); return E_FAIL; } // Create the vertex buffer. if( FAILED( g_pd3dDevice->CreateVertexBuffer( 20*20*2*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB ) ) ) { return E_FAIL; } // Fill the vertex buffer. We are setting the tu and tv texture // coordinates, which range from 0.0 to 1.0 CUSTOMVERTEX* pVertices; if( FAILED( g_pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 ) ) ) return E_FAIL; for( DWORD x=0; x<20; x++ ) for( DWORD z=0; z<20; z++ ) { // Point 1's coordiantes: pVertices[(40*x)+(2*z)].position = D3DXVECTOR3( ((float)x), 0.0f , ((float)z)); pVertices[(40*x)+(2*z)].color = 0xffffffff; pVertices[(40*x)+(2*z)].tu = ((float)x)*0.05f; pVertices[(40*x)+(2*z)].tv = ((float)z)*0.05f; // Point 2's coordinates: pVertices[(40*x)+(2*z)+1].position = D3DXVECTOR3( ((float)x) +1.0f, 0.0f , ((float)z)); pVertices[(40*x)+(2*z)+1].color = 0xffffffff; pVertices[(40*x)+(2*z)+1].tu = ((float)x)*0.05f + 0.05f; pVertices[(40*x)+(2*z)+1].tv = ((float)z)*0.05f; } g_pVB->Unlock(); return S_OK;}

In some experiements I did mess around with the vertex buffer size- usually finding that, when it was defined smaller than the calls made to drawprimative, my screen would flash green and pink. I assumed that was Direct3D saying there was an error of some sort, though I never found mention of it in the docs.

quote:

2nd,
Did you turn on the z-buffer, and set it to a reasonable bit-depth?

Yes, I initialized the z-buffer, although I'm new to the term "bit-depth". My z-buffer was assigned the same charictaristics as the current display (I think... that's how I read the code, but for the most part I didn't write that part). Again, this is (mostly) the source from tutorial 5.

  //-----------------------------------------------------------------------------// Name: InitD3D()// Desc: Initializes Direct3D//-----------------------------------------------------------------------------HRESULT InitD3D(){ // Create the D3D object. if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) ) return E_FAIL; // Get the current desktop display mode, so we can set up a back // buffer of the same format D3DDISPLAYMODE d3ddm; if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) ) return E_FAIL; // Set up the structure used to create the D3DDevice. Since we are now // using more complex geometry, we will create a device with a zbuffer. D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; // Create the D3DDevice if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) ) { return E_FAIL; } g_pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_ALWAYS ); // Turn off culling g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); // Turn off D3D lighting g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); // Turn on the zbuffer g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); return S_OK;}

so... everything checks out with me, so far... hrm.

quote:

..and every render I get missing primatives- single triangles and/or lines of them. I'm stumped!

my friend has problem what is very like to yours on Riva128 ZX card. My terrain editor, with height gird was showing properly on my Savage4 and RivaTNT2Pro+ but he has holes
p.s. can you post a pic?

As far as the hardware goes, I'm running a (mouthful) ASUS AGP-v6600 GeForce256 32meg. (it was the only one I could find available in my area with tv in/out AND 3d glasses)

This would be the first time posting I pic (I *just* got it working... for me, in another prog)

Thanks all for helping.

-Tok.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"Hey, I was't joking... You really /could/ be "boinked" by some irate looney wielding a rubber malet." -Baldor the Bold

Edited by - Tok on October 19, 2001 12:29:05 AM

##### Share on other sites
Great Texture. Was it easy to make?
Why don''t you make the map a little smaller, like say 5 * 5 and see if the same problems pop up. The main advantage is that if they do, then you could use the debugger and check out whether all the Vertices are being filled in correctly without going through 400+ steps. Only 25 would be needed.

Good luck...

##### Share on other sites
quote:
Original post by DLin
Great Texture. Was it easy to make?
Why don't you make the map a little smaller, like say 5 * 5 and see if the same problems pop up. The main advantage is that if they do, then you could use the debugger and check out whether all the Vertices are being filled in correctly without going through 400+ steps. Only 25 would be needed.

Good luck...

(I'll need it...)

First off, Thank you everyone who is helping me out. I'm sorry that I can't just figure this out on my own- but I've tried upwards of a dozen different coding methods to try to implement the same effect, and *ALL* give me this error. I'm just about ready to blame it on hardware.

As for the "grass", thank you, but I found the texture with a programming example on the net. I like it, and have ideas about how to create my own versions of it so I don't steal anyone else's work.

Regarding working it 5x5: I'm sorry to say that of the many, many things I've tried, I've also changed the defined size of "the lawn".

In the following

we have the camera placed at (-5.0, 7.0, 2.5) looking at the "2.5" center of a 5 by 5. Each square in this case has a width of 1, though I've tried a few scales of grid ranging from .01f to 1.0f/sq. As far as the verticies being filled in correctly they are, unless the initialization (in this case trianglestrip, though there have been others)
pVertices[(40*x)+(2*z)].position = D3DXVECTOR3( ((float)x), 0.0f , ((float)z));pVertices[(40*x)+(2*z)+1].position = D3DXVECTOR3( ((float)x) +1.0f, 0.0f , ((float)z));

is lying to me somehow. I doubt this, as the verticies missed depend on the angle of view. By simply changing the x camera coordinate from 2.5 to 3.5, we get

Only 2 of the 13 faces missed with the x = 2.5 implemention are missing with x = 3.5. Other camera coordinates show the entire grid rendered- some show almost none of it.

I am new to DirectX, but I am not new to programming. This bug is mocking every debugging method I know... short of compiling someone else's working copy and saying "here, this is my code."

A fairly exhausted (and fed up) thank you to anyone and everyone who has had questions/comments/suggestions for me. They are *all* appreciated.

-Tok.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"Hey, I was't joking... You really /could/ be "boinked" by some irate looney wielding a rubber malet." -Baldor the Bold

Edited by - Tok on October 23, 2001 5:51:30 AM

##### Share on other sites
To me it seems like there is a culling problem (you are showing the backface of the triangles and they don''t have a texture attached to them).

To check if this is the problem set the renderstate to wireframe rendering (instead of solid) and if you (with your culling_mode == none) see all the triangles independent of the camera position then your creation of the triangle list/stripe has the wrong culling for some of the triangles.

##### Share on other sites
Sorry, I've tried wireframe, textured, and point- when they're not drawn in one method, they don't draw in any.
And in the examples, I have culling set to cull_none. I've tried every culling method I could find in the docx, and none work.

-Regards,
Tok.

Edited by - Tok on October 23, 2001 10:18:52 AM

##### Share on other sites
Any chance you''re not creating your triangles in the right order. Meaning, clockwise for the first, counter for second in the strip?

1--3
|\ |
| \|
0--2

Should be:

0,1,2
2,3,1

I''m not 100% sure on the order for the second triangle, but you should be able to find it in the SDK or on the web. The order is important because it determines which side is considered the backface for culling. You images seem like the usual problem with triangle point ordering in a strip.

Just a thought.

Rube.

##### Share on other sites
quote:
Original post by Rube
Any chance you''re not creating your triangles in the right order. Meaning, clockwise for the first, counter for second in the strip?

Since he''s tried it with CULL_NONE and still gets the problem, I don''t think that''s it.

Do you have an archive (source & exe)I could download? It might be a driver issue.

Stay Casual,

Ken
Drunken Hyena

1. 1
2. 2
JoeJ
20
3. 3
4. 4
5. 5
frob
12

• 10
• 13
• 21
• 13
• 20
• ### Forum Statistics

• Total Topics
632195
• Total Posts
3004702

×