Sign in to follow this  
quanganht

[SlimDX] Empty render window

Recommended Posts

quanganht    118
Hi, I'm new with DirectX programming. So I started with SlimDX and D3D10. After a while, I was able to code a simple app base on this tutorial series http://takinginitiative.net/directx10-tutorials/, part 1 and 2. But I encoutered a strange problem: The Render window shows nothing but a black color. I think I have made a very close translation from original C++ code to C#. And it seems like no bugs present in my code. Can anyone help me with this?

My VS2010 project in this link: http://www.mediafire.com/?oj11ett95ejs3p2

BTW, there's no option to attach files to posts?

Share this post


Link to post
Share on other sites
Mike.Popoloski    3258
Noticed a few things:

1. Setting the minZ/maxZ of the viewport doesn't just set the clip planes, it changes how the vertices get scaled from homogeneous clip coordinates into screen space. You should probably leave this as 0 to 1.

2. The field-of-view and aspect ratio of your projection matrix are off. The fov is often set to some fractional value of pi, but you're setting it to 2*pi. For your aspect ratio, you're dividing two integers, which is going to use integer division and not give you the correct aspect ratio. Make sure you cast at least one of the operands to float in order to get a floating point result.

3. You define your input layout as sending a vector3 for the position, but in your shader your VS function takes a float4 as an input. You should change that to a float3, and then when multiplying by the world matrix use float4(Pos, 0) to get a float4 position.

Share this post


Link to post
Share on other sites
quanganht    118
Thanks a thousand times for the reply, Mike. :) I helped me found the bug. It was a typo, where I should have FOV = PI * 0.5f instead of PI / 0.5. Noew it works like a charm!!! Again, thanks a lot!

About the position variable, I just do as instructed by the tutorial. I find it quite strange, too. Using float4(Pos, 0) will make the screen black again.

Share this post


Link to post
Share on other sites
unbird    8336
I think float4(Pos, 1) is correct in this case, your shader operates in homogenous coordinates after all. (x,y,z,0) is reserved for homogenous normals/directions, that's why it's not working.

I also think it's ok to use a float4 as input for the vertex shader. Can't speak for DX 10, but I've just checked on DX 9 and the docs in fact confirm a float3 will be expanded to (x,y,z,1) automatically. Chances are you got the same behaviour in DX 10 (upward compatibility). But you never know: Maybe it's better to enforce that 1.

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