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


Problem with my program..

Recommended Posts

Vecna    122
Hi there, this program I have made compiles and links just fine but there is suppose to be 2 polygons (triangle and a square) that are rotating but they don''t show up! I have looked at the code for a long time now and I can''t find out what''s going wrong . Thanks for any help you may provide. Source Code: By the way, I wrote this with the help of a tutorial at so it''s not entirely my creation .

Share this post

Link to post
Share on other sites
S1CA    1418
1. The source code on that URL you posted doesn''t even compile!!... The HWND passed to SetFocus() and DestroyWindow() *should NOT* be a pointer.

2. I don''t think you have the Debug *DIRECTX* runtimes installed! - when I run that program with the true DirectX debug runtime two notable things happen:

a) My screen flashes between red and green - this is something the *DEBUG* version of Direct3D does to tell you that there is a problem.

b) My debug output fills up with error messages telling me what the problem is:


Direct3D8: (ERROR) :*** Exception in d:\builds\nt32_chk\multimedia\directx\dxg\d3d8\fe\vshader.cpp Line: 653
Direct3D8: (ERROR) :Vertex buffer must be unlocked during DrawPrimitive call
Direct3D8: (ERROR) :DrawPrimitive failed.

3. So the solution, given that D3D has clearly told me what the problem is (the vertex buffer is still locked):

a) Make sure you have the debug runtime properly installed and the output level turned up (see the other thread on here about the debug runtime, what it does for you, and how to enable it). This way you can debug the code yourself.

b) Insert a g_pVb->Unlock(); after the memcpy();

Now that bug is fixed, the screen stops flashing and the debug output calms down, however the code STILL doesn''t work, just displays a grey screen - so take a look at the new debug output:


Direct3D8: (WARN) :Cannot compute WNear and WFar from the supplied projection matrix

Direct3D8: (WARN) :Setting wNear to 0.0 and wFar to 1.0

Direct3D8: (ERROR) :Cannot invert projection matrix

That tells me you have a problem with your projection matrix... so I look at your code again... init_scene to be precise.

matProj variable is declared, never initialised to anything, then passed straight to D3D''s SetTransform() call!!...

You **NEED** a projection matrix for 3D graphics, particularly if not using XYZRHW style vertices.

Next issue, you also NEED a view matrix set to *something*, you calculate one, but never call SetTransform on it.

Even after fixing those, there were still more bugs. Hint: what does the second parameter on the Lock() call for the VB mean, and the last parameter for the memcpy()...

By this point the shapes appear on the screen but don''t rotate. Final bug hint: adding 0.004f (i.e. a floating point value) to a variable stored in an int rounds the number being added - i.e. becomes +0.

The fixed code has a coloured triangle spinning in the X axis and a blue square spinning in the Y axis.

I''d suggest working your way through the Tutorials supplied with DirectX SDK!

I''d also suggest not trying run before you''ve learnt to walk, get a single non-rotating triangle nailed down before you start trying to transform and rotate them.

Simon O''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites