Sign in to follow this  
Kimani

Question - My little box is all black!

Recommended Posts

I am going through a book learning about doing things in DirectX, and I'm having what is probably a simple problem, which nevertheless escapes me. The black box above should have some simple coloring to it! The vertex structure I am using has indeed a color value, and the D3DFVF_DIFFUSE is indeed being used, and yet it displays only what you see above. The code is located here. BONUS: I made a little test camera to see if I could make one, controlled with the arrow keys. The camera rotates fine, but behaves strangely when going forth or backward... BONUS 2: If something is dragged on top of the window, it does not redraw any damaged areas. Maybe there's something special you have to do to do this that my little book does not address... Thanks in advance!

Share this post


Link to post
Share on other sites
1) Your box is black because you have enabled lighting but your vertex data doesn't include normals! Lighting affect a model only if you provide normals data. If you just want to see the vertex colours without the hassle (which it isn't actually) of normals, just disable the lighting.

2) The camera movement is strange? I suppose it doesn't move on the axis you think it should? If that's so it's probably because when you rotate the camera, the camera axis rotates too and you aren't moving on the z axis anymore! You'll have to maintain a camera view matrix (using a camera up, camera forward and camera right vectors) to get around this. Perhaps this article might help? http://www.cubic.org/docs/camera.htm

Incidentally, you are using a strange process to draw the box. Since you already have a vertex buffer (with hopefully the vertices stored in the correct order - I didn't check) with the required vertex data, all you need is a single draw primitive call to render the box! Unless I'm missing something....

Share this post


Link to post
Share on other sites
Ah... well, next up in the book was lighting. I added some code to do this, as maybe if I lit up the box it would show some colors. For the purpose of this thread I thought I took out all of the lighting code, so I would have just the error to present without all the lighting complications, but it looks like I missed that line in that function there. In short: it still does not work even without that line in there. For me at least.

The book also didn't mention normals. Perhaps it's either going to get to that in a later chapter, or I'll have to Google it up / look through a different book. It's "Beginning DirectX 9" from Premier Press, by the way.

The box is drawn in such a way because for the purpose of just testing out all this 3D stuff for the first time, a box is nice and simple, so the book provides a way to make one. Not complaining, I just copied down the array it provided. I was going to put all of that in just one DrawPrimitive call, but then I realized that the array I copied out of the book is in six sections of four verticies, for the sides of the cube. If I wanted to go through and make it for one Triangle Strip, it would have taken a good deal of thought and time manuvering all the vertices... it works fine the way it is at the moment, so eh. It's only a little test.

As for the camera, I'm using some of the D3DX things to set the thing up, so I haven't yet delved into the manual math of it all (although I'm the kind of guy who likes reinventing wheels, per se, so the link is still useful!)

The code for going forthward and backward is this:
D3DXVECTOR3 AVec = *look * ( speed * anim_rate );
*location += AVec;

look and locations are pointers to D3DXVECTOR3's. Speed is a float with the speed at which the camera will move, and anim_rate is a float with the time, in seconds, one render seems to take, used to make things move smoothly. When the program is run, look is [0,0,1], which should be looking straight ahead. Which it does. This code should, when the speed is nonzero, add [0,0,speed * anim_rate] to the location of the camera. Even when the camera is rotated, so the look is something different, it should just add that to the location, and work.

Fairly simple! But it doesn't quite work, and rather does something very strange, only describable by compiling it yourself and trying it. Perhaps I am missing something conceptually about the whole thing.

Share this post


Link to post
Share on other sites
Simply removing the line isn't going to help because the default lighting is TRUE, so you have to explicitly set it to FALSE. In any case if you do want lighting (TRUE) then, if I'm not wrong, you need some sort of material on the model too. I suggest putting off all this lighting business till you actually get to the part on lighting in the book. Till then explicitly set the lighting to false and try.

Regarding the camera, the point I was stressing was that you need to rebuild your camera vectors after the rotations so that the camera axis is aligned properly. This may or may not help your case but it's worth bearing in mind.

HTH.

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