Bizarre graphical anomalies, please help!

Started by
12 comments, last by Calneon 13 years, 4 months ago
I'm learning DX10, and following a series of great tutorials on Bobby Anguelov's blog. Been going fine until I wanted to apply textures to the meshes I made by following his tutorial. You can recreate the exact thing I get by downloading the tutorial here (http://takinginitiative.net/2009/02/24/directx-10-tutorial-5-basic-meshes/), and adding any variable to the vertex structure in "vertexTypes.h". For example, edit the file so it says;

D3DXVECTOR3 pos;
D3DXVECTOR4 color;
D3DXVECTOR2 texCoord;

and then compile and run it. You will see some very strange graphical glitches and I have no idea why or how to fix it. Can anyone help? Thanks.

If you don't want to load up the project, this is what you see: http://imgur.com/W4Qbj.png

It's meant to be a cube.
Advertisement
Is that meant to be a single cube? or multiple cubes?
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
Quote:adding any variable to the vertex structure in "vertexTypes.h". For example, edit the file so it says;

D3DXVECTOR3 pos;
D3DXVECTOR4 color;
D3DXVECTOR2 texCoord;


Did you modify the input declaration to handle color and/or texture coordinates?
Quote:Original post by 16bit_port
Quote:adding any variable to the vertex structure in "vertexTypes.h". For example, edit the file so it says;

D3DXVECTOR3 pos;
D3DXVECTOR4 color;
D3DXVECTOR2 texCoord;


Did you modify the input declaration to handle color and/or texture coordinates?

No, I added the variable that's it. Not declaring it or using it anywhere. I have tried modifying the rest of the code to enable textures but get the same thing. I managed to remove code step by step and found that adding this variable caused the problem.

It's multiple cubes yes, sorry. Rotating.
You definitely need to modify the stride when setting the vertex buffer, as each vertex is larger if you add something to the structure, and in order to use the new parameter you need to modify the vertex declaration and the vertex shader input structure.
Quote:Original post by Erik Rufelt
You definitely need to modify the stride when setting the vertex buffer, as each vertex is larger if you add something to the structure, and in order to use the new parameter you need to modify the vertex declaration and the vertex shader input structure.

I don't know what the stride is, and I'm not using a vertex buffer. What you're saying makes sense, but I'm not sure what to do.
Quote:Original post by Calneon
Quote:Original post by Erik Rufelt
You definitely need to modify the stride when setting the vertex buffer, as each vertex is larger if you add something to the structure, and in order to use the new parameter you need to modify the vertex declaration and the vertex shader input structure.

I don't know what the stride is, and I'm not using a vertex buffer. What you're saying makes sense, but I'm not sure what to do.


Stride is the size of the vertex struct.
Not just stride, you may have to change some other numbers related to the Vertex structure's size as well. But as I recall, that tutorial series uses sizeof() operator, so it is not needed to change anything in side C++ code. What I doubt here is that you have to change your vertex shader input to match that structure.
Quote:Original post by Calneon
I don't know what the stride is, and I'm not using a vertex buffer. What you're saying makes sense, but I'm not sure what to do.


In your case the vertex buffer is inside the ID3DX10Mesh. In order to make it work, you must add the texcoord to the input-layout as well as to the vertex, as for example "TEXCOORD", 0, DXGI_FORMAT_R32G32, 0, 28, PER_VERTEX, 0. Then you need to change the creation of the input-layout to match this by setting the element count to 3 instead of 2, for D3DX10CreateMesh and CreateInputLayout, and you must also modify the effect so that the vertex shader input contains a float2 texcoord : TEXCOORD.
Quote:Original post by Calneon
I'm learning DX10, and following a series of great tutorials on Bobby Anguelov's blog. Been going fine until I wanted to apply textures to the meshes I made by following his tutorial. You can recreate the exact thing I get by downloading the tutorial here (http://takinginitiative.net/2009/02/24/directx-10-tutorial-5-basic-meshes/), and adding any variable to the vertex structure in "vertexTypes.h". For example, edit the file so it says;

D3DXVECTOR3 pos;
D3DXVECTOR4 color;
D3DXVECTOR2 texCoord;

and then compile and run it. You will see some very strange graphical glitches and I have no idea why or how to fix it. Can anyone help? Thanks.

If you don't want to load up the project, this is what you see: http://imgur.com/W4Qbj.png

It's meant to be a cube.


well,the solution is simple,just turn on z-buffer:
d3dpp.EnableAutoDepthStencil=TRUE;
d3dpp.AutoDepthStencilFormat=D3DFMT_D16;//D16 standard
d3ddev->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );

and when render():
d3ddev->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, RGB(255, 255, 255), 1.0f, 0L);
also read this:
<url>http://www.toymaker.info/Games/html/z_buffer.html</url>
for more information about z-buffer

This topic is closed to new replies.

Advertisement